Skip to content

Commit

Permalink
Link to Github code from sidebar for undocumented components
Browse files Browse the repository at this point in the history
  • Loading branch information
davidalejandroaguilar committed Oct 9, 2024
1 parent a8c5ced commit 9fed41e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
4 changes: 4 additions & 0 deletions app/models/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ def implemented?
"PhlexyUI::#{name}".safe_constantize.present?
end

def github_url
"https://github.com/PhlexyUI/phlexy_ui/blob/main/lib/phlexy_ui/#{name.underscore}.rb"
end

private

def file_exists?
Expand Down
10 changes: 9 additions & 1 deletion app/views/components/shared/github_svg.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
module Shared
class GithubSvg < ApplicationComponent
def initialize(**options)
@classes = options[:class] || "w-5 h-5"
end

def view_template
svg(
viewbox: "0 0 16 16",
class: "w-5 h-5",
class: classes,
fill: "currentColor",
aria_hidden: "true"
) do |s|
Expand All @@ -13,5 +17,9 @@ def view_template
)
end
end

private

attr_reader :classes
end
end
19 changes: 12 additions & 7 deletions app/views/components/sidebar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,23 @@ def view_template
)
elsif component.implemented?
link_to(
"#",
class: "!cursor-default",
data: {turbo_frame: :content}
component.github_url,
class: "!cursor-alias",
data: {turbo_frame: :content},
target: "_blank"
) do
span class: "opacity-50" do
span do
component.name
end

Tooltip tip: "Implemented, not documented" do
Badge :outline, :info, class: "opacity-50" do
"Undocumented"
div class: "flex gap-2 justify-end items-center" do
Tooltip tip: "Implemented, undocumented" do
Badge :outline, :info, :sm, class: "opacity-50" do
"Undocumented"
end
end

render GithubSvg.new(class: "w-4 h-4 opacity-50")
end
end
else
Expand Down

0 comments on commit 9fed41e

Please sign in to comment.