Skip to content

Commit

Permalink
Remove referenced components list (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephannv authored Nov 12, 2024
1 parent 57061e3 commit aec0f12
Show file tree
Hide file tree
Showing 38 changed files with 52 additions and 106 deletions.
32 changes: 2 additions & 30 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,6 @@
module ApplicationHelper
def component_references(component, code_example = nil, use_component_files = false)
return [] unless code_example

calls = []
Prism.parse(code_example).value.accept(MethodCallFinder.new(calls))
calls_set = Set.new(calls.map(&:to_s))
descendants = Phlex::HTML.descendants.map { |d| d.to_s.gsub(/^RubyUI::/, "") }
component_names = descendants.select { |d| calls_set.include?(d) }

# component_names = code_example.scan(/(?<=^|\s)#{component}\w*/).uniq

component_names.map do |name|
Docs::ComponentStruct.new(
name: name,
source: "lib/ruby_ui/#{camel_to_snake(component)}/#{camel_to_snake(name)}.rb",
built_using: :phlex
)
end

# component_names.push(
# Docs::ComponentStruct.new(
# name: "ComboboxController",
# source: "https://github.com/PhlexUI/phlex_ui_stimulus/blob/main/controllers/command_controller.js",
# built_using: :stimulus
# )
# )
end

require "rubygems"
require "rubygems"

module ApplicationHelper
def component_files(component, gem_name = "ruby_ui")
# Find the gem specification
gem_spec = Gem::Specification.find_by_name(gem_name)
Expand Down
32 changes: 3 additions & 29 deletions app/views/components/docs/components_table.rb
Original file line number Diff line number Diff line change
@@ -1,40 +1,14 @@
# frozen_string_literal: true

class Docs::ComponentsTable < ApplicationComponent
def initialize(components, file_components = nil)
@components = components.sort_by { |component| [component.built_using, component.name] }
@file_components = file_components.sort_by { |component| [component.built_using, component.name] } if file_components
def initialize(component_files)
@component_files = component_files.sort_by { |component| [component.built_using, component.name] }
end

def view_template
Heading(level: 2) { "Components" }

Tabs(default_value: "account", class: "") do
TabsList do
TabsTrigger(value: "components") { "Components Referenced" }
TabsTrigger(value: "file-components") { "Component files" }
end
TabsContent(value: "components") do
div(class: "rounded-lg border p-6 space-y-4 bg-background text-foreground") do
div(class: "space-y-0") do
component_table_view(@components)
end
end
end
if @file_components
TabsContent(value: "file-components") do
div(class: "rounded-lg border p-6 space-y-4 bg-background text-foreground") do
div do
if @file_components.present?
component_table_view(@file_components)
else
Text { "No components for this page" }
end
end
end
end
end
end
component_table_view(@component_files)
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/views/docs/accordion_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def view_template
RUBY
end

render Docs::ComponentsTable.new(component_references(component, @@code), component_files(component))
render Docs::ComponentsTable.new(component_files(component))
end
end
end
2 changes: 1 addition & 1 deletion app/views/docs/alert_dialog_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def view_template
RUBY
end

render Docs::ComponentsTable.new(component_references(component, Docs::VisualCodeExample.collected_code), component_files(component))
render Docs::ComponentsTable.new(component_files(component))
end
end
end
2 changes: 1 addition & 1 deletion app/views/docs/alert_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def view_template
RUBY
end

render Docs::ComponentsTable.new(component_references(component, Docs::VisualCodeExample.collected_code), component_files(component))
render Docs::ComponentsTable.new(component_files(component))
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/docs/aspect_ratio_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def view_template
RUBY
end

render Docs::ComponentsTable.new(component_references(component, Docs::VisualCodeExample.collected_code), component_files(component))
render Docs::ComponentsTable.new(component_files(component))
end
end
end
2 changes: 1 addition & 1 deletion app/views/docs/avatar_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def view_template
RUBY
end

render Docs::ComponentsTable.new(component_references(component, Docs::VisualCodeExample.collected_code), component_files(component))
render Docs::ComponentsTable.new(component_files(component))
end
end
end
2 changes: 1 addition & 1 deletion app/views/docs/badge_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def view_template
end

# components
render Docs::ComponentsTable.new(component_references("Badge", Docs::VisualCodeExample.collected_code), component_files("Badge"))
render Docs::ComponentsTable.new(component_files("Badge"))
end
end
end
10 changes: 5 additions & 5 deletions app/views/docs/button_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def view_template

render Docs::VisualCodeExample.new(title: "Icon", context: self) do
<<~RUBY
Button(variant: :outline, icon: true) do
Button(variant: :outline, icon: true) do
svg(
xmlns: "http://www.w3.org/2000/svg",
viewbox: "0 0 20 20",
Expand All @@ -71,7 +71,7 @@ def view_template

render Docs::VisualCodeExample.new(title: "With Icon", context: self) do
<<~RUBY
Button(variant: :primary) do
Button(variant: :primary) do
svg(
xmlns: "http://www.w3.org/2000/svg",
fill: "none",
Expand All @@ -94,7 +94,7 @@ def view_template

render Docs::VisualCodeExample.new(title: "With Icon", context: self) do
<<~RUBY
Button(variant: :primary, disabled: true) do
Button(variant: :primary, disabled: true) do
svg(
xmlns: "http://www.w3.org/2000/svg",
viewbox: "0 0 20 20",
Expand All @@ -115,13 +115,13 @@ def view_template

render Docs::VisualCodeExample.new(title: "Submit", context: self) do
<<~RUBY
Button(variant: :primary, type: :submit) do
Button(variant: :primary, type: :submit) do
span { "Submit application" }
end
RUBY
end

render Docs::ComponentsTable.new(component_references("Button", Docs::VisualCodeExample.collected_code), component_files("Button"))
render Docs::ComponentsTable.new(component_files("Button"))
end
end
end
2 changes: 1 addition & 1 deletion app/views/docs/calendar_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def view_template
RUBY
end

render Docs::ComponentsTable.new(component_references(component, Docs::VisualCodeExample.collected_code), component_files(component))
render Docs::ComponentsTable.new(component_files(component))
end
end
end
2 changes: 1 addition & 1 deletion app/views/docs/card_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def view_template
RUBY
end

render Docs::ComponentsTable.new(component_references(component, Docs::VisualCodeExample.collected_code), component_files(component))
render Docs::ComponentsTable.new(component_files(component))
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/views/docs/checkbox_group_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Docs::CheckboxGroupView < ApplicationView
def view_template
component = "Checkbox Group"
component = "Checkbox"

div(class: "max-w-2xl mx-auto w-full py-10 space-y-10") do
render Docs::Header.new(title: "Checkbox Group", description: "A control that allows the user to toggle between checked and not checked.")
Expand Down Expand Up @@ -71,7 +71,7 @@ def view_template
RUBY
end

render Docs::ComponentsTable.new(component_references(component, Docs::VisualCodeExample.collected_code), component_files(component))
render Docs::ComponentsTable.new(component_files(component))
end
end
end
2 changes: 1 addition & 1 deletion app/views/docs/checkbox_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def view_template
RUBY
end

render Docs::ComponentsTable.new(component_references(component, Docs::VisualCodeExample.collected_code), component_files(component))
render Docs::ComponentsTable.new(component_files(component))
end
end
end
2 changes: 1 addition & 1 deletion app/views/docs/clipboard_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def view_template
RUBY
end

render Docs::ComponentsTable.new(component_references(component, Docs::VisualCodeExample.collected_code), component_files(component))
render Docs::ComponentsTable.new(component_files(component))
end
end
end
8 changes: 4 additions & 4 deletions app/views/docs/codeblock_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def view_template

render Docs::VisualCodeExample.new(title: "With clipboard", context: self) do
<<~RUBY
code = <<~CODE
code = <<~CODE
def hello_world
puts "Hello, world!"
end
Expand All @@ -23,7 +23,7 @@ def hello_world

render Docs::VisualCodeExample.new(title: "Without clipboard", context: self) do
<<~RUBY
code = <<~CODE
code = <<~CODE
def hello_world
puts "Hello, world!"
end
Expand All @@ -36,7 +36,7 @@ def hello_world

render Docs::VisualCodeExample.new(title: "Custom message", description: "Copy the code to see the message", context: self) do
<<~RUBY
code = <<~CODE
code = <<~CODE
def hello_world
puts "Hello, world!"
end
Expand All @@ -47,7 +47,7 @@ def hello_world
RUBY
end

render Docs::ComponentsTable.new(component_references(component, Docs::VisualCodeExample.collected_code), component_files(component))
render Docs::ComponentsTable.new(component_files(component))
end
end
end
2 changes: 1 addition & 1 deletion app/views/docs/collapsible_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def view_template
RUBY
end

render Docs::ComponentsTable.new(component_references(component, Docs::VisualCodeExample.collected_code), component_files(component))
render Docs::ComponentsTable.new(component_files(component))
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/docs/combobox_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def view_template
end
RUBY
end
render Docs::ComponentsTable.new(component_references(component, @@code_example), component_files("Combobox"))
render Docs::ComponentsTable.new(component_files("Combobox"))
end
end
end
2 changes: 1 addition & 1 deletion app/views/docs/command_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def view_template
RUBY
end

render Docs::ComponentsTable.new(component_references(component, Docs::VisualCodeExample.collected_code), component_files(component))
render Docs::ComponentsTable.new(component_files(component))
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/docs/context_menu_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def view_template
RUBY
end

render Docs::ComponentsTable.new(component_references(component, Docs::VisualCodeExample.collected_code), component_files(component))
render Docs::ComponentsTable.new(component_files(component))
end
end
end
4 changes: 2 additions & 2 deletions app/views/docs/date_picker_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Docs::DatePickerView < ApplicationView
def view_template
component = "Date Picker"
component = "DatePicker"

div(class: "max-w-2xl mx-auto w-full py-10 space-y-10") do
render Docs::Header.new(title: "Date Picker", description: "A date picker component with input.")
Expand All @@ -27,7 +27,7 @@ def view_template
RUBY
end

render Docs::ComponentsTable.new(component_references(component, Docs::VisualCodeExample.collected_code), component_files(component))
render Docs::ComponentsTable.new(component_files(component))
end
end
end
2 changes: 1 addition & 1 deletion app/views/docs/dialog_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def view_template
RUBY
end

render Docs::ComponentsTable.new(component_references(component, Docs::VisualCodeExample.collected_code), component_files(component))
render Docs::ComponentsTable.new(component_files(component))
end
end
end
2 changes: 1 addition & 1 deletion app/views/docs/dropdown_menu_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def view_template
RUBY
end

render Docs::ComponentsTable.new(component_references(component, Docs::VisualCodeExample.collected_code), component_files(component))
render Docs::ComponentsTable.new(component_files(component))
end
end
end
2 changes: 1 addition & 1 deletion app/views/docs/form_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def view_template
RUBY
end

render Docs::ComponentsTable.new(component_references(component, Docs::VisualCodeExample.collected_code), component_files(component))
render Docs::ComponentsTable.new(component_files(component))
end
end
end
2 changes: 1 addition & 1 deletion app/views/docs/hover_card_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def view_template
RUBY
end

render Docs::ComponentsTable.new(component_references(component, Docs::VisualCodeExample.collected_code), component_files(component))
render Docs::ComponentsTable.new(component_files(component))
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/docs/input_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def view_template
RUBY
end

render Docs::ComponentsTable.new(component_references(component, Docs::VisualCodeExample.collected_code), component_files(component))
render Docs::ComponentsTable.new(component_files(component))
end
end
end
6 changes: 3 additions & 3 deletions app/views/docs/link_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ def view_template

render Docs::VisualCodeExample.new(title: "Icon", description: "This is the icon variant of a Link", context: self) do
<<~RUBY
Link(href: "#", variant: :outline, icon: true) do
Link(href: "#", variant: :outline, icon: true) do
chevron_icon
end
RUBY
end

render Docs::VisualCodeExample.new(title: "With Icon", description: "This is the primary variant of a Link with an icon", context: self) do
<<~RUBY
Link(href: "#", variant: :primary) do
Link(href: "#", variant: :primary) do
email_icon
span { "Login with Email" }
end
Expand All @@ -56,7 +56,7 @@ def view_template
RUBY
end

render Docs::ComponentsTable.new(component_references(component, Docs::VisualCodeExample.collected_code), component_files(component))
render Docs::ComponentsTable.new(component_files(component))
end
end

Expand Down
Loading

0 comments on commit aec0f12

Please sign in to comment.