view_component_storybook 0.9.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -138
  3. data/app/controllers/view_component/storybook/stories_controller.rb +9 -11
  4. data/app/views/view_component/storybook/stories/show.html.erb +8 -3
  5. data/config/locales/en.yml +1 -1
  6. data/lib/view_component/storybook/content_concern.rb +42 -0
  7. data/lib/view_component/storybook/controls/base_options_config.rb +41 -0
  8. data/lib/view_component/storybook/controls/control_config.rb +4 -0
  9. data/lib/view_component/storybook/{dsl/controls_dsl.rb → controls/controls_helpers.rb} +21 -16
  10. data/lib/view_component/storybook/controls/custom_config.rb +2 -4
  11. data/lib/view_component/storybook/controls/multi_options_config.rb +46 -0
  12. data/lib/view_component/storybook/controls/object_config.rb +3 -1
  13. data/lib/view_component/storybook/controls/options_config.rb +12 -26
  14. data/lib/view_component/storybook/controls/simple_control_config.rb +1 -1
  15. data/lib/view_component/storybook/controls.rb +3 -1
  16. data/lib/view_component/storybook/dsl/legacy_controls_dsl.rb +2 -2
  17. data/lib/view_component/storybook/dsl.rb +0 -2
  18. data/lib/view_component/storybook/engine.rb +13 -2
  19. data/lib/view_component/storybook/method_args/component_constructor_args.rb +23 -0
  20. data/lib/view_component/storybook/method_args/control_method_args.rb +15 -12
  21. data/lib/view_component/storybook/method_args/dry_initializer_component_constructor_args.rb +45 -0
  22. data/lib/view_component/storybook/method_args/method_args.rb +37 -4
  23. data/lib/view_component/storybook/method_args/method_parameters_names.rb +1 -1
  24. data/lib/view_component/storybook/method_args.rb +2 -1
  25. data/lib/view_component/storybook/slots/slot.rb +24 -0
  26. data/lib/view_component/storybook/slots/slot_config.rb +79 -0
  27. data/lib/view_component/storybook/slots.rb +14 -0
  28. data/lib/view_component/storybook/stories.rb +17 -10
  29. data/lib/view_component/storybook/story.rb +18 -0
  30. data/lib/view_component/storybook/story_config.rb +120 -26
  31. data/lib/view_component/storybook/tasks/write_stories_json.rake +1 -1
  32. data/lib/view_component/storybook/version.rb +1 -1
  33. data/lib/view_component/storybook.rb +23 -2
  34. metadata +43 -8
  35. data/lib/view_component/storybook/controls/array_config.rb +0 -37
  36. data/lib/view_component/storybook/dsl/story_dsl.rb +0 -51
  37. data/lib/view_component/storybook/method_args/validatable_method_args.rb +0 -50
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.9.0
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Palmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-13 00:00:00.000000000 Z
11
+ date: 2022-02-14 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.2'
19
+ version: '2.36'
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.2'
26
+ version: '2.36'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: capybara
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: dry-initializer
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.0.4
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.0.4
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: rake
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -177,29 +205,35 @@ files:
177
205
  - app/views/view_component/storybook/stories/show.html.erb
178
206
  - config/locales/en.yml
179
207
  - lib/view_component/storybook.rb
208
+ - lib/view_component/storybook/content_concern.rb
180
209
  - lib/view_component/storybook/controls.rb
181
- - lib/view_component/storybook/controls/array_config.rb
210
+ - lib/view_component/storybook/controls/base_options_config.rb
182
211
  - lib/view_component/storybook/controls/boolean_config.rb
183
212
  - lib/view_component/storybook/controls/color_config.rb
184
213
  - lib/view_component/storybook/controls/control_config.rb
214
+ - lib/view_component/storybook/controls/controls_helpers.rb
185
215
  - lib/view_component/storybook/controls/custom_config.rb
186
216
  - lib/view_component/storybook/controls/date_config.rb
217
+ - lib/view_component/storybook/controls/multi_options_config.rb
187
218
  - lib/view_component/storybook/controls/number_config.rb
188
219
  - lib/view_component/storybook/controls/object_config.rb
189
220
  - lib/view_component/storybook/controls/options_config.rb
190
221
  - lib/view_component/storybook/controls/simple_control_config.rb
191
222
  - lib/view_component/storybook/controls/text_config.rb
192
223
  - lib/view_component/storybook/dsl.rb
193
- - lib/view_component/storybook/dsl/controls_dsl.rb
194
224
  - lib/view_component/storybook/dsl/legacy_controls_dsl.rb
195
- - lib/view_component/storybook/dsl/story_dsl.rb
196
225
  - lib/view_component/storybook/engine.rb
197
226
  - lib/view_component/storybook/method_args.rb
227
+ - lib/view_component/storybook/method_args/component_constructor_args.rb
198
228
  - lib/view_component/storybook/method_args/control_method_args.rb
229
+ - lib/view_component/storybook/method_args/dry_initializer_component_constructor_args.rb
199
230
  - lib/view_component/storybook/method_args/method_args.rb
200
231
  - lib/view_component/storybook/method_args/method_parameters_names.rb
201
- - lib/view_component/storybook/method_args/validatable_method_args.rb
232
+ - lib/view_component/storybook/slots.rb
233
+ - lib/view_component/storybook/slots/slot.rb
234
+ - lib/view_component/storybook/slots/slot_config.rb
202
235
  - lib/view_component/storybook/stories.rb
236
+ - lib/view_component/storybook/story.rb
203
237
  - lib/view_component/storybook/story_config.rb
204
238
  - lib/view_component/storybook/tasks/write_stories_json.rake
205
239
  - lib/view_component/storybook/version.rb
@@ -210,6 +244,7 @@ metadata:
210
244
  allowed_push_host: https://rubygems.org
211
245
  homepage_uri: https://github.com/jonspalmer/view_component_storybook
212
246
  source_code_uri: https://github.com/jonspalmer/view_component_storybook
247
+ rubygems_mfa_required: 'true'
213
248
  post_install_message:
214
249
  rdoc_options: []
215
250
  require_paths:
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ViewComponent
4
- module Storybook
5
- module Controls
6
- class ArrayConfig < SimpleControlConfig
7
- attr_reader :separator
8
-
9
- validates :separator, presence: true
10
-
11
- def initialize(default_value, separator = ",", param: nil, name: nil)
12
- super(default_value, param: param, name: name)
13
- @separator = separator
14
- end
15
-
16
- def type
17
- :array
18
- end
19
-
20
- def value_from_params(params)
21
- params_value = super(params)
22
- if params_value.is_a?(String)
23
- params_value.split(separator)
24
- else
25
- params_value
26
- end
27
- end
28
-
29
- private
30
-
31
- def csf_control_params
32
- super.merge(separator: separator)
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ViewComponent
4
- module Storybook
5
- module Dsl
6
- class StoryDsl
7
- include ControlsDsl
8
-
9
- def self.evaluate!(story_config, &block)
10
- new(story_config).instance_eval(&block)
11
- end
12
-
13
- def parameters(**params)
14
- story_config.parameters = params
15
- end
16
-
17
- def controls(&block)
18
- ActiveSupport::Deprecation.warn("`controls` will be removed in v1.0.0. Use `#constructor` instead.")
19
- controls_dsl = LegacyControlsDsl.new
20
- controls_dsl.instance_eval(&block)
21
-
22
- controls_hash = controls_dsl.controls.index_by(&:param)
23
- story_config.constructor_args(**controls_hash)
24
- end
25
-
26
- def layout(layout)
27
- story_config.layout = layout
28
- end
29
-
30
- def content(&block)
31
- story_config.content_block = block
32
- end
33
-
34
- def constructor(*args, **kwargs, &block)
35
- story_config.constructor_args(*args, **kwargs)
36
- story_config.content_block = block
37
- end
38
-
39
- delegate :component, to: :story_config
40
-
41
- private
42
-
43
- attr_reader :story_config
44
-
45
- def initialize(story_config)
46
- @story_config = story_config
47
- end
48
- end
49
- end
50
- end
51
- end
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ViewComponent
4
- module Storybook
5
- module MethodArgs
6
- ##
7
- # Class representing arguments passed to a method which can be validated
8
- # against the args of the target method
9
- class ValidatableMethodArgs < MethodArgs
10
- include ActiveModel::Validations
11
-
12
- attr_reader :target_method_params_names
13
-
14
- validate :validate_args, :validate_kwargs
15
-
16
- def initialize(target_method, *args, **kwargs, &block)
17
- @target_method_params_names = MethodParametersNames.new(target_method)
18
- super(args, kwargs, block)
19
- end
20
-
21
- private
22
-
23
- def validate_args
24
- arg_count = args.count
25
-
26
- if arg_count > target_method_params_names.max_arg_count
27
- errors.add(:args, :too_many, max: target_method_params_names.max_arg_count, count: arg_count)
28
- elsif arg_count < target_method_params_names.min_arg_count
29
- errors.add(:args, :too_few, min: target_method_params_names.min_arg_count, count: arg_count)
30
- end
31
- end
32
-
33
- def validate_kwargs
34
- kwargs.each_key do |kwarg|
35
- unless target_method_params_names.include_kwarg?(kwarg)
36
- errors.add(:kwargs, :invalid_arg, kwarg: kwarg)
37
- end
38
- end
39
-
40
- return if target_method_params_names.covers_required_kwargs?(kwargs.keys)
41
-
42
- expected_keys = target_method_params_names.req_kwarg_names.join(', ')
43
- actual_keys = kwargs.keys.join(', ')
44
-
45
- errors.add(:kwargs, :invalid, expected_keys: expected_keys, actual_keys: actual_keys)
46
- end
47
- end
48
- end
49
- end
50
- end