rails-previews 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: db7a6eb488743fcae71fdc262d2850af0857667f7c79be35cf6d1e0b76bb1fa9
4
+ data.tar.gz: f564ba3310a7ebcb499bbf2d4a525482a15cf0075a6fef5b269e39575eb50ba3
5
+ SHA512:
6
+ metadata.gz: 459d64b879b2687b93d91fcae395a49e5253b53a771d122606b304e2b0785e43f37c19f0efeebc6d7fcc71ddb04decc5182eefab9a14a8349a5e3d8755afa06f
7
+ data.tar.gz: beb3c8e1653e631c10603b234548fa1b8041940c638ec9c74992b04671bfd0c64ef8e36017f788647d5573cf1b908371dfd593d63d95e942c3a537399fecfdb3
@@ -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,21 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /log/*.log
7
+ /pkg/
8
+ /tmp/
9
+ /spec/reports/
10
+
11
+ # WIP: generated by the Rails engine generator, but maybe don't need them all
12
+ /test/dummy/db/*.sqlite3
13
+ /test/dummy/db/*.sqlite3-*
14
+ /test/dummy/log/*.log
15
+ /test/dummy/storage/
16
+ /test/dummy/tmp/
17
+
18
+ # rspec failure tracking
19
+ .rspec_status
20
+
21
+ *.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-previews.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,268 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rails-previews (0.1.0)
5
+ slim (~> 5.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (6.1.4.7)
11
+ actionpack (= 6.1.4.7)
12
+ activesupport (= 6.1.4.7)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (>= 0.6.1)
15
+ actionmailbox (6.1.4.7)
16
+ actionpack (= 6.1.4.7)
17
+ activejob (= 6.1.4.7)
18
+ activerecord (= 6.1.4.7)
19
+ activestorage (= 6.1.4.7)
20
+ activesupport (= 6.1.4.7)
21
+ mail (>= 2.7.1)
22
+ actionmailer (6.1.4.7)
23
+ actionpack (= 6.1.4.7)
24
+ actionview (= 6.1.4.7)
25
+ activejob (= 6.1.4.7)
26
+ activesupport (= 6.1.4.7)
27
+ mail (~> 2.5, >= 2.5.4)
28
+ rails-dom-testing (~> 2.0)
29
+ actionpack (6.1.4.7)
30
+ actionview (= 6.1.4.7)
31
+ activesupport (= 6.1.4.7)
32
+ rack (~> 2.0, >= 2.0.9)
33
+ rack-test (>= 0.6.3)
34
+ rails-dom-testing (~> 2.0)
35
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
36
+ actiontext (6.1.4.7)
37
+ actionpack (= 6.1.4.7)
38
+ activerecord (= 6.1.4.7)
39
+ activestorage (= 6.1.4.7)
40
+ activesupport (= 6.1.4.7)
41
+ nokogiri (>= 1.8.5)
42
+ actionview (6.1.4.7)
43
+ activesupport (= 6.1.4.7)
44
+ builder (~> 3.1)
45
+ erubi (~> 1.4)
46
+ rails-dom-testing (~> 2.0)
47
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
48
+ activejob (6.1.4.7)
49
+ activesupport (= 6.1.4.7)
50
+ globalid (>= 0.3.6)
51
+ activemodel (6.1.4.7)
52
+ activesupport (= 6.1.4.7)
53
+ activerecord (6.1.4.7)
54
+ activemodel (= 6.1.4.7)
55
+ activesupport (= 6.1.4.7)
56
+ activestorage (6.1.4.7)
57
+ actionpack (= 6.1.4.7)
58
+ activejob (= 6.1.4.7)
59
+ activerecord (= 6.1.4.7)
60
+ activesupport (= 6.1.4.7)
61
+ marcel (~> 1.0.0)
62
+ mini_mime (>= 1.1.0)
63
+ activesupport (6.1.4.7)
64
+ concurrent-ruby (~> 1.0, >= 1.0.2)
65
+ i18n (>= 1.6, < 2)
66
+ minitest (>= 5.1)
67
+ tzinfo (~> 2.0)
68
+ zeitwerk (~> 2.3)
69
+ addressable (2.8.7)
70
+ public_suffix (>= 2.0.2, < 7.0)
71
+ ast (2.4.2)
72
+ builder (3.3.0)
73
+ concurrent-ruby (1.3.4)
74
+ connection_pool (2.4.1)
75
+ crass (1.0.6)
76
+ date (3.3.4)
77
+ debug (1.9.2)
78
+ irb (~> 1.10)
79
+ reline (>= 0.3.8)
80
+ diff-lcs (1.5.1)
81
+ erubi (1.13.0)
82
+ execjs (2.9.1)
83
+ globalid (1.2.1)
84
+ activesupport (>= 6.1)
85
+ i18n (1.14.5)
86
+ concurrent-ruby (~> 1.0)
87
+ io-console (0.7.2)
88
+ irb (1.14.0)
89
+ rdoc (>= 4.0.0)
90
+ reline (>= 0.4.2)
91
+ json (2.7.2)
92
+ language_server-protocol (3.17.0.3)
93
+ loofah (2.22.0)
94
+ crass (~> 1.0.2)
95
+ nokogiri (>= 1.12.0)
96
+ mail (2.8.1)
97
+ mini_mime (>= 0.1.1)
98
+ net-imap
99
+ net-pop
100
+ net-smtp
101
+ marcel (1.0.4)
102
+ method_source (1.1.0)
103
+ mini_mime (1.1.5)
104
+ minitest (5.25.1)
105
+ net-imap (0.4.16)
106
+ date
107
+ net-protocol
108
+ net-pop (0.1.2)
109
+ net-protocol
110
+ net-protocol (0.2.2)
111
+ timeout
112
+ net-smtp (0.5.0)
113
+ net-protocol
114
+ nio4r (2.7.3)
115
+ nokogiri (1.16.7-aarch64-linux)
116
+ racc (~> 1.4)
117
+ nokogiri (1.16.7-arm-linux)
118
+ racc (~> 1.4)
119
+ nokogiri (1.16.7-arm64-darwin)
120
+ racc (~> 1.4)
121
+ nokogiri (1.16.7-x86-linux)
122
+ racc (~> 1.4)
123
+ nokogiri (1.16.7-x86_64-darwin)
124
+ racc (~> 1.4)
125
+ nokogiri (1.16.7-x86_64-linux)
126
+ racc (~> 1.4)
127
+ parallel (1.26.3)
128
+ parser (3.3.5.0)
129
+ ast (~> 2.4.1)
130
+ racc
131
+ psych (5.1.2)
132
+ stringio
133
+ public_suffix (6.0.1)
134
+ racc (1.8.1)
135
+ rack (2.2.9)
136
+ rack-test (2.1.0)
137
+ rack (>= 1.3)
138
+ rails (6.1.4.7)
139
+ actioncable (= 6.1.4.7)
140
+ actionmailbox (= 6.1.4.7)
141
+ actionmailer (= 6.1.4.7)
142
+ actionpack (= 6.1.4.7)
143
+ actiontext (= 6.1.4.7)
144
+ actionview (= 6.1.4.7)
145
+ activejob (= 6.1.4.7)
146
+ activemodel (= 6.1.4.7)
147
+ activerecord (= 6.1.4.7)
148
+ activestorage (= 6.1.4.7)
149
+ activesupport (= 6.1.4.7)
150
+ bundler (>= 1.15.0)
151
+ railties (= 6.1.4.7)
152
+ sprockets-rails (>= 2.0.0)
153
+ rails-dom-testing (2.2.0)
154
+ activesupport (>= 5.0.0)
155
+ minitest
156
+ nokogiri (>= 1.6)
157
+ rails-html-sanitizer (1.6.0)
158
+ loofah (~> 2.21)
159
+ nokogiri (~> 1.14)
160
+ railties (6.1.4.7)
161
+ actionpack (= 6.1.4.7)
162
+ activesupport (= 6.1.4.7)
163
+ method_source
164
+ rake (>= 0.13)
165
+ thor (~> 1.0)
166
+ rainbow (3.1.1)
167
+ rake (10.5.0)
168
+ rdoc (6.7.0)
169
+ psych (>= 4.0.0)
170
+ react_on_rails (14.0.5)
171
+ addressable
172
+ connection_pool
173
+ execjs (~> 2.5)
174
+ rails (>= 5.2)
175
+ rainbow (~> 3.0)
176
+ regexp_parser (2.9.2)
177
+ reline (0.5.10)
178
+ io-console (~> 0.5)
179
+ rspec (3.13.0)
180
+ rspec-core (~> 3.13.0)
181
+ rspec-expectations (~> 3.13.0)
182
+ rspec-mocks (~> 3.13.0)
183
+ rspec-core (3.13.1)
184
+ rspec-support (~> 3.13.0)
185
+ rspec-expectations (3.13.3)
186
+ diff-lcs (>= 1.2.0, < 2.0)
187
+ rspec-support (~> 3.13.0)
188
+ rspec-mocks (3.13.1)
189
+ diff-lcs (>= 1.2.0, < 2.0)
190
+ rspec-support (~> 3.13.0)
191
+ rspec-support (3.13.1)
192
+ rubocop (1.66.1)
193
+ json (~> 2.3)
194
+ language_server-protocol (>= 3.17.0)
195
+ parallel (~> 1.10)
196
+ parser (>= 3.3.0.2)
197
+ rainbow (>= 2.2.2, < 4.0)
198
+ regexp_parser (>= 2.4, < 3.0)
199
+ rubocop-ast (>= 1.32.2, < 2.0)
200
+ ruby-progressbar (~> 1.7)
201
+ unicode-display_width (>= 2.4.0, < 3.0)
202
+ rubocop-ast (1.32.3)
203
+ parser (>= 3.3.1.0)
204
+ rubocop-minitest (0.36.0)
205
+ rubocop (>= 1.61, < 2.0)
206
+ rubocop-ast (>= 1.31.1, < 2.0)
207
+ rubocop-performance (1.21.1)
208
+ rubocop (>= 1.48.1, < 2.0)
209
+ rubocop-ast (>= 1.31.1, < 2.0)
210
+ rubocop-rails (2.26.1)
211
+ activesupport (>= 4.2.0)
212
+ rack (>= 1.1)
213
+ rubocop (>= 1.52.0, < 2.0)
214
+ rubocop-ast (>= 1.31.1, < 2.0)
215
+ rubocop-rails-omakase (1.0.0)
216
+ rubocop
217
+ rubocop-minitest
218
+ rubocop-performance
219
+ rubocop-rails
220
+ ruby-progressbar (1.13.0)
221
+ slim (5.2.1)
222
+ temple (~> 0.10.0)
223
+ tilt (>= 2.1.0)
224
+ sprockets (4.2.1)
225
+ concurrent-ruby (~> 1.0)
226
+ rack (>= 2.2.4, < 4)
227
+ sprockets-rails (3.5.2)
228
+ actionpack (>= 6.1)
229
+ activesupport (>= 6.1)
230
+ sprockets (>= 3.0.0)
231
+ stringio (3.1.1)
232
+ temple (0.10.3)
233
+ thor (1.3.2)
234
+ tilt (2.4.0)
235
+ timeout (0.4.1)
236
+ tzinfo (2.0.6)
237
+ concurrent-ruby (~> 1.0)
238
+ unicode-display_width (2.5.0)
239
+ view_component (3.14.0)
240
+ activesupport (>= 5.2.0, < 8.0)
241
+ concurrent-ruby (~> 1.0)
242
+ method_source (~> 1.0)
243
+ websocket-driver (0.7.6)
244
+ websocket-extensions (>= 0.1.0)
245
+ websocket-extensions (0.1.5)
246
+ zeitwerk (2.6.18)
247
+
248
+ PLATFORMS
249
+ aarch64-linux
250
+ arm-linux
251
+ arm64-darwin
252
+ x86-linux
253
+ x86_64-darwin
254
+ x86_64-linux
255
+
256
+ DEPENDENCIES
257
+ bundler (~> 2.5)
258
+ debug (~> 1.6)
259
+ rails-previews!
260
+ rake (~> 10.0)
261
+ react_on_rails (~> 14.0)
262
+ rspec (~> 3.0)
263
+ rubocop (~> 1.6)
264
+ rubocop-rails-omakase (~> 1.0)
265
+ view_component (~> 3.14)
266
+
267
+ BUNDLED WITH
268
+ 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,115 @@
1
+ # Rails::Previews
2
+
3
+ A Rails engine to allow previews of many different kinds of Rails view pieces, specifically:
4
+
5
+ - Partials
6
+ - View Components
7
+ - React-on-Rails React Components
8
+
9
+ Cribbed from the internals of the preview engine for View Components, and built to work with the [rails-storybook](https://github.com/rangerscience/rails-storybook) gem.
10
+
11
+ This gem is *extremely* barebones so far!
12
+
13
+ ## Installation
14
+
15
+ ```ruby
16
+ gem 'rails-previews'
17
+ ```
18
+
19
+ Then mount the engine where you want it:
20
+ ```ruby
21
+ mount Rails::Previews::Engine => "/previews"
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ Previews should be defined in `spec/preview/*.rb` files (and inherit from the helper class), inside a `Previews` module. Each class function becomes an example, and under the hood, it's just passing the hash directly into the bog-standard Rail's controller `render` function, so basic usage is simple:
27
+
28
+ ```ruby
29
+ module Previews
30
+ class Example < Rails::Previews::Preview
31
+ def example_1
32
+ { plain: "Hello, World!" }
33
+ end
34
+
35
+ def example_2
36
+ { partial: 'your_partial_name', locals: { foo: "bar" } }
37
+ end
38
+ end
39
+ end
40
+ ```
41
+
42
+ To cut down on boiler plate for partials, there's a utility function:
43
+
44
+ ```ruby
45
+ module Previews
46
+ class Example < Rails::Previews::Preview
47
+ def example_2
48
+ render_partial 'your_partial_name', { foo: "bar" }
49
+ end
50
+ end
51
+ end
52
+ ```
53
+
54
+ If you're using Github's View Components:
55
+
56
+ ```ruby
57
+ module Previews
58
+ class Example < Rails::Previews::Preview
59
+ def example_3
60
+ MyViewComponent.new(name: "Foo")
61
+ end
62
+ end
63
+ end
64
+ ```
65
+
66
+ Lastly, if you're using Shakapacker's React On Rails, this gem provides a handy partial:
67
+ ```ruby
68
+ module Previews
69
+ class Example < Rails::Previews::Preview
70
+ def example_4
71
+ {
72
+ partial: "previews/react_on_rails",
73
+ locals: {
74
+ pack: "application", # This being the name of your React component pack/bundle/thing
75
+ component_name: "MyReactComponent",
76
+ props: {foo: "bar"}
77
+ }
78
+ }
79
+ end
80
+ end
81
+ end
82
+ ```
83
+
84
+ Or, with a helper to eliminate boilerplate:
85
+ ```ruby
86
+ module Previews
87
+ class Example < Rails::Previews::Preview
88
+ def example_4
89
+ render_react_on_rails "MyReactComponent", foo: "bar"
90
+ end
91
+ end
92
+ end
93
+ ```
94
+ (FYI: `pack` is an optional keyword argument, defaulting to `"application"`)
95
+
96
+ Visit `http://localhost:3000/previews/` (or whever you mounted the engine) to see your examples!
97
+
98
+
99
+ ## Development
100
+
101
+ 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.
102
+
103
+ 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).
104
+
105
+ ## Contributing
106
+
107
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rangerscience/rails-previews. 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.
108
+
109
+ ## License
110
+
111
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
112
+
113
+ ## Code of Conduct
114
+
115
+ Everyone interacting in the Rails::Previews project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rangerscience/rails-previews/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
@@ -0,0 +1 @@
1
+ //= link_directory ../stylesheets/rails/previews .css
File without changes
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
File without changes
@@ -0,0 +1,27 @@
1
+
2
+ require "rails/application_controller"
3
+
4
+ class Rails::Previews::PreviewsController < ApplicationController
5
+ layout false
6
+
7
+ def index
8
+ @previews = Rails::Previews::Preview.all
9
+ render "previews/index", layout: false
10
+ end
11
+
12
+ def show
13
+ Rails::Previews::Preview.all # TODO: Autoloading instead (ideally)
14
+
15
+ klazz_name = Pathname.new(params[:path]).parent.to_s
16
+ klazz = "Previews::#{klazz_name.camelize}".constantize
17
+
18
+ example_name = Pathname.new(params[:path]).basename.to_s
19
+ example = klazz.new.send(example_name)
20
+
21
+ if example.is_a? Hash
22
+ render **example
23
+ else
24
+ render example
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,6 @@
1
+ module Rails
2
+ module Previews
3
+ module ApplicationHelper
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Rails
2
+ module Previews
3
+ class ApplicationJob < ActiveJob::Base
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ module Rails
2
+ module Previews
3
+ class ApplicationMailer < ActionMailer::Base
4
+ default from: "from@example.com"
5
+ layout "mailer"
6
+ end
7
+ end
8
+ end
File without changes
@@ -0,0 +1,7 @@
1
+ module Rails
2
+ module Previews
3
+ class ApplicationRecord < ActiveRecord::Base
4
+ self.abstract_class = true
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ = javascript_pack_tag pack
2
+ = react_component component_name, props: props, prerender: true
@@ -0,0 +1,5 @@
1
+ - @previews.each do |preview|
2
+ h3= preview.preview_name.titleize
3
+ ul
4
+ - preview.examples.each do |example|
5
+ li= link_to example, preview_path("#{preview.preview_name}/#{example}")
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rails/previews"
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
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ Rails::Previews::Engine.routes.draw do
2
+ get "/", to: "previews#index" # TODO: `internal: true` ...?
3
+ get "/*path", to: "previews#show", as: :preview # TODO: `internal: true` ...?
4
+ end
@@ -0,0 +1,7 @@
1
+ module Rails
2
+ module Previews
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace Rails::Previews
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,46 @@
1
+ module Rails::Previews
2
+ class Preview
3
+ def render_partial(name, locals = {})
4
+ { partial: name, locals: locals }
5
+ end
6
+
7
+ def render_react_on_rails(name, pack: "application", props: {})
8
+ raise "React on Rails is not installed - did you add the gem?" unless defined?(ReactOnRails)
9
+
10
+ {
11
+ partial: "previews/react_on_rails",
12
+ locals: {
13
+ pack: pack,
14
+ component_name: name,
15
+ props: props
16
+ }
17
+ }
18
+ end
19
+
20
+ class << self
21
+ # TODO: Use regular Rails autoloading
22
+ def all
23
+ load_previews!
24
+ descendants
25
+ end
26
+
27
+ def load_previews!
28
+ Array(preview_paths).each do |preview_path|
29
+ Dir["#{preview_path}/**/*.rb"].sort.each { |file| require_dependency file }
30
+ end
31
+ end
32
+
33
+ def preview_paths
34
+ [ "#{Rails.root}/spec/previews" ]
35
+ end
36
+
37
+ def preview_name
38
+ name.delete_prefix("Previews::").underscore
39
+ end
40
+
41
+ def examples
42
+ public_instance_methods(false).map(&:to_s).sort
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,5 @@
1
+ module Rails
2
+ module Previews
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ require "rails/previews/version"
2
+ require "rails/previews/engine"
3
+ require "rails/previews/preview"
4
+
5
+ module Rails
6
+ module Previews
7
+ class Error < StandardError; end
8
+ # Your code goes here...
9
+ end
10
+ end
@@ -0,0 +1,39 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "rails/previews/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rails-previews"
8
+ spec.version = Rails::Previews::VERSION
9
+ spec.authors = [ "Nicholas Barone" ]
10
+ spec.email = [ "nicktbarone@gmail.com" ]
11
+
12
+ spec.summary = %q(A rails engine for previewing views in many forms)
13
+ spec.description = %q(
14
+ Rails Previews is a Rails engine that allows you to preview the pieces that make up your views,
15
+ specifically: partials, view components, and react-on-rails components
16
+ )
17
+ spec.homepage = "http://github.com/rangerscience/rails-previews"
18
+ spec.license = "MIT"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = [ "lib" ]
28
+
29
+ spec.add_development_dependency "bundler", "~> 2.5"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rspec", "~> 3.0"
32
+ spec.add_development_dependency "debug", "~> 1.6"
33
+ spec.add_development_dependency "rubocop", "~> 1.6"
34
+ spec.add_development_dependency "rubocop-rails-omakase", "~> 1.0"
35
+ spec.add_development_dependency "view_component", "~> 3.14"
36
+ spec.add_development_dependency "react_on_rails", "~> 14.0"
37
+
38
+ spec.add_dependency "slim", "~> 5.2"
39
+ end
metadata ADDED
@@ -0,0 +1,203 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-previews
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-09-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: debug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-rails-omakase
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: view_component
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.14'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.14'
111
+ - !ruby/object:Gem::Dependency
112
+ name: react_on_rails
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '14.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '14.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: slim
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '5.2'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '5.2'
139
+ description: "\n Rails Previews is a Rails engine that allows you to preview the
140
+ pieces that make up your views,\n specifically: partials, view components, and
141
+ react-on-rails components\n "
142
+ email:
143
+ - nicktbarone@gmail.com
144
+ executables: []
145
+ extensions: []
146
+ extra_rdoc_files: []
147
+ files:
148
+ - ".github/workflows/ci.yml"
149
+ - ".gitignore"
150
+ - ".rspec"
151
+ - ".rubocop.yml"
152
+ - ".ruby-version"
153
+ - ".travis.yml"
154
+ - CODE_OF_CONDUCT.md
155
+ - Gemfile
156
+ - Gemfile.lock
157
+ - LICENSE.txt
158
+ - README.md
159
+ - Rakefile
160
+ - app/assets/config/rails_previews_manifest.js
161
+ - app/assets/images/rails/previews/.keep
162
+ - app/assets/stylesheets/rails/previews/application.css
163
+ - app/controllers/concerns/.keep
164
+ - app/controllers/rails/previews/previews_controller.rb
165
+ - app/helpers/rails/previews/application_helper.rb
166
+ - app/jobs/rails/previews/application_job.rb
167
+ - app/mailers/rails/previews/application_mailer.rb
168
+ - app/models/concerns/.keep
169
+ - app/models/rails/previews/application_record.rb
170
+ - app/views/previews/_react_on_rails.html.slim
171
+ - app/views/previews/index.html.slim
172
+ - bin/console
173
+ - bin/setup
174
+ - config/routes.rb
175
+ - lib/rails/previews.rb
176
+ - lib/rails/previews/engine.rb
177
+ - lib/rails/previews/preview.rb
178
+ - lib/rails/previews/version.rb
179
+ - rails-previews.gemspec
180
+ homepage: http://github.com/rangerscience/rails-previews
181
+ licenses:
182
+ - MIT
183
+ metadata: {}
184
+ post_install_message:
185
+ rdoc_options: []
186
+ require_paths:
187
+ - lib
188
+ required_ruby_version: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ version: '0'
193
+ required_rubygems_version: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - ">="
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
198
+ requirements: []
199
+ rubygems_version: 3.5.16
200
+ signing_key:
201
+ specification_version: 4
202
+ summary: A rails engine for previewing views in many forms
203
+ test_files: []