komponent 1.1.0 → 1.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
  SHA1:
3
- metadata.gz: 4658a034e4427f5870e308f64d0699e9b588b198
4
- data.tar.gz: ef78a5b00c52b95676b15741765c8d221d12c697
3
+ metadata.gz: 4023592e98d1c3fd22dee1153f0782e18c0e3008
4
+ data.tar.gz: f5c82a9ac16d366cddcc1c22c8517604b7f6deda
5
5
  SHA512:
6
- metadata.gz: e362c8e4e277a68bfbf469c27c15f47a2544925710c16901b94eaf4b3d56a7359237f2b747a9b157ec68cc256476d11212456a37bc89e151b2d6aa6b8c823e2d
7
- data.tar.gz: d8d8e23f3b219769d250cb58c46428bcc6344bbc68c18b300b39ef3d75d7d2ad8935ae44920da98d0a756dfd4efa08073d45f6e79222d492ff799454b027b5d2
6
+ metadata.gz: 167a8d4d1bb14e3ed1521dd5512b1496a527dbd77b8ef3b3f7d02fdf447e6428623bf3055330b840f6c55bcca615ced56e7beec6b3087da73496d268ef950ef7
7
+ data.tar.gz: faec5c09267be7d1fa4552672ae062c7a67e029dc972937640c53416e91dfb8f5313e631cd4ca3fa0557337f1af5a39ba22d9662895fd25da07f6d5531c2b913
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## Upcoming release
4
4
 
5
+ ## v1.1.1 (2018-01-20)
6
+
7
+ **Enhancements:**
8
+ - Add an option to change default root path where Komponent is installed, and components are generated
9
+
5
10
  ## v1.1.0 (2018-01-12)
6
11
 
7
12
  **Enhancements:**
data/README.md CHANGED
@@ -28,6 +28,7 @@ This gem has been inspired by our Rails development practices at [Ouvrages](http
28
28
  - [Stimulus integration](#stimulus-integration)
29
29
  - [Internationalization](#internationalization)
30
30
  - [Configuration](#configuration)
31
+ - [Change default root path](#change-default-root-path)
31
32
  - [Default options for the generators](#default-options-for-the-generators)
32
33
  - [Additional paths](#additional-paths)
33
34
  - [Contributing](#contributing)
@@ -71,6 +72,23 @@ Then, render it in your views with the `component` helper (or its alias `c`).
71
72
  = c "button"
72
73
  ```
73
74
 
75
+ Make sure to include javascript pack tag and stylesheet pack tag in your application layout file, for instance:
76
+
77
+ ```slim
78
+ / app/views/layouts/application.html.slim
79
+
80
+ doctype html
81
+ html
82
+ head
83
+ = stylesheet_pack_tag "application"
84
+
85
+ body
86
+ = yield
87
+ = javascript_pack_tag "application"
88
+ ```
89
+
90
+ Check [Webpacker documentation](https://github.com/rails/webpacker) for further information.
91
+
74
92
  ### Passing variables
75
93
 
76
94
  You can pass `locals` to the helper. They are accessible within the component partial, as instance variables.
@@ -214,20 +232,23 @@ This will create a `yml` file for each locale (using `I18n.available_locales`).
214
232
 
215
233
  ```slim
216
234
  / frontend/components/button/_button.html.slim
235
+
217
236
  = a.button(href=@href)
218
237
  = @text
219
238
  = render("suffix", text: t(".external_link")) if external_link?
220
239
  ```
221
240
 
222
241
  ```yml
223
- / frontend/components/button/button.en.yml
242
+ # frontend/components/button/button.en.yml
243
+
224
244
  en:
225
245
  button_component:
226
246
  external_link: "external link"
227
247
  ```
228
248
 
229
249
  ```yml
230
- / frontend/components/button/button.fr.yml
250
+ # frontend/components/button/button.fr.yml
251
+
231
252
  fr:
232
253
  button_component:
233
254
  external_link: "lien externe"
@@ -245,6 +266,14 @@ config.generators do |g|
245
266
  end
246
267
  ```
247
268
 
269
+ #### Change default root path
270
+
271
+ You can change the default root path (`frontend`) to another path where Komponent should be installed and components generated. You need to change `komponent.root` in an initializer.
272
+
273
+ ```rb
274
+ Rails.application.config.komponent.root = Rails.root.join("app/frontend")
275
+ ```
276
+
248
277
  #### Additional paths
249
278
 
250
279
  You may want to use components in a gem, or a Rails engine, and expose them to the main app. In order to do that, you just have to configure the paths where Komponent will look for components.
@@ -255,24 +284,24 @@ From a gem:
255
284
  module MyGem
256
285
  class Railtie < Rails::Railtie
257
286
  config.after_initialize do |app|
258
- app.config.komponent.component_paths.append(self.root.join("frontend/components"))
287
+ app.config.komponent.component_paths.append(MyGem.root.join("frontend/components"))
259
288
  end
260
289
 
261
290
  initializer "my_gem.action_dispatch" do |app|
262
291
  ActiveSupport.on_load :action_controller do
263
- ActionController::Base.prepend_view_path self.root.join("frontend")
292
+ ActionController::Base.prepend_view_path MyGem.root.join("frontend")
264
293
  end
265
294
  end
266
295
 
267
296
  initializer 'my_gem.autoload', before: :set_autoload_paths do |app|
268
- app.config.autoload_paths << self.root.join("frontend")
297
+ app.config.autoload_paths << MyGem.root.join("frontend")
269
298
  end
299
+ end
300
+
301
+ private
270
302
 
271
- private
272
-
273
- def self.root
274
- Pathname.new(File.dirname(__dir__))
275
- end
303
+ def self.root
304
+ Pathname.new(File.dirname(__dir__))
276
305
  end
277
306
  end
278
307
  ```
@@ -33,7 +33,7 @@ class ComponentGenerator < Rails::Generators::NamedBase
33
33
  end
34
34
 
35
35
  def import_to_packs
36
- root_path = Pathname.new("frontend")
36
+ root_path = default_path
37
37
  base_path = root_path + "components"
38
38
 
39
39
  imports = []
@@ -77,7 +77,7 @@ class ComponentGenerator < Rails::Generators::NamedBase
77
77
  end
78
78
 
79
79
  def component_path
80
- path_parts = ["frontend", "components", *split_name]
80
+ path_parts = [default_path, "components", *split_name]
81
81
 
82
82
  Pathname.new(path_parts.join("/"))
83
83
  end
@@ -106,6 +106,10 @@ class ComponentGenerator < Rails::Generators::NamedBase
106
106
  end
107
107
  end
108
108
 
109
+ def default_path
110
+ rails_configuration.komponent.root
111
+ end
112
+
109
113
  def locale?
110
114
  return options[:locale] if options[:locale]
111
115
  komponent_configuration[:locale]
@@ -119,7 +123,10 @@ class ComponentGenerator < Rails::Generators::NamedBase
119
123
  private
120
124
 
121
125
  def komponent_configuration
122
- { stimulus: nil, locale: nil }.merge app_generators.komponent
126
+ {
127
+ stimulus: nil,
128
+ locale: nil,
129
+ }.merge(app_generators.komponent)
123
130
  end
124
131
 
125
132
  def rails_configuration
@@ -1,6 +1,6 @@
1
- div data-controller="<%= component_class_name %>" class="<%= component_class_name %>"
1
+ .<%= component_class_name %>(data-controller="<%= component_class_name %>")
2
2
  <%- if locale? -%>
3
3
  = t ".component_name"
4
4
  <%- else -%>
5
- <%= module_name.underscore %>
5
+ | <%= module_name.underscore %>
6
6
  <%- end -%>
@@ -1,6 +1,6 @@
1
- div class="<%= component_class_name %>"
1
+ .<%= component_class_name %>
2
2
  <%- if locale? -%>
3
3
  = t "<%= module_name.underscore %>.component_name"
4
4
  <%- else -%>
5
- <%= module_name.underscore %>
5
+ | <%= module_name.underscore %>
6
6
  <%- end -%>
@@ -14,7 +14,7 @@ module Komponent
14
14
  end
15
15
 
16
16
  def modify_webpacker_configuration
17
- gsub_file(webpacker_configuration_file, /source_path: app\/javascript$/, "source_path: frontend")
17
+ gsub_file(webpacker_configuration_file, /source_path: app\/javascript$/, "source_path: #{relative_path_from_rails}")
18
18
  end
19
19
 
20
20
  def move_webpacker_default_structure
@@ -27,12 +27,7 @@ module Komponent
27
27
  end
28
28
 
29
29
  def create_stimulus_file
30
- template = <<-eos
31
- import { Application } from "stimulus";
32
- const application = Application.start();
33
- export default application;
34
- eos
35
- create_file(stimulus_application_path, stimulus? ? template : "")
30
+ create_file(stimulus_application_path, stimulus? ? stimulus_application_template : "")
36
31
  end
37
32
 
38
33
  def append_to_application_pack
@@ -47,7 +42,15 @@ export default application;
47
42
  end
48
43
  end
49
44
 
50
- private
45
+ protected
46
+
47
+ def stimulus_application_template
48
+ <<~HEREDOC
49
+ import { Application } from "stimulus";
50
+ const application = Application.start();
51
+ export default application;
52
+ HEREDOC
53
+ end
51
54
 
52
55
  def stimulus_application_path
53
56
  komponent_root_directory.join("stimulus_application.js")
@@ -58,7 +61,7 @@ export default application;
58
61
  end
59
62
 
60
63
  def komponent_root_directory
61
- Rails.root.join("frontend")
64
+ default_path
62
65
  end
63
66
 
64
67
  def components_directory
@@ -82,10 +85,21 @@ export default application;
82
85
  komponent_configuration[:stimulus]
83
86
  end
84
87
 
88
+ def default_path
89
+ rails_configuration.komponent.root
90
+ end
91
+
92
+ def relative_path_from_rails
93
+ default_path.relative_path_from(Rails.root)
94
+ end
95
+
85
96
  private
86
97
 
87
98
  def komponent_configuration
88
- { stimulus: nil, locale: nil }.merge app_generators.komponent
99
+ {
100
+ stimulus: nil,
101
+ locale: nil,
102
+ }.merge(app_generators.komponent)
89
103
  end
90
104
 
91
105
  def rails_configuration
@@ -6,34 +6,37 @@ require 'komponent/core/component_path_resolver'
6
6
  module Komponent
7
7
  class Railtie < Rails::Railtie
8
8
  config.komponent = ActiveSupport::OrderedOptions.new
9
+ config.komponent.root = nil
9
10
  config.komponent.component_paths = []
10
11
 
11
12
  config.before_configuration do |app|
13
+ app.config.komponent.root = app.config.root.join("frontend")
12
14
  app.config.komponent = config.komponent
13
- app.config.komponent.component_paths.append(app.config.root.join("frontend/components"))
14
15
  end
15
16
 
16
- initializer "komponent.action_view" do |app|
17
+ config.after_initialize do |app|
18
+ app.config.komponent.component_paths.prepend(
19
+ app.config.komponent.root.join("components")
20
+ )
21
+
17
22
  ActiveSupport.on_load :action_view do
18
23
  require 'komponent/komponent_helper'
19
24
  include KomponentHelper
20
25
  end
21
- end
22
26
 
23
- initializer "komponent.action_dispatch" do |app|
24
27
  ActiveSupport.on_load :action_controller do
25
- ActionController::Base.prepend_view_path "#{app.config.root}/frontend"
28
+ ActionController::Base.prepend_view_path(
29
+ app.config.komponent.root
30
+ )
26
31
  end
27
- end
28
32
 
29
- initializer "komponent.i18n" do |app|
30
33
  ActiveSupport.on_load :i18n do
31
- I18n.load_path.concat(Dir["#{app.config.root}/frontend/components/**/*.yml"])
34
+ I18n.load_path.concat(
35
+ Dir["#{app.config.komponent.root}/components/**/*.yml"]
36
+ )
32
37
  end
33
- end
34
38
 
35
- initializer 'komponent.autoload', before: :set_autoload_paths do |app|
36
- app.config.autoload_paths << "#{app.config.root}/frontend"
39
+ app.config.autoload_paths += [app.config.komponent.root]
37
40
  end
38
41
  end
39
42
  end
@@ -1,3 +1,3 @@
1
1
  module Komponent
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: komponent
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ouvrages
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-12 00:00:00.000000000 Z
11
+ date: 2018-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aruba