lookbook_storybook_json_generator 0.3.0 → 0.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0918677905f162afe15aaf2e4d59a63709f0b79f14b9fee2561a37d230bfd1cd'
4
- data.tar.gz: 858aca738508af72e733332c0ba93211282bf2542b02bead5879aa3114f77537
3
+ metadata.gz: 521bdf4ded7b02c6d834456c0fd254fc85fcd9f899728e8c9fd7a5e8986ed378
4
+ data.tar.gz: c3ab604a9e1190749df573a90792df5732a1fc6f28d251c040db9521bf114922
5
5
  SHA512:
6
- metadata.gz: 7e41e2a8b9dd88c0e17d39a4bbd40bb4c8203bb37e5dcd5dc4316c1317641e84768889d0eb5ff080c56d4c137ed7cfb56df87105b62d9251ea646e9450584ff0
7
- data.tar.gz: 3ac9349b5754888777ca3aecd231f237c24633bacc64d4259d1e6773938b6e02f5c108414fc07b360e162ab5b107c95d9b7a2a4cf7cc51086466ea9810bba34d
6
+ metadata.gz: ad3fedd7af02b633e271ddcc655a1050cbeb5d4ce1740622066afc923de8531089efae5717bb3e861264efdbd4f46b8e205cf8638fbb3d7950cce3b9cd1f07dc
7
+ data.tar.gz: 07bd22663bb68468b7b95b6da909fb1566feedc6c7373bc25a4720f691f44d5c1483f79a7294c79666f3be4c721890449ce4b92a97f6b1b07f74a156d2dfb850
data/README.md CHANGED
@@ -3,6 +3,8 @@
3
3
  This is a gem that allows you to use lookbook with storybook.
4
4
  It outputs JSON that can be used with storybook.
5
5
 
6
+ https://github.com/forgxisto/lookbook_storybook_json_generator/assets/1164914/08be7939-6882-43cd-9d60-4e4369d007ed
7
+
6
8
  ## Installation
7
9
 
8
10
  Install the gem and add to the application's Gemfile by executing:
@@ -15,13 +17,72 @@ If bundler is not being used to manage dependencies, install the gem by executin
15
17
 
16
18
  ## Usage
17
19
 
18
- TODO: Write usage instructions here
20
+ This gem depends on lookbook.
21
+ No special settings are required.
22
+
23
+ Create `_preview.stories.json` in the same directory as `_preview.rb` written according to the lookbook rules.
24
+
25
+ This JSON is created when the lookbook loads `_preview.rb`.
26
+
27
+ ### example
28
+
29
+ 0. You may want to refer to `dummy_app` in this repository.
30
+
31
+ 1. First, write the following in Gemfile and complete the lookbook settings.
32
+
33
+ ```
34
+ gem 'lookbook'
35
+ gem 'lookbook_storybook_json_generator'
36
+ ```
37
+
38
+ Please refer to the official website for the lookbook.
39
+ https://lookbook.build/
40
+
41
+ 2. Create `_preview.rb` according to the lookbook description rules.
42
+
43
+ By default, it is created under the `test/components/previews/` directory.
44
+
45
+ 3. Start Rails.
46
+
47
+ At this point, the lookbook preview file is read and a JSON file is created in the same directory.
48
+
49
+ 4. Install Storybook.
50
+
51
+ Please refer to the official website for Storybook.
52
+ https://storybook.js.org/
53
+
54
+ 5. To reference the JSON created with this gem in Storybook, use `@storybook/server-webpack5
55
+ Add `.
56
+
57
+ ```
58
+ npm install @storybook/server-webpack5
59
+ ```
60
+
61
+ 6. Set up `.storybook/main.js` and `.storybook/preview.js`.
62
+
63
+ Again, `dummy_app/.storybook/` in this repository may be helpful.
64
+
65
+ See the repository README for details.
66
+ https://www.npmjs.com/package/@storybook/server-webpack5
67
+
68
+ 7. Launch Storybook.
69
+
70
+ That's it! If all goes well, the preview created in lookbook will also be reflected in Storybook.
71
+
72
+ If you have any problems, please raise an issue in this repository.
19
73
 
20
74
  ## Development
21
75
 
22
76
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
23
77
 
24
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
78
+ A small Rails app for development is included in this repository. (located in the `dummy_app` directory)
79
+
80
+ We provide a shortcut command to start this little Rails app.
81
+
82
+ - `bin/dummy_rails` ... start Rails
83
+ - `bin/dummy_storybook` ... start Storybook
84
+
85
+ If you use overmind, we provide a Procfile.
25
86
 
26
87
  ## Contributing
27
88
 
@@ -3,14 +3,35 @@
3
3
  module LookbookStorybookJsonGenerator
4
4
  # lookbook のコードオブジェクトを storybook の json として出力する
5
5
  class StorybookJsonGenerator
6
- def self.execute(code_objects, _args)
7
- code_objects.each do |code_object|
8
- # code_object と同じ場所にファイルを作成する
9
- # ただし、ファイル名は .stories.json とする
10
- file_name = code_object.file.to_s.gsub('.rb', '.stories.json')
11
- json = LookbookStorybookJsonGenerator::LookbookCodeObjectParser.new(code_object).to_json
12
- File.open(file_name, 'w') { _1.puts json }
13
- end
6
+ def self.execute(code_objects, changes = nil)
7
+ new(code_objects, changes).execute
8
+ rescue => e
9
+ Rails.loggoer.warn "LookbookStorybookJsonGenerator #{e.message}"
10
+ end
11
+
12
+ def initialize(code_objects, changes)
13
+ @code_objects = code_objects
14
+ @changes = changes
15
+ end
16
+
17
+ def execute
18
+ generate_all
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :code_objects, :changes
24
+
25
+ def generate_all
26
+ code_objects.each { generate_json(_1) }
27
+ end
28
+
29
+ # code_object と同じ場所にファイルを作成する
30
+ # ただし、ファイル名は .stories.json とする
31
+ def generate_json(code_object)
32
+ file_name = code_object.file.to_s.gsub('.rb', '.stories.json')
33
+ json = LookbookStorybookJsonGenerator::LookbookCodeObjectParser.new(code_object).to_json
34
+ File.open(file_name, 'w') { _1.puts json }
14
35
  end
15
36
  end
16
37
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LookbookStorybookJsonGenerator
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.files = Dir.chdir(__dir__) do
22
22
  `git ls-files -z`.split("\x0").reject do |f|
23
23
  (File.expand_path(f) == __FILE__) ||
24
- f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile dummy_app/])
24
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile dummy_app/ Procfile])
25
25
  end
26
26
  end
27
27
  spec.bindir = 'exe'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lookbook_storybook_json_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ikad
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-17 00:00:00.000000000 Z
11
+ date: 2024-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lookbook