view_component_storybook 0.11.0 → 0.12.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: 0dd708afcf2aa165339b0b1fde82ae610665554e3633c1e50b25509088b43e79
4
- data.tar.gz: 950739b2892877a1451c262dc2110d6885a86c740c7fec9cd626a305feb8313d
3
+ metadata.gz: d7004b9355be5188f56964a21b76fd5e4929917a8a7db77fade82564cb54db30
4
+ data.tar.gz: 869698caed29c33a261571a8e064d5cc260f0882ceea11a7b2652981934d12bf
5
5
  SHA512:
6
- metadata.gz: 3f9b37292f202ac1c79fd4d31b9ace6b067efff03bf60a6f6a7b44a241ce5661c3669a382d9e549461dfe391d9c77fe0b9b98d33a3a5a47ce821d47e9c26ec7d
7
- data.tar.gz: 8e7db14af389ae4d4b2dbcf269269476ac9309c9e518226afedbef769e31f72d32ed44a61382f9830836cab5a4ceba45a701af0a66861de31f928713be9b6c55
6
+ metadata.gz: f067153bdb1ebfacf6a95c62bfe82c591f4984b621d7c37694202a31b1be333fd723f875127d16de037d6751e3474e0c31f4ea760b569166062deb27d13107e0
7
+ data.tar.gz: 22be61b5dee0d65f0641a167bfc848346bd10212dc6d5c76fd3c6de55e819aa0203c766f1c46a06c3a59dc0253e15a49aa65cd406833c6bddb5c40570c1e4ae6
@@ -8,8 +8,8 @@ module ViewComponent
8
8
 
9
9
  validates :type, :options, presence: true
10
10
 
11
- def initialize(type, options, default_value, labels: nil, param: nil, name: nil)
12
- super(default_value, param: param, name: name)
11
+ def initialize(type, options, default_value, labels: nil, param: nil, name: nil, description: nil)
12
+ super(default_value, param: param, name: name, description: description)
13
13
  @type = type
14
14
  @options = options
15
15
  @labels = labels
@@ -6,8 +6,8 @@ module ViewComponent
6
6
  class ColorConfig < SimpleControlConfig
7
7
  attr_reader :preset_colors
8
8
 
9
- def initialize(default_value, preset_colors: nil, param: nil, name: nil)
10
- super(default_value, param: param, name: name)
9
+ def initialize(default_value, preset_colors: nil, param: nil, name: nil, description: nil)
10
+ super(default_value, param: param, name: name, description: description)
11
11
  @preset_colors = preset_colors
12
12
  end
13
13
 
@@ -8,9 +8,10 @@ module ViewComponent
8
8
 
9
9
  validates :param, presence: true
10
10
 
11
- def initialize(param: nil, name: nil)
11
+ def initialize(param: nil, name: nil, description: nil)
12
12
  @param = param
13
13
  @name = name
14
+ @description = description
14
15
  end
15
16
 
16
17
  def name(new_name = nil)
@@ -22,6 +23,13 @@ module ViewComponent
22
23
  end
23
24
  end
24
25
 
26
+ def description(new_description = nil)
27
+ return @description if new_description.nil?
28
+
29
+ @description = new_description
30
+ self
31
+ end
32
+
25
33
  def param(new_param = nil)
26
34
  return @param if new_param.nil?
27
35
 
@@ -4,8 +4,8 @@ module ViewComponent
4
4
  module Storybook
5
5
  module Controls
6
6
  class DateConfig < SimpleControlConfig
7
- def initialize(default_value, param: nil, name: nil)
8
- super(default_value, param: param, name: name)
7
+ def initialize(default_value, param: nil, name: nil, description: nil)
8
+ super(default_value, param: param, name: name, description: description)
9
9
  end
10
10
 
11
11
  def type
@@ -9,8 +9,8 @@ module ViewComponent
9
9
  validates :type, inclusion: { in: TYPES }, unless: -> { type.nil? }
