view_component-contrib 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1df61bb2350983380af49ecddc12cb3e6e5f90b5b05bdc66466a40064c435508
4
- data.tar.gz: 7b03a2c077b2c54cd16deb8720c3d878aa1a0a2d7e1240566aaa4c42fe4e616d
3
+ metadata.gz: 837ad4bbcf45a025383e628eb59f57b1aa9463468045d843eabd061cb3134f2c
4
+ data.tar.gz: c8e9169d866f92ba5c5a67a1214c2909dd6704f340eb8b3f1404ca8efb478bc3
5
5
  SHA512:
6
- metadata.gz: 7ad12d739fad8a74bed8d299212ad41667021cd535f98bbd2a86055808a0f321b8a5919f11ca214f5bb4fc6cbff8199f19a1026d147eea92f2173986aaebcaaa
7
- data.tar.gz: 01724fd258b05e894635ca0a438e45a0369160dc74645f7cd675eeae8eba0157f09f56e000951b0b2b7d3829582ff27950e8219f017a14b1f14252fbfdaadf39
6
+ metadata.gz: d418a0bd1a8cf862f88dd9f4b9bb8d51252e6d5705fb3240fce51d5e014be0c37f06196d8c281845f256d8773d8f558bcd761ffda550b72a7f3bcdb9eeef04c7
7
+ data.tar.gz: 5094714a83ed34e41b2fd2631db68c1ef09d03ffcdb10d2620acac0265771233402f262452bf14932a18587d8877a694b631259d0835a9c2afc8766e3f77cf8b
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.1.1 (2022-03-14)
6
+
7
+ - Fix adding gem's previews to the app's path. ([@palkan][])
8
+
9
+ - Fix configurable default template.
10
+
5
11
  ## 0.1.0 (2021-04-07)
6
12
 
7
13
  - Initial release.
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
- ```html
101
+ ```erb
102
102
  <div class="<%= container_class %>">
103
- <%= render component %>
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
@@ -228,7 +241,7 @@ context.keys().forEach((path) => {
228
241
  // nav/user_info/index.js -> nav--user-info
229
242
  const identifier = path.replace(/^\.\//, '')
230
243
  .replace(/\/index\.js$/, '')
231
- .replace(/\//, '--');
244
+ .replace(/\//g, '--');
232
245
 
233
246
  application.register(identifier, mod.Controller);
234
247
  });
@@ -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}`;
@@ -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") %>
@@ -14,7 +14,8 @@ module ViewComponentContrib
14
14
  alias_method :abstract_class?, :abstract_class
15
15
 
16
16
  def all
17
- super.reject(&:abstract_class?)
17
+ load_previews if descendants.reject(&:abstract_class?).empty?
18
+ descendants.reject(&:abstract_class?)
18
19
  end
19
20
  end
20
21
  end
@@ -30,13 +30,9 @@ module ViewComponentContrib
30
30
  Dir.glob(File.join(path, preview_name, "preview.html.*")).any?
31
31
  end
32
32
 
33
- has_preview_template ? File.join(preview_name, "preview") : DEFAULT_TEMPLATE
33
+ has_preview_template ? File.join(preview_name, "preview") : default_preview_template
34
34
  end
35
35
  end
36
36
  end
37
37
  end
38
38
  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,7 @@
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
+ end
7
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ViewComponentContrib # :nodoc:all
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  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.0
4
+ version: 0.1.1
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: 2021-04-07 00:00:00.000000000 Z
11
+ date: 2022-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: view_component
@@ -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.5'
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.0.6
198
- signing_key:
198
+ rubygems_version: 3.2.22
199
+ signing_key:
199
200
  specification_version: 4
200
201
  summary: A collection of extensions and developer tools for ViewComponent
201
202
  test_files: []