Skip to content

Commit

Permalink
feat: install task creates an initializer; added more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jrogers-hedgeye committed Sep 6, 2024
1 parent b1bd86c commit 303917a
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
phlex_storybook (0.2.0)
phlex_storybook (0.2.1)
importmap-rails
phlex-icons (~> 0.11.0)
phlex-rails (~> 1.2)
Expand Down
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,42 @@ Then run the installer:
rails phlex_storybook:install
```

By default, this creates an initializer at `config/initializers/phlex_storybook.rb`, which looks in
`app/components` for your registered Phlex components. Those components should register themselves
with the storybook. E.g.

```ruby
class HelloWorld < Phlex::HTML
register_component do
# component_category is optional, non-categorized components will appear under "Uncategorized"
component_category "Category 1"

# component_name is optional, it defaults to the name of your component
component_name "Good ol' Hello"

# component_description is optional
component_description "The typical programmer's first attempt..."

# component props are required if your component takes arguments in #initialize
component_props [
PhlexStorybook::Props::String.new(key: :who, placeholder: "Who do you want to say hello to?")
]

# component stories are optional; they are predefined instances of your component
component_stories "Arnold" => { who: "Arnie Schwarzenegger" },
"Reagan" => { who: "Ronnie" }
end

def initialize(who: "world")
@who = who
end

def view_template
div { "hello #{@who}!" }
end
end
```

## License

The gem is available as open source under the terms of the [MIT License](LICENSE).
14 changes: 14 additions & 0 deletions lib/phlex_storybook/tasks/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ class Install < Thor
def install
say "Adding phlex_storybook to your application manifest..."
append_to_file("app/assets/config/manifest.js", "//= link phlex_storybook_manifest.js\n")
create_file("config/initializers/phlex_storybook.rb") do
<<~RUBY
# frozen_string_literal: true
#
# Make sure to add register_component blocks to your components
#
# Example:
# register_component do
# component_category "Category 1"
# end
Dir[Rails.root.join("app/components/**/*.rb").to_s].each { |file| require file }
RUBY
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/phlex_storybook/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module PhlexStorybook
VERSION = "0.2.0"
VERSION = "0.2.1"
end
4 changes: 3 additions & 1 deletion phlex_storybook.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ Gem::Specification.new do |spec|
$ bin/rails phlex_storybook:install
Then add phlex_storybook to your application by mounting it in your `config/routes.rb` file:
Then, add phlex_storybook to your application by mounting it in your `config/routes.rb` file:
Rails.application.routes.draw do
mount PhlexStorybook::Engine => "/phlex_storybook"
end
If necessary, update the `config/initializers/phlex_storybook.rb` file with the path(s) to your components.
MESSAGE

spec.metadata["homepage_uri"] = spec.homepage
Expand Down
2 changes: 0 additions & 2 deletions test/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ class Application < Rails::Application
config.autoload_paths << "#{root}/app/components"
config.load_defaults Rails::VERSION::STRING.to_f

Dir["#{root}/app/components/**/*.rb"].each { |file| require file }

# For compatibility with applications that use this config
config.action_controller.include_all_helpers = false

Expand Down
5 changes: 3 additions & 2 deletions test/dummy/config/initializers/phlex_storybook.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
PhlexStorybook.configure do |config|
end
# frozen_string_literal: true

Dir[Rails.root.join("app/components/**/*.rb").to_s].each { |file| require file }

0 comments on commit 303917a

Please sign in to comment.