10
10
  validate :validate_default_value, unless: -> { options.nil? || default_value.nil? }
11
11
 
12
- def initialize(type, options, default_value, labels: nil, param: nil, name: nil)
13
- super(type, options, Array.wrap(default_value), labels: labels, param: param, name: name)
12
+ def initialize(type, options, default_value, labels: nil, param: nil, name: nil, description: nil)
13
+ super(type, options, Array.wrap(default_value), labels: labels, param: param, name: name, description: description)
14
14
  end
15
15
 
16
16
  def value_from_params(params)
@@ -11,8 +11,8 @@ module ViewComponent
11
11
  validates :type, presence: true
12
12
  validates :type, inclusion: { in: TYPES }, unless: -> { type.nil? }
13
13
 
14
- def initialize(type, default_value, min: nil, max: nil, step: nil, param: nil, name: nil)
15
- super(default_value, param: param, name: name)
14
+ def initialize(type, default_value, min: nil, max: nil, step: nil, param: nil, name: nil, description: nil)
15
+ super(default_value, param: param, name: name, description: description)
16
16
  @type = type
17
17
  @min = min
18
18
  @max = max
@@ -9,8 +9,8 @@ module ViewComponent
9
9
  class SimpleControlConfig < ControlConfig
10
10
  attr_reader :default_value
11
11
 
12
- def initialize(default_value, param: nil, name: nil)
13
- super(param: param, name: name)
12
+ def initialize(default_value, param: nil, name: nil, description: nil)
13
+ super(param: param, name: name, description: description)
14
14
  @default_value = default_value
15
15
  end
16
16
 
@@ -18,7 +18,9 @@ module ViewComponent
18
18
  validate!
19
19
  {
20
20
  args: { param => csf_value },
21
- argTypes: { param => { control: csf_control_params, name: name } }
21
+ argTypes: {
22
+ param => { control: csf_control_params, name: name, description: description }.compact
23
+ }
22
24
  }
23
25
  end
24
26
 
@@ -11,12 +11,14 @@ module ViewComponent
11
11
  options = app.config.view_component_storybook
12
12
 
13
13
  options.show_stories = Rails.env.development? if options.show_stories.nil?
14
- options.stories_route ||= ViewComponent::Storybook.stories_route
14
+ options.stories_route ||= "/rails/stories"
15
15
 
16
16
  if options.show_stories
17
- options.stories_path ||= defined?(Rails.root) ? Rails.root.join("test/components/stories") : nil
17
+ options.stories_path ||= defined?(Rails.root) ? Rails.root.join("test/components/stories").to_s : nil
18
18
  end
19
19
 
20
+ options.stories_title_generator ||= ViewComponent::Storybook.stories_title_generator
21
+
20
22
  ActiveSupport.on_load(:view_component_storybook) do
21
23
  options.each { |k, v| send("#{k}=", v) }
22
24
  end
@@ -25,7 +27,11 @@ module ViewComponent
25
27
  initializer "view_component.set_autoload_paths" do |app|
26
28
  options = app.config.view_component_storybook
27
29
 
28
- ActiveSupport::Dependencies.autoload_paths << options.stories_path if options.show_stories && options.stories_path
30
+ if options.show_stories &&
31
+ options.stories_path &&
32
+ ActiveSupport::Dependencies.autoload_paths.exclude?(options.stories_path)
33
+ ActiveSupport::Dependencies.autoload_paths << options.stories_path
34
+ end
29
35
  end
30
36
 
31
37
  config.after_initialize do |app|
@@ -46,7 +52,7 @@ module ViewComponent
46
52
  end
47
53
 
48
54
  # :nocov:
49
- unless defined?(ViewComponent::Storybook)
55
+ unless defined?(ViewComponent::Storybook::Stories)
50
56
  ActiveSupport::Deprecation.warn(
51
57
  "This manually engine loading is deprecated and will be removed in v1.0.0. " \
52
58
  "Remove `require \"view_component/storybook/engine\"`."
@@ -16,7 +16,7 @@ module ViewComponent
16
16
  end
17
17
 
18
18
  def call(&block)
19
- component.send(slot_name, *slot_method_args.args, **slot_method_args.kwargs, &block)
19
+ component.send("with_#{slot_name}", *slot_method_args.args, **slot_method_args.kwargs, &block)
20
20
  end
21
21
  end
22
22
  end
@@ -27,10 +27,10 @@ module ViewComponent
27
27
  )
28
28
  end
29
29
 
30
- def slot(componeont, params)
30
+ def slot(component, params)
31
31
  resolved_method_args = slot_method_args.resolve_method_args(params)
32
32
  story_content_block = resolve_content_block(params)
33
- Slot.new(componeont, slot_name, resolved_method_args, story_content_block)
33
+ Slot.new(component, slot_name, resolved_method_args, story_content_block)
34
34
  end
35
35
 
36
36
  def controls
@@ -99,7 +99,7 @@ module ViewComponent
99
99
  def inherited(other)
100
100
  super(other)
101
101
  # setup class defaults
102
- other.stories_title = other.stories_name.humanize.titlecase
102
+ other.stories_title = Storybook.stories_title_generator.call(other)
103
103
  other.story_configs = []
104
104
  end
105
105
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ViewComponent
4
4
  module Storybook
5
- VERSION = "0.11.0"
5
+ VERSION = "0.12.0"
6
6
  end
7
7
  end
@@ -37,9 +37,7 @@ module ViewComponent
37
37
  #
38
38
  # Defaults to `/rails/stories` when `show_stories` is enabled.
39
39
  #
40
- mattr_accessor :stories_route, instance_writer: false do
41
- "/rails/stories"
42
- end
40
+ mattr_accessor :stories_route, instance_writer: false
43
41
 
44
42
  # :nocov:
45
43
  if defined?(ViewComponent::Storybook::Engine)
@@ -52,6 +50,15 @@ module ViewComponent
52
50
  end
53
51
  # :nocov:
54
52
 
53
+ # Define how component stories titles are generated:
54
+ #
55
+ # config.view_component_storybook.stories_title_generator = lambda { |stories|
56
+ # stories.stories_name.humanize.upcase
57
+ # }
58
+ #
59
+ mattr_accessor :stories_title_generator, instance_writer: false,
60
+ default: ->(stories) { stories.stories_name.humanize.titlecase }
61
+
55
62
  ActiveSupport.run_load_hooks(:view_component_storybook, self)
56
63
  end
57
64
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_component_storybook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Palmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-14 00:00:00.000000000 Z
11
+ date: 2022-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: view_component
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '2.36'
19
+ version: '2.54'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '2.36'
26
+ version: '2.54'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '5.0'
117
+ version: '5.1'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '5.0'
124
+ version: '5.1'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rubocop
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -192,6 +192,20 @@ dependencies:
192
192
  - - "~>"
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0.9'
195
+ - !ruby/object:Gem::Dependency
196
+ name: sprockets-rails
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: 3.4.2
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: 3.4.2
195
209
  description: Generate Storybook CSF JSON for rendering Rails View Components in Storybook
196
210
  email:
197
211
  - 328224+jonspalmer@users.noreply.github.com
@@ -253,14 +267,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
253
267
  requirements:
254
268
  - - ">="
255
269
  - !ruby/object:Gem::Version
256
- version: 2.5.0
270
+ version: 2.6.0
257
271
  required_rubygems_version: !ruby/object:Gem::Requirement
258
272
  requirements:
259
273
  - - ">="
260
274
  - !ruby/object:Gem::Version
261
275
  version: '0'
262
276
  requirements: []
263
- rubygems_version: 3.0.6
277
+ rubygems_version: 3.1.6
264
278
  signing_key:
265
279
  specification_version: 4
266
280
  summary: Storybook for Rails View Components