komponent 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4023592e98d1c3fd22dee1153f0782e18c0e3008
4
- data.tar.gz: f5c82a9ac16d366cddcc1c22c8517604b7f6deda
3
+ metadata.gz: f58c3da5a2b11f34695dcf60c3d2e4d943f0bb97
4
+ data.tar.gz: fc3d219e942b0649b983d2b943b254c151bbb43f
5
5
  SHA512:
6
- metadata.gz: 167a8d4d1bb14e3ed1521dd5512b1496a527dbd77b8ef3b3f7d02fdf447e6428623bf3055330b840f6c55bcca615ced56e7beec6b3087da73496d268ef950ef7
7
- data.tar.gz: faec5c09267be7d1fa4552672ae062c7a67e029dc972937640c53416e91dfb8f5313e631cd4ca3fa0557337f1af5a39ba22d9662895fd25da07f6d5531c2b913
6
+ metadata.gz: 12825b03452c3b914efe7ff4b0c9e3ac76fbb21b79da3f83ef03fdd48dbbd4bf737b1bc7e73e8f2af5be002f19330031999a0b407dfa6be3478868d8c063f01b
7
+ data.tar.gz: 25f321f222d8cd35224060365069d151e8535cf8910b86e942e778440bb15546be7d812539fdb3fb42d6c8106ca863d5bd6eaa9c87e979dfabff9e657dafa186
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## Upcoming release
4
4
 
5
+ **Enhancements:**
6
+ - Support for Stimulus 1.0
7
+ - `import`s are now sorted alphabetically every time you run the component generator
8
+ - Added the `block_given_to_component?` helper to components
9
+
5
10
  ## v1.1.1 (2018-01-20)
6
11
 
7
12
  **Enhancements:**
data/README.md CHANGED
@@ -30,6 +30,7 @@ This gem has been inspired by our Rails development practices at [Ouvrages](http
30
30
  - [Configuration](#configuration)
31
31
  - [Change default root path](#change-default-root-path)
32
32
  - [Default options for the generators](#default-options-for-the-generators)
33
+ - [Force default templating engine](#force-default-templating-engine)
33
34
  - [Additional paths](#additional-paths)
34
35
  - [Contributing](#contributing)
35
36
  - [License](#license)
@@ -124,6 +125,8 @@ The component also accepts a `block`. To render the block, just use the standard
124
125
  = yield
125
126
  ```
126
127
 
128
+ You can check if the component has been called with a block using the `block_given_to_component?` helper from within the component.
129
+
127
130
  ### Properties
128
131
 
129
132
  Each component comes with a Ruby `module`. You can use it to set properties:
@@ -206,7 +209,9 @@ This will create the component in an `admin` folder, and name its Ruby module `A
206
209
 
207
210
  ### Stimulus integration
208
211
 
209
- You can pass `--stimulus` to both generators to use [stimulus](https://github.com/stimulusjs/stimulus) in your components.
212
+ Komponent supports [stimulus](https://github.com/stimulusjs/stimulus) 1.0.
213
+
214
+ You can pass `--stimulus` to both generators to use Stimulus in your components.
210
215
 
211
216
  ```sh
212
217
  rails generate komponent:install --stimulus
@@ -274,6 +279,14 @@ You can change the default root path (`frontend`) to another path where Komponen
274
279
  Rails.application.config.komponent.root = Rails.root.join("app/frontend")
275
280
  ```
276
281
 
282
+ #### Force default templating engine
283
+
284
+ If for some reason your preferred templating engine is not detected by Komponent, you can force it by manually defining it in your config:
285
+
286
+ ```rb
287
+ Rails.application.config.generators.template_engine = :haml
288
+ ```
289
+
277
290
  #### Additional paths
278
291
 
279
292
  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.
@@ -297,7 +310,7 @@ module MyGem
297
310
  app.config.autoload_paths << MyGem.root.join("frontend")
298
311
  end
299
312
  end
300
-
313
+
301
314
  private
302
315
 
303
316
  def self.root
@@ -52,14 +52,16 @@ class ComponentGenerator < Rails::Generators::NamedBase
52
52
  import = imports.shift
53
53
  if import
54
54
  append_to_file(root_path_dup + "index.js") do
55
- "import \"#{import}\";\n"
55
+ "\nimport \"#{import}\";\n"
56
56
  end
57
+ sort_lines_alphabetically!(root_path_dup + "index.js")
57
58
  end
58
59
  end
59
60
 
60
61
  append_to_file(base_path + "index.js") do
61
- "import \"#{base_path.relative_path_from(root_path)}/#{component_name}/#{name_with_namespace.underscore}\";\n"
62
+ "\nimport \"#{base_path.relative_path_from(root_path)}/#{component_name}/#{name_with_namespace.underscore}\";\n"
62
63
  end
64
+ sort_lines_alphabetically!(base_path + "index.js")
63
65
  end
64
66
 
65
67
  protected
@@ -136,4 +138,20 @@ class ComponentGenerator < Rails::Generators::NamedBase
136
138
  def app_generators
137
139
  rails_configuration.app_generators
138
140
  end
141
+
142
+ def sort_lines_alphabetically!(path)
143
+ lines = File.readlines(path).map do |line|
144
+ line if line =~ /^import "(.*)";$/
145
+ end.compact
146
+
147
+ return if lines.empty?
148
+
149
+ lines = lines.sort
150
+
151
+ File.open(path, "w") do |f|
152
+ lines.each do |line|
153
+ f.write(line)
154
+ end
155
+ end
156
+ end
139
157
  end
@@ -1,11 +1,8 @@
1
- <%- if stimulus? -%>
2
- import application from 'stimulus_application';
3
- import { autoload } from "stimulus/webpack-helpers";
4
-
5
1
  import "./<%= name_with_namespace %>.<%= stylesheet_engine %>";
2
+ <%- if stimulus? -%>
3
+ import application from "stimulus_application";
4
+ import { definitionsFromContext } from "stimulus/webpack-helpers";
6
5
 
7
6
  const context = require.context('./', true, /_controller\.js$/);
8
- autoload(context, application);
9
- <%- else -%>
10
- import "./<%= name_with_namespace %>.<%= stylesheet_engine %>";
7
+ application.load(definitionsFromContext(context));
11
8
  <%- end -%>
@@ -1,9 +1,7 @@
1
1
  import { Controller } from "stimulus";
2
- import "./<%= name_with_namespace %>.<%= stylesheet_engine %>";
3
2
 
4
3
  export default class extends Controller {
5
4
  connect() {
6
5
  console.log("Hello, Stimulus!", this.element);
7
6
  }
8
7
  }
9
-
@@ -7,5 +7,10 @@ module ComponentHelper
7
7
 
8
8
  def self.extended(component)
9
9
  component.properties = {}
10
+ component.class_eval do
11
+ def block_given_to_component?
12
+ @block_given_to_component.present?
13
+ end
14
+ end
10
15
  end
11
16
  end
@@ -39,18 +39,15 @@ module KomponentHelper
39
39
  locals.each do |name, value|
40
40
  instance_variable_set(:"@#{name}", locals[name] || options[:default])
41
41
  end
42
+
43
+ instance_variable_set(:"@block_given_to_component", block)
42
44
  end
43
45
 
44
- custom_method = :"render_#{component_name}"
45
- if context.respond_to?(custom_method)
46
- context.public_send(custom_method, locals, &capture_block)
47
- else
48
- begin
49
- context.render("components/#{component}/#{parts.join('_')}", &capture_block)
50
- rescue ActionView::MissingTemplate
51
- warn "[DEPRECATION WARNING] `#{parts.last}` filename in namespace is deprecated in favor of `#{parts.join('_')}`."
52
- context.render("components/#{component}/#{parts.last}", &capture_block)
53
- end
46
+ begin
47
+ context.render("components/#{component}/#{parts.join('_')}", &capture_block)
48
+ rescue ActionView::MissingTemplate
49
+ warn "[DEPRECATION WARNING] `#{parts.last}` filename in namespace is deprecated in favor of `#{parts.join('_')}`."
50
+ context.render("components/#{component}/#{parts.last}", &capture_block)
54
51
  end
55
52
  end
56
53
  alias :c :component
@@ -1,3 +1,3 @@
1
1
  module Komponent
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
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.1
4
+ version: 1.1.2
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-20 00:00:00.000000000 Z
11
+ date: 2018-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aruba