storybook_rails 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3156e720148b32541cf3a26364ab48422d8578c0f77ed0a5af2b79d6464c389c
4
- data.tar.gz: 5c8aca3a712de9a7b937967629e465cac1319f339163f3a3e81fcd6877098ac6
3
+ metadata.gz: 3d9e73c7b0bf6d8f82291a937ef7d37f74621b5e1803d561a7396829ca4f61c3
4
+ data.tar.gz: ce0f60e3dd44c77e3678287d74ac340b3d5dd3233b1f7d52e31f083d734acb8d
5
5
  SHA512:
6
- metadata.gz: 1f4973da1272dfb432b3a6cbd8d9fc09430aad699887885f947550c95a6a5045e520c4cf200c2f34b876fb553e4e257d53a32efb5bb173dbaf3653078374d940
7
- data.tar.gz: 277c3bf438cc3f5f438072abd7066a76d4b4242e3754d7b0d24cc48123afd037de985aff8a996b146bfb016b1af91b239c580cd6d5ac460d2269db3ddea6835c
6
+ metadata.gz: 6a7b37fc8c986e55f9926c307e8966b40cc855f0174f2cf9c9fd7b4e2458abe3b634471edcfc007b85b1822f4ca2a231e149cfe995228fa499a7a280f54794b7
7
+ data.tar.gz: 8f6e2d0188d83131473477881735d314c3f118f3dbe08c6028e5650fe4b58e6b9b804b0df66d3f022043a1f262a5deb5d43e92d2c5db26ff09ed0cfc2340c772
data/LICENSE.txt CHANGED
@@ -1,6 +1,7 @@
1
1
  The MIT License (MIT)
2
2
 
3
3
  Copyright (c) 2020 Jon Palmer
4
+ Copyright (c) 2021 Daniel Pence
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -22,7 +22,7 @@ This gem is a fork of [ViewComponent::Storybook](https://github.com/jonspalmer/v
22
22
  #### Configure Asset Hosts
23
23
 
24
24
  If your views depend on Javascript, CSS or other assets served by the Rails application you will need to configure `asset_hosts`
25
- apporpriately for your various environments. For local development this is a simple as adding to `config/development.rb`:
25
+ appropriately for your various environments. For local development, do this by adding the following to `config/development.rb`:
26
26
  ```ruby
27
27
  Rails.application.configure do
28
28
  ...
@@ -65,7 +65,7 @@ Equivalent configuration will be necessary in `config/production.rb` or `applica
65
65
  };
66
66
  ```
67
67
 
68
- #### Webpacker
68
+ ### Webpacker
69
69
  If your application uses Webpacker to compile your JavaScript and/or CSS, you will need to modify the default Storybook webpack configuration. Please see the [Storybook Webpack config](https://storybook.js.org/docs/react/configure/webpack) for more information on how to do that. Here's an example:
70
70
 
71
71
  ```javascript
@@ -105,6 +105,26 @@ module.exports = {
105
105
  };
106
106
  ```
107
107
 
108
+ ### Optional Nice-To-Haves
109
+ #### Setup File-Watching and Automatically run `rake storybook_rails:write_stories_json`
110
+ For a better developer experience, install your favorite file watching utility, such as [chokidar](https://github.com/kimmobrunfeldt/chokidar-cli) and add a couple scripts to enable automatic regeneration of `*.stories.json` files when you update `*_stories.rb` files:
111
+
112
+ `yarn add -D chokidar-cli`
113
+
114
+ In package.json:
115
+ ```js
116
+ {
117
+ ...
118
+ "scripts": {
119
+ "storybook:start": "rm -rf node_modules/.cache/storybook && start-storybook",
120
+ "storybook:write-json": "bundle exec rake storybook_rails:write_stories_json",
121
+ "storybook:watch": "chokidar '**/*_stories.rb' -c 'yarn storybook:write-json'"
122
+ },
123
+ ...
124
+ }
125
+ ```
126
+
127
+
108
128
  ## Usage
109
129
 
110
130
  ### Writing Stories
@@ -195,6 +215,17 @@ By Default `storybook_rails` expects to find stories in the folder `test/compone
195
215
  config.storybook_rails.stories_path = Rails.root.join("spec/components/stories")
196
216
  ```
197
217
 
218
+ ### Troubleshooting
219
+ #### Restarting Storybook Fails
220
+ If Storybook fails to load with a `cannot get /` error, it could be related to [this issue](https://github.com/storybookjs/storybook/issues/14152). As a workaround, you can update the `yarn storybook` script to remove the `node_modules/.cache/storybook` files before Storybook starts:
221
+ ```json
222
+ {
223
+ "scripts": {
224
+ "storybook": "rm -rf node_modules/.cache/storybook && start-storybook"
225
+ }
226
+ }
227
+ ```
228
+
198
229
  ### The Story DSL
199
230
 
200
231
  Coming Soon
@@ -18,7 +18,7 @@ module ActionView
18
18
  story_params = @story.values_from_params(params.permit!.to_h)
19
19
  story_params.deep_merge!(story_name: params[:story_name])
20
20
 
21
- render template: "#{@story.template}", layout: @story.layout, locals: { story_params: story_params }
21
+ render template: @story.template.to_s, layout: @story.layout, locals: { story_params: story_params }
22
22
  end
23
23
 
24
24
  private
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module StoryParamsHelper
2
4
  def story_params
3
- params.dig(:story_params)
5
+ params[:story_params]
4
6
  end
5
7
  end
@@ -97,14 +97,14 @@ module ActionView
97
97
  end
98
98
 
99
99
  def default_template
100
- "#{name.chomp("Stories").underscore}_stories"
100
+ "#{name.chomp('Stories').underscore}_stories"
101
101
  end
102
102
 
103
103
  def load_stories
104
- if stories_path
105
- Dir["#{stories_path}/**/*_stories.rb"].sort.each do |file|
106
- require_dependency file
107
- end
104
+ return unless stories_path
105
+
106
+ Dir["#{stories_path}/**/*_stories.rb"].sort.each do |file|
107
+ require_dependency file
108
108
  end
109
109
  end
110
110
 
@@ -20,15 +20,15 @@ module ActionView
20
20
 
21
21
  def to_csf_params
22
22
  validate!
23
- csf_params = {
23
+ csf_params = {
24
24
  name: pretty_name(name),
25
- parameters: {
26
- server: {
25
+ parameters: {
26
+ server: {
27
27
  id: id,
28
- params: {
29
- story_name: name
30
- }
31
- }
28
+ params: {
29
+ story_name: name
30
+ }
31
+ }
32
32
  }
33
33
  }
34
34
  csf_params.deep_merge!(parameters: parameters) if parameters.present?
@@ -59,10 +59,6 @@ module ActionView
59
59
  protected
60
60
 
61
61
  def valid_controls
62
- controls.reject(&:valid?).each do |control|
63
- errors.add(:controls, :invalid, value: control)
64
- end
65
-
66
62
  control_names = controls.map(&:name)
67
63
  duplicate_names = control_names.group_by(&:itself).map { |k, v| k if v.length > 1 }.compact
68
64
  return if duplicate_names.empty?
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActionView
4
4
  module Storybook
5
- VERSION = "1.0.0"
5
+ VERSION = "1.1.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: storybook_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Pence
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-26 00:00:00.000000000 Z
11
+ date: 2021-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler