view_component-contrib 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/README.md +17 -6
- data/app/templates/install/index.stimulus.js +1 -1
- data/app/templates/install/postcss-modules.js +1 -1
- data/app/templates/install/template.rb +6 -2
- data/lib/view_component_contrib/preview/abstract.rb +2 -1
- data/lib/view_component_contrib/preview/default_template.rb +11 -7
- data/lib/view_component_contrib/railtie.rb +16 -0
- data/lib/view_component_contrib/translation_helper.rb +5 -5
- data/lib/view_component_contrib/version.rb +1 -1
- data/lib/view_component_contrib.rb +3 -0
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f439e065cd49e9a08753fbcdfda2fbccc3b96f2a72f5d0ccb6896cd3da7b74e
|
4
|
+
data.tar.gz: 211ea998a9033327fdf57cc6094dcea1a269bb9022f539b2f182aece95fd6eb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bfa8779d3a7cc39519f92e9d020c325bf0f4f6d8e845dc3de21d1aef129959ebad4a68249b2229d3e49edf19096c73107fff6ffbccee43b8408db217fedf91e
|
7
|
+
data.tar.gz: 3add0d31953c16acc07a58637be8f6d5acd4dc7505a7466a635924c5afdddd23b0f6ffbded2e03e3c4195df45c04ba54f0822e58d72413b0aacd4a998469511e
|
data/CHANGELOG.md
CHANGED
@@ -2,8 +2,26 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 0.1.2 (2023-01-13)
|
6
|
+
|
7
|
+
- Fix compatibility with sidecar translations. ([@palkan][])
|
8
|
+
|
9
|
+
- Detect Webpack when using Rails 7 + jsbundling-rails. ([@unikitty37][])
|
10
|
+
|
11
|
+
- Skip autoloading of Preview files when viewing previews is disabled. ([@dhnaranjo][])
|
12
|
+
|
13
|
+
- Automatic publish to RailsBytes in CI. ([@fargelus][])
|
14
|
+
|
15
|
+
## 0.1.1 (2022-03-14)
|
16
|
+
|
17
|
+
- Fix adding gem's previews to the app's path. ([@palkan][])
|
18
|
+
|
19
|
+
- Fix configurable default template.
|
20
|
+
|
5
21
|
## 0.1.0 (2021-04-07)
|
6
22
|
|
7
23
|
- Initial release.
|
8
24
|
|
9
25
|
[@palkan]: https://github.com/palkan
|
26
|
+
[@fargelus]: https://github.com/fargelus
|
27
|
+
[@dhnaranjo]: https://github.com/dhnaranjo
|
data/README.md
CHANGED
@@ -98,12 +98,25 @@ We provide a `ViewComponentContrib::Preview` class, which helps to reduce the bo
|
|
98
98
|
|
99
99
|
The default template shipped with the gem is as follows:
|
100
100
|
|
101
|
-
```
|
101
|
+
```erb
|
102
102
|
<div class="<%= container_class %>">
|
103
|
-
|
103
|
+
<%- if component -%>
|
104
|
+
<%= render component %>
|
105
|
+
<%- else -%>
|
106
|
+
Failed to infer a component from the preview: <%= error %>
|
107
|
+
<%- end -%>
|
104
108
|
</div>
|
105
109
|
```
|
106
110
|
|
111
|
+
To define your own default template:
|
112
|
+
```ruby
|
113
|
+
class ApplicationViewComponentPreview < ViewComponentContrib::Preview::Base
|
114
|
+
# ...
|
115
|
+
self.default_preview_template = "path/to/your/template.html.{erb,haml,slim}"
|
116
|
+
# ...
|
117
|
+
end
|
118
|
+
```
|
119
|
+
|
107
120
|
Let's assume that you have the following `ApplicationViewComponentPreview`:
|
108
121
|
|
109
122
|
```ruby
|
@@ -154,9 +167,7 @@ class Banner::Preview < ApplicationViewComponentPreview
|
|
154
167
|
end
|
155
168
|
```
|
156
169
|
|
157
|
-
If you need more control over your template, you can add a custom `preview.html.erb`
|
158
|
-
**NOTE:** We assume that all examples uses the same `preview.html`. If it's not the case,
|
159
|
-
you can use the original `#render_with_template` method.
|
170
|
+
If you need more control over your template, you can add a custom `preview.html.*` template (which will be used for all examples in this preview), or even create an example-specific `previews/example.html.*` (e.g. `previews/mobile.html.erb`).
|
160
171
|
|
161
172
|
## Organizing assets (JS, CSS)
|
162
173
|
|
@@ -228,7 +239,7 @@ context.keys().forEach((path) => {
|
|
228
239
|
// nav/user_info/index.js -> nav--user-info
|
229
240
|
const identifier = path.replace(/^\.\//, '')
|
230
241
|
.replace(/\/index\.js$/, '')
|
231
|
-
.replace(
|
242
|
+
.replace(/\//g, '--');
|
232
243
|
|
233
244
|
application.register(identifier, mod.Controller);
|
234
245
|
});
|
@@ -14,7 +14,7 @@ context.keys().forEach((path) => {
|
|
14
14
|
// nav/user_info/index.js -> nav--user-info
|
15
15
|
const identifier = path.replace(/^\\.\\//, '')
|
16
16
|
.replace(/\\/index\\.js$/, '')
|
17
|
-
.replace(
|
17
|
+
.replace(/\\//g, '--');
|
18
18
|
|
19
19
|
application.register(identifier, mod.Controller);
|
20
20
|
});
|
@@ -4,7 +4,7 @@
|
|
4
4
|
if (!matches) return name;
|
5
5
|
|
6
6
|
// identifier here is the same identifier we used for Stimulus controller (see above)
|
7
|
-
const identifier = matches[1].replace(
|
7
|
+
const identifier = matches[1].replace(/\\//g, "--");
|
8
8
|
|
9
9
|
// We also add the `c-` prefix to all components classes
|
10
10
|
return `c-${identifier}-${name}`;
|
@@ -3,7 +3,7 @@ say "👋 Welcome to interactive ViewComponent installer and configurator. " \
|
|
3
3
|
|
4
4
|
run "bundle add view_component view_component-contrib --skip-install"
|
5
5
|
|
6
|
-
inject_into_file "config/application.rb", "
|
6
|
+
inject_into_file "config/application.rb", "\nrequire \"view_component/engine\"\n", before: "\nBundler.require(*Rails.groups)"
|
7
7
|
|
8
8
|
say_status :info, "✅ ViewComponent gems added"
|
9
9
|
|
@@ -65,7 +65,7 @@ end
|
|
65
65
|
|
66
66
|
say_status :info, "✅ RSpec configured"
|
67
67
|
|
68
|
-
USE_WEBPACK = File.directory?("config/webpack")
|
68
|
+
USE_WEBPACK = File.directory?("config/webpack") || File.file?("webpack.config.js")
|
69
69
|
|
70
70
|
if USE_WEBPACK
|
71
71
|
USE_STIMULUS = yes? "Do you use StimulusJS?"
|
@@ -85,6 +85,8 @@ if USE_WEBPACK
|
|
85
85
|
say_status :info, "✅ Added index.js to load components JS/CSS"
|
86
86
|
say "⚠️ Don't forget to import component JS/CSS (#{ROOT_PATH}/index.js) from your application.js entrypoint"
|
87
87
|
|
88
|
+
say "⚠️ Don't forget to add #{ROOT_PATH} to `additional_paths` in your `webpacker.yml` (unless your `source_path` already includes it)"
|
89
|
+
|
88
90
|
USE_POSTCSS_MODULES = yes? "Would you like to use postcss-modules to isolate component styles?"
|
89
91
|
|
90
92
|
if USE_POSTCSS_MODULES
|
@@ -122,6 +124,8 @@ if USE_WEBPACK
|
|
122
124
|
|
123
125
|
say_status :info, "✅ postcss-modules configured"
|
124
126
|
end
|
127
|
+
else
|
128
|
+
say "⚠️ See the discussion on how to configure non-Wepback JS/CSS installations: https://github.com/palkan/view_component-contrib/discussions/14"
|
125
129
|
end
|
126
130
|
|
127
131
|
<%= embed("./generator.rb") %>
|
@@ -23,20 +23,24 @@ module ViewComponentContrib
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
def preview_example_template_path(
|
26
|
+
def preview_example_template_path(example)
|
27
27
|
super
|
28
28
|
rescue ViewComponent::PreviewTemplateError
|
29
|
-
|
29
|
+
has_example_preview = preview_paths.find do |path|
|
30
|
+
Dir.glob(File.join(path, preview_name, "previews", "#{example}.html.*")).any?
|
31
|
+
end
|
32
|
+
|
33
|
+
return File.join(preview_name, "previews", example) if has_example_preview
|
34
|
+
|
35
|
+
has_root_preview = preview_paths.find do |path|
|
30
36
|
Dir.glob(File.join(path, preview_name, "preview.html.*")).any?
|
31
37
|
end
|
32
38
|
|
33
|
-
|
39
|
+
return File.join(preview_name, "preview") if has_root_preview
|
40
|
+
|
41
|
+
default_preview_template
|
34
42
|
end
|
35
43
|
end
|
36
44
|
end
|
37
45
|
end
|
38
46
|
end
|
39
|
-
|
40
|
-
ActiveSupport.on_load(:view_component) do
|
41
|
-
ViewComponent::Base.preview_paths << File.join(ViewComponentContrib::APP_PATH, "views")
|
42
|
-
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ViewComponentContrib
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
config.view_component.preview_paths << File.join(ViewComponentContrib::APP_PATH, "views")
|
6
|
+
|
7
|
+
initializer "view_component-contrib.skip_loading_previews_if_disabled" do
|
8
|
+
unless Rails.application.config.view_component.show_previews
|
9
|
+
previews = Rails.application.config.view_component.preview_paths.flat_map do |path|
|
10
|
+
Pathname(path).glob("**/*preview.rb")
|
11
|
+
end
|
12
|
+
Rails.autoloaders.each { |autoloader| autoloader.ignore(previews) }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -22,22 +22,22 @@ module ViewComponentContrib
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
26
|
-
return @
|
25
|
+
def contrib_i18n_scope
|
26
|
+
return @contrib_i18n_scope if defined?(@contrib_i18n_scope)
|
27
27
|
|
28
|
-
@
|
28
|
+
@contrib_i18n_scope = name.sub("::Component", "").underscore.split("/")
|
29
29
|
end
|
30
30
|
|
31
31
|
def i18n_scope=(val)
|
32
32
|
raise ArgumentError, "Must be array" unless val.is_a?(Array)
|
33
33
|
|
34
|
-
@
|
34
|
+
@contrib_i18n_scope = val.dup.freeze
|
35
35
|
end
|
36
36
|
|
37
37
|
def virtual_path
|
38
38
|
@contrib_virtual_path ||= [
|
39
39
|
i18n_namespace,
|
40
|
-
*
|
40
|
+
*contrib_i18n_scope
|
41
41
|
].join(".")
|
42
42
|
end
|
43
43
|
end
|
@@ -3,6 +3,8 @@
|
|
3
3
|
require "ruby-next/language/setup"
|
4
4
|
RubyNext::Language.setup_gem_load_path
|
5
5
|
|
6
|
+
require "view_component"
|
7
|
+
|
6
8
|
module ViewComponentContrib
|
7
9
|
APP_PATH = File.expand_path(File.join(__dir__, "../app"))
|
8
10
|
|
@@ -14,4 +16,5 @@ module ViewComponentContrib
|
|
14
16
|
autoload :Preview, "view_component_contrib/preview"
|
15
17
|
end
|
16
18
|
|
19
|
+
require "view_component_contrib/railtie" if defined?(::Rails::Railtie)
|
17
20
|
require "view_component_contrib/version"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: view_component-contrib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Dementyev
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: view_component
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: ruby-next
|
28
|
+
name: ruby-next
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -166,6 +166,7 @@ files:
|
|
166
166
|
- lib/view_component_contrib/preview/base.rb
|
167
167
|
- lib/view_component_contrib/preview/default_template.rb
|
168
168
|
- lib/view_component_contrib/preview/sidecarable.rb
|
169
|
+
- lib/view_component_contrib/railtie.rb
|
169
170
|
- lib/view_component_contrib/translation_helper.rb
|
170
171
|
- lib/view_component_contrib/version.rb
|
171
172
|
- lib/view_component_contrib/wrapped_helper.rb
|
@@ -179,7 +180,7 @@ metadata:
|
|
179
180
|
documentation_uri: http://github.com/palkan/view_component-contrib
|
180
181
|
homepage_uri: http://github.com/palkan/view_component-contrib
|
181
182
|
source_code_uri: http://github.com/palkan/view_component-contrib
|
182
|
-
post_install_message:
|
183
|
+
post_install_message:
|
183
184
|
rdoc_options: []
|
184
185
|
require_paths:
|
185
186
|
- lib
|
@@ -187,15 +188,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
187
188
|
requirements:
|
188
189
|
- - ">="
|
189
190
|
- !ruby/object:Gem::Version
|
190
|
-
version: '2.
|
191
|
+
version: '2.6'
|
191
192
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
192
193
|
requirements:
|
193
194
|
- - ">="
|
194
195
|
- !ruby/object:Gem::Version
|
195
196
|
version: '0'
|
196
197
|
requirements: []
|
197
|
-
rubygems_version: 3.
|
198
|
-
signing_key:
|
198
|
+
rubygems_version: 3.3.11
|
199
|
+
signing_key:
|
199
200
|
specification_version: 4
|
200
201
|
summary: A collection of extensions and developer tools for ViewComponent
|
201
202
|
test_files: []
|