rails-storybook 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 83b229f8189dd57281db3c891bb6b36b8a437777bdb964ea059a652c8c2c9aad
4
+ data.tar.gz: 616420336b4acf5a60967d24498ebeeb004d31169ca7f5de85a309d4795c0ca2
5
+ SHA512:
6
+ metadata.gz: 941d4806670ba38473617ecab1a385788da1d56de11267c9372d884c47bf6b45fd191d6b5d40816858f247b70242e1cb089a2bf1ac16da2633be49fbb8a92587
7
+ data.tar.gz: 9cc2e89ded7fd27eec72f7b3127acdf854bc6de168e8ffbfe1409ea168ca2bb869702e016ae18e9752cd13657bf96ceb59b624f30cc0102563eb16d59463cb34
@@ -0,0 +1,37 @@
1
+ name: Test & lint
2
+ on: [push, pull_request]
3
+
4
+ jobs:
5
+ tests:
6
+ name: Test
7
+ runs-on: ubuntu-latest
8
+
9
+ steps:
10
+ - name: Checkout code
11
+ uses: actions/checkout@v4
12
+ with:
13
+ fetch-depth: '20'
14
+
15
+ - name: Setup Ruby
16
+ uses: ruby/setup-ruby@v1
17
+
18
+ - run: bundle install
19
+
20
+ - name: RSpec
21
+ run: bundle exec rspec
22
+
23
+ lint:
24
+ name: Lint
25
+ runs-on: ubuntu-latest
26
+
27
+ steps:
28
+ - name: Checkout code
29
+ uses: actions/checkout@v4
30
+
31
+ - name: Setup Ruby
32
+ uses: ruby/setup-ruby@v1
33
+
34
+ - run: bundle install
35
+
36
+ - name: Run linter
37
+ run: bundle exec rubocop
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ inherit_gem:
2
+ rubocop-rails-omakase: rubocop.yml
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-3.3.4
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.10
7
+ before_install: gem install bundler -v 1.17.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at nicktbarone@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in rails-storybook.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,266 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rails-storybook (0.1.0)
5
+ rails (~> 7.0)
6
+ slim (~> 5.2)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actioncable (7.1.3.4)
12
+ actionpack (= 7.1.3.4)
13
+ activesupport (= 7.1.3.4)
14
+ nio4r (~> 2.0)
15
+ websocket-driver (>= 0.6.1)
16
+ zeitwerk (~> 2.6)
17
+ actionmailbox (7.1.3.4)
18
+ actionpack (= 7.1.3.4)
19
+ activejob (= 7.1.3.4)
20
+ activerecord (= 7.1.3.4)
21
+ activestorage (= 7.1.3.4)
22
+ activesupport (= 7.1.3.4)
23
+ mail (>= 2.7.1)
24
+ net-imap
25
+ net-pop
26
+ net-smtp
27
+ actionmailer (7.1.3.4)
28
+ actionpack (= 7.1.3.4)
29
+ actionview (= 7.1.3.4)
30
+ activejob (= 7.1.3.4)
31
+ activesupport (= 7.1.3.4)
32
+ mail (~> 2.5, >= 2.5.4)
33
+ net-imap
34
+ net-pop
35
+ net-smtp
36
+ rails-dom-testing (~> 2.2)
37
+ actionpack (7.1.3.4)
38
+ actionview (= 7.1.3.4)
39
+ activesupport (= 7.1.3.4)
40
+ nokogiri (>= 1.8.5)
41
+ racc
42
+ rack (>= 2.2.4)
43
+ rack-session (>= 1.0.1)
44
+ rack-test (>= 0.6.3)
45
+ rails-dom-testing (~> 2.2)
46
+ rails-html-sanitizer (~> 1.6)
47
+ actiontext (7.1.3.4)
48
+ actionpack (= 7.1.3.4)
49
+ activerecord (= 7.1.3.4)
50
+ activestorage (= 7.1.3.4)
51
+ activesupport (= 7.1.3.4)
52
+ globalid (>= 0.6.0)
53
+ nokogiri (>= 1.8.5)
54
+ actionview (7.1.3.4)
55
+ activesupport (= 7.1.3.4)
56
+ builder (~> 3.1)
57
+ erubi (~> 1.11)
58
+ rails-dom-testing (~> 2.2)
59
+ rails-html-sanitizer (~> 1.6)
60
+ activejob (7.1.3.4)
61
+ activesupport (= 7.1.3.4)
62
+ globalid (>= 0.3.6)
63
+ activemodel (7.1.3.4)
64
+ activesupport (= 7.1.3.4)
65
+ activerecord (7.1.3.4)
66
+ activemodel (= 7.1.3.4)
67
+ activesupport (= 7.1.3.4)
68
+ timeout (>= 0.4.0)
69
+ activestorage (7.1.3.4)
70
+ actionpack (= 7.1.3.4)
71
+ activejob (= 7.1.3.4)
72
+ activerecord (= 7.1.3.4)
73
+ activesupport (= 7.1.3.4)
74
+ marcel (~> 1.0)
75
+ activesupport (7.1.3.4)
76
+ base64
77
+ bigdecimal
78
+ concurrent-ruby (~> 1.0, >= 1.0.2)
79
+ connection_pool (>= 2.2.5)
80
+ drb
81
+ i18n (>= 1.6, < 2)
82
+ minitest (>= 5.1)
83
+ mutex_m
84
+ tzinfo (~> 2.0)
85
+ ast (2.4.2)
86
+ base64 (0.2.0)
87
+ bigdecimal (3.1.8)
88
+ builder (3.3.0)
89
+ concurrent-ruby (1.3.3)
90
+ connection_pool (2.4.1)
91
+ crass (1.0.6)
92
+ date (3.3.4)
93
+ debug (1.9.2)
94
+ irb (~> 1.10)
95
+ reline (>= 0.3.8)
96
+ diff-lcs (1.5.1)
97
+ drb (2.2.1)
98
+ erubi (1.13.0)
99
+ globalid (1.2.1)
100
+ activesupport (>= 6.1)
101
+ i18n (1.14.5)
102
+ concurrent-ruby (~> 1.0)
103
+ io-console (0.7.2)
104
+ irb (1.14.0)
105
+ rdoc (>= 4.0.0)
106
+ reline (>= 0.4.2)
107
+ json (2.7.2)
108
+ language_server-protocol (3.17.0.3)
109
+ loofah (2.22.0)
110
+ crass (~> 1.0.2)
111
+ nokogiri (>= 1.12.0)
112
+ mail (2.8.1)
113
+ mini_mime (>= 0.1.1)
114
+ net-imap
115
+ net-pop
116
+ net-smtp
117
+ marcel (1.0.4)
118
+ mini_mime (1.1.5)
119
+ mini_portile2 (2.8.7)
120
+ minitest (5.24.1)
121
+ mutex_m (0.2.0)
122
+ net-imap (0.4.14)
123
+ date
124
+ net-protocol
125
+ net-pop (0.1.2)
126
+ net-protocol
127
+ net-protocol (0.2.2)
128
+ timeout
129
+ net-smtp (0.5.0)
130
+ net-protocol
131
+ nio4r (2.7.3)
132
+ nokogiri (1.16.7)
133
+ mini_portile2 (~> 2.8.2)
134
+ racc (~> 1.4)
135
+ nokogiri (1.16.7-x86_64-darwin)
136
+ racc (~> 1.4)
137
+ parallel (1.25.1)
138
+ parser (3.3.4.0)
139
+ ast (~> 2.4.1)
140
+ racc
141
+ psych (5.1.2)
142
+ stringio
143
+ racc (1.8.1)
144
+ rack (3.1.7)
145
+ rack-session (2.0.0)
146
+ rack (>= 3.0.0)
147
+ rack-test (2.1.0)
148
+ rack (>= 1.3)
149
+ rackup (2.1.0)
150
+ rack (>= 3)
151
+ webrick (~> 1.8)
152
+ rails (7.1.3.4)
153
+ actioncable (= 7.1.3.4)
154
+ actionmailbox (= 7.1.3.4)
155
+ actionmailer (= 7.1.3.4)
156
+ actionpack (= 7.1.3.4)
157
+ actiontext (= 7.1.3.4)
158
+ actionview (= 7.1.3.4)
159
+ activejob (= 7.1.3.4)
160
+ activemodel (= 7.1.3.4)
161
+ activerecord (= 7.1.3.4)
162
+ activestorage (= 7.1.3.4)
163
+ activesupport (= 7.1.3.4)
164
+ bundler (>= 1.15.0)
165
+ railties (= 7.1.3.4)
166
+ rails-dom-testing (2.2.0)
167
+ activesupport (>= 5.0.0)
168
+ minitest
169
+ nokogiri (>= 1.6)
170
+ rails-html-sanitizer (1.6.0)
171
+ loofah (~> 2.21)
172
+ nokogiri (~> 1.14)
173
+ railties (7.1.3.4)
174
+ actionpack (= 7.1.3.4)
175
+ activesupport (= 7.1.3.4)
176
+ irb
177
+ rackup (>= 1.0.0)
178
+ rake (>= 12.2)
179
+ thor (~> 1.0, >= 1.2.2)
180
+ zeitwerk (~> 2.6)
181
+ rainbow (3.1.1)
182
+ rake (13.2.1)
183
+ rdoc (6.7.0)
184
+ psych (>= 4.0.0)
185
+ regexp_parser (2.9.2)
186
+ reline (0.5.9)
187
+ io-console (~> 0.5)
188
+ rexml (3.3.4)
189
+ strscan
190
+ rspec (3.13.0)
191
+ rspec-core (~> 3.13.0)
192
+ rspec-expectations (~> 3.13.0)
193
+ rspec-mocks (~> 3.13.0)
194
+ rspec-core (3.13.0)
195
+ rspec-support (~> 3.13.0)
196
+ rspec-expectations (3.13.1)
197
+ diff-lcs (>= 1.2.0, < 2.0)
198
+ rspec-support (~> 3.13.0)
199
+ rspec-mocks (3.13.1)
200
+ diff-lcs (>= 1.2.0, < 2.0)
201
+ rspec-support (~> 3.13.0)
202
+ rspec-support (3.13.1)
203
+ rubocop (1.65.1)
204
+ json (~> 2.3)
205
+ language_server-protocol (>= 3.17.0)
206
+ parallel (~> 1.10)
207
+ parser (>= 3.3.0.2)
208
+ rainbow (>= 2.2.2, < 4.0)
209
+ regexp_parser (>= 2.4, < 3.0)
210
+ rexml (>= 3.2.5, < 4.0)
211
+ rubocop-ast (>= 1.31.1, < 2.0)
212
+ ruby-progressbar (~> 1.7)
213
+ unicode-display_width (>= 2.4.0, < 3.0)
214
+ rubocop-ast (1.31.3)
215
+ parser (>= 3.3.1.0)
216
+ rubocop-minitest (0.35.1)
217
+ rubocop (>= 1.61, < 2.0)
218
+ rubocop-ast (>= 1.31.1, < 2.0)
219
+ rubocop-performance (1.21.1)
220
+ rubocop (>= 1.48.1, < 2.0)
221
+ rubocop-ast (>= 1.31.1, < 2.0)
222
+ rubocop-rails (2.25.1)
223
+ activesupport (>= 4.2.0)
224
+ rack (>= 1.1)
225
+ rubocop (>= 1.33.0, < 2.0)
226
+ rubocop-ast (>= 1.31.1, < 2.0)
227
+ rubocop-rails-omakase (1.0.0)
228
+ rubocop
229
+ rubocop-minitest
230
+ rubocop-performance
231
+ rubocop-rails
232
+ ruby-progressbar (1.13.0)
233
+ slim (5.2.1)
234
+ temple (~> 0.10.0)
235
+ tilt (>= 2.1.0)
236
+ stringio (3.1.1)
237
+ strscan (3.1.0)
238
+ temple (0.10.3)
239
+ thor (1.3.1)
240
+ tilt (2.4.0)
241
+ timeout (0.4.1)
242
+ tzinfo (2.0.6)
243
+ concurrent-ruby (~> 1.0)
244
+ unicode-display_width (2.5.0)
245
+ webrick (1.8.1)
246
+ websocket-driver (0.7.6)
247
+ websocket-extensions (>= 0.1.0)
248
+ websocket-extensions (0.1.5)
249
+ zeitwerk (2.6.17)
250
+
251
+ PLATFORMS
252
+ ruby
253
+ x86_64-darwin-23
254
+
255
+ DEPENDENCIES
256
+ bundler (~> 2.5)
257
+ debug (~> 1.6)
258
+ rails (~> 7.0)
259
+ rails-storybook!
260
+ rake (~> 13.2)
261
+ rspec (~> 3.13)
262
+ rubocop (~> 1.6)
263
+ rubocop-rails-omakase (~> 1.0)
264
+
265
+ BUNDLED WITH
266
+ 2.5.16
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Nicholas Barone
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # Rails::Storybook
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/rails-storybook.svg)](https://badge.fury.io/rb/rails-storybook)
4
+ ![ci](https://github.com/rangerscience/rails-storybook/actions/workflows/ci.yml/badge.svg)
5
+ [![code-climate](https://codeclimate.com/github/rangerscience/rails-storybook.svg)](https://codeclimate.com/github/rangerscience/rails-storybook)
6
+
7
+ Storybook is a very cool Javascript ecosystem tool, aiding in the development of component-based UIs. It takes a little bit of doing to make it play nicely with Rails. And, a main benefit of using Storybook is that it lets you use Chromatic - which means no more need for *a lot* of your UI tests!
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'rails-storybook'
15
+ ```
16
+
17
+ Then:
18
+ ```bash
19
+ rails g storybook:install
20
+ ```
21
+
22
+ Then, optionally:
23
+ ```bash
24
+ rails g storybook:example
25
+ ```
26
+
27
+ Restart your processes (stop and restart `./bin/dev`) and viola! Opens up a Storybook connected to your Rails server, and if you've also generated the example, will have a simple View Component showing up in Storybook.
28
+
29
+ ## Usage
30
+
31
+ Today, write a JSON to describe your View Component's "story":
32
+ ```
33
+ {
34
+ "title": "ExampleComponent",
35
+ "stories": [
36
+ {
37
+ "name": "default",
38
+ "parameters": {
39
+ "server": { "id": "example_component/default" }
40
+ }
41
+ }
42
+ ]
43
+ }
44
+ ```
45
+
46
+ Tomorrow(tm), run a rake task to generate those stories for you.
47
+
48
+ ## Development
49
+
50
+ Inspired by [gem view_component-storybook](https://github.com/jonspalmer/view_component-storybook), but, I want to accomplish things in a different way (using the existing view component previews), to aim higher (handling view components, partials, *and* React components), and to aim specifically at integration with Chromatic.
51
+
52
+ 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.
53
+
54
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
55
+
56
+ ## Contributing
57
+
58
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rangerscience/rails-storybook. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
59
+
60
+ ## License
61
+
62
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
63
+
64
+ ## Code of Conduct
65
+
66
+ Everyone interacting in the Rails::Storybook project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rangerscience/rails-storybook/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rails/storybook"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,62 @@
1
+ require "rails/generators"
2
+
3
+ class Storybook::ExampleGenerator < Rails::Generators::Base
4
+ def install_view_components
5
+ insert_into_file "Gemfile", "gem 'view_component'"
6
+ system "bundle install"
7
+ end
8
+
9
+ def create_example_component
10
+ create_file "app/components/example_component.rb", <<~RUBY
11
+ # frozen_string_literal: true
12
+
13
+ class ExampleComponent < ViewComponent::Base
14
+ slim_template <<~SLIM
15
+ span
16
+ = @title
17
+ SLIM
18
+
19
+ def initialize(title:)
20
+ @title = title
21
+ end
22
+ end
23
+ RUBY
24
+ end
25
+
26
+ def create_example_component_preview
27
+ create_file "test/components/previews/example_component_preview.rb", <<~RUBY
28
+ # frozen_string_literal: true
29
+
30
+ class ExampleComponentPreview < ViewComponent::Preview
31
+ layout "storybook"
32
+ def default
33
+ render(ExampleComponent.new(title: "title"))
34
+ end
35
+
36
+ def with_content_block
37
+ render(ExampleComponent.new(title: "This component accepts a block of content")) do
38
+ tag.div do
39
+ content_tag(:span, "Hello")
40
+ end
41
+ end
42
+ end
43
+ end
44
+ RUBY
45
+ end
46
+
47
+ def create_example_story
48
+ create_file "stories/example_component.stories.json", <<~JSON
49
+ {
50
+ "title": "ExampleComponent",
51
+ "stories": [
52
+ {
53
+ "name": "default",
54
+ "parameters": {
55
+ "server": { "id": "example_component/default" }
56
+ }
57
+ }
58
+ ]
59
+ }
60
+ JSON
61
+ end
62
+ end
@@ -0,0 +1,57 @@
1
+ require "rails/generators"
2
+
3
+ class Storybook::InstallGenerator < Rails::Generators::Base
4
+ def install_storybook
5
+ system "npx storybook@latest init --yes --dev --no-dev --builder webpack5"
6
+ system "yarn add @storybook/server --dev"
7
+ system "yarn add @storybook/server-webpack5 --dev"
8
+ system "yarn install"
9
+ insert_into_file "Procfile.dev", "storybook: yarn storybook -p 6006"
10
+ end
11
+
12
+ def install_rack_cors
13
+ insert_into_file "Gemfile", " gem 'rack-cors'\n", after: "group :development do\n"
14
+ system "bundle install"
15
+ create_file "config/initializers/cors.rb", <<~RUBY
16
+ Rails.application.config.middleware.insert_before 0, Rack::Cors do
17
+ allow do
18
+ origins '*'
19
+ resource '*', headers: :any, methods: [:get, :post, :patch, :put]
20
+ end
21
+ end
22
+ RUBY
23
+ end
24
+
25
+ def create_storybook_layout_slim
26
+ create_file "app/views/layouts/storybook.html.slim", <<~SLIM
27
+ doctype html
28
+ html lang='en'
29
+ head
30
+ title Trainyard
31
+ meta charset="UTF-8"
32
+ meta[name="viewport" content="width=device-width,initial-scale=1"]
33
+ = csrf_meta_tags
34
+ = csp_meta_tag
35
+ = stylesheet_link_tag "tailwind", "inter-font", "data-turbo-track": "reload"
36
+ = stylesheet_link_tag "application"
37
+ = javascript_pack_tag "application"
38
+ body
39
+ div
40
+ main.ml-64.p-8
41
+ == yield
42
+ SLIM
43
+ end
44
+
45
+ def update_storybook
46
+ # Main.js
47
+ insert_into_file ".storybook/main.js", "\n \"@storybook/server\",", after: "addons: ["
48
+ gsub_file ".storybook/main.js", "*.stories.@(js|jsx|mjs|ts|tsx)", "*.stories.@(js|jsx|mjs|ts|tsx|json)"
49
+ gsub_file ".storybook/main.js", "@storybook/react-webpack5", "@storybook/server-webpack5"
50
+
51
+ # Preview.js
52
+ base_url = "http://localhost:3000/rails/view_components"
53
+ insert_into_file ".storybook/preview.js", "\n server: { url: \"#{base_url}\", },", after: "parameters: {"
54
+
55
+ # insert_into_file ".storybook/main.js", "@storybook/addon-controls", after: "addons: ["
56
+ end
57
+ end
@@ -0,0 +1,4 @@
1
+
2
+ module Storybook
3
+ VERSION = "0.1.0"
4
+ end
data/lib/storybook.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "storybook/version"
2
+
3
+ module Storybook
4
+ class Error < StandardError; end
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,37 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "storybook/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rails-storybook"
8
+ spec.version = Storybook::VERSION
9
+ spec.authors = [ "Nicholas Barone" ]
10
+ spec.email = [ "nicktbarone@gmail.com" ]
11
+
12
+ spec.summary = %q(Gem to allow Storybook to work with Rails)
13
+ spec.description = %q(...specifically for use with Chromatic)
14
+ spec.homepage = "https://github.com/rangerscience/rails-storybook"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = [ "lib" ]
25
+
26
+
27
+ spec.add_dependency "rails", "~> 7.0"
28
+ spec.add_dependency "slim", "~> 5.2"
29
+ spec.add_development_dependency "rails", "~> 7.0"
30
+
31
+ spec.add_development_dependency "bundler", "~> 2.5"
32
+ spec.add_development_dependency "rake", "~> 13.2"
33
+ spec.add_development_dependency "rspec", "~> 3.13"
34
+ spec.add_development_dependency "debug", "~> 1.6"
35
+ spec.add_development_dependency "rubocop", "~> 1.6"
36
+ spec.add_development_dependency "rubocop-rails-omakase", "~> 1.0"
37
+ end
metadata ADDED
@@ -0,0 +1,188 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-storybook
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nicholas Barone
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-08-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '7.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '7.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: slim
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '7.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '7.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '13.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '13.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.13'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.13'
97
+ - !ruby/object:Gem::Dependency
98
+ name: debug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.6'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.6'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.6'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.6'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-rails-omakase
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.0'
139
+ description: "...specifically for use with Chromatic"
140
+ email:
141
+ - nicktbarone@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".github/workflows/ci.yml"
147
+ - ".gitignore"
148
+ - ".rspec"
149
+ - ".rubocop.yml"
150
+ - ".ruby-version"
151
+ - ".travis.yml"
152
+ - CODE_OF_CONDUCT.md
153
+ - Gemfile
154
+ - Gemfile.lock
155
+ - LICENSE.txt
156
+ - README.md
157
+ - Rakefile
158
+ - bin/console
159
+ - bin/setup
160
+ - lib/generators/storybook/example_generator.rb
161
+ - lib/generators/storybook/install_generator.rb
162
+ - lib/storybook.rb
163
+ - lib/storybook/version.rb
164
+ - rails-storybook.gemspec
165
+ homepage: https://github.com/rangerscience/rails-storybook
166
+ licenses:
167
+ - MIT
168
+ metadata: {}
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ requirements: []
184
+ rubygems_version: 3.5.16
185
+ signing_key:
186
+ specification_version: 4
187
+ summary: Gem to allow Storybook to work with Rails
188
+ test_files: []