custom_elements-rails 0.1.1 → 0.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
  SHA256:
3
- metadata.gz: 22d257cc2e8c052814180e03810ed19525ffaae2989826a5660dc0306dfc3df2
4
- data.tar.gz: 2661b7ce42c1a797e0d52fd8deb91922e6af03b8045a31656ec4c59c2f392dc5
3
+ metadata.gz: b77ebf93580a7eb3cb83365dc83ba086f6d3bb1f20e173020039c08c5234669c
4
+ data.tar.gz: fc62a709561eeeefdae11cac69983062664d21065e058b376932258d3d1a522a
5
5
  SHA512:
6
- metadata.gz: c92ca66bdfd4c7a9bc5eb90bb383506716bf0efbe1ec977371695a45362578e15292bf22321381f04ba48ea4cb49699fa797b64ecf0d16f19f2d4c53316a5876
7
- data.tar.gz: fa02fa675a3a96445063e0eb5a825c942c6e85658c587d6b70ca2ef6858c3e5eb892c11114715e42aebdee0d5418a46821054b01c2fa09e5ff827b76fdf9e77a
6
+ metadata.gz: bb09a978e032b95385a14b5a2e7ef060edd995981466eb941cef16c423bf27ba00ab012f9169e9502ea40c60308014b19fcdc8e3d1601b3f57c847d830cd276b
7
+ data.tar.gz: b7dc6b1f79854aa70ae148222eb8093d772cb647f927dc7d73f4d8a7b0202389c4f5f80db1f2645bb21c8982e4785aa1097365fd521521d12a9670b3100a8ebf
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Custom Elements with Rails
2
2
 
3
- This gem provides a small helper and installation scripts to use custom elements in conjunction with `importmap-rails`.
3
+ This gem provides a small js-helper, installation and generators to use custom elements in conjunction with `importmap-rails`.
4
4
 
5
5
  ## Usage
6
6
 
@@ -33,14 +33,44 @@ app/javascript
33
33
  └── index.js
34
34
  ```
35
35
 
36
- You can now add the `<app-hello>` custom element in your app. No build step needed.
36
+ You can now add the `<app-hello>` custom element in your HTML. No build step needed.
37
+
38
+ ## How it works
39
+
40
+ `eagerDefineCustomElementsFrom("custom_elements", { prefix: "app" })` will parse the JSON-importmap rendered by the `importmap-rails` gem and register custom elements with `customElements.define(...)` to the browser's custom element registry.
41
+
42
+ ```
43
+ custom_elements/hello_element.js // will register <app-hello>
44
+ ```
45
+
46
+ Your `_element.js` files have to `export default` custom elements for this to work.
47
+
48
+ > [!WARNING]
49
+ > Only single word elements are support currently.
50
+
37
51
 
38
52
  ## Add a custom element
39
53
 
40
- TODO
54
+ Generate a new custom element with:
55
+
56
+ ```bash
57
+ $ rails generate custom_element test
58
+ ```
59
+
60
+ This will generate
61
+
62
+ ```
63
+ app/javascript
64
+ └── custom_elements
65
+ └── test_element.js
66
+ ```
67
+
68
+ which in turn will register a `<app-test></app-test>` custom element.
41
69
 
42
70
  ## Contributing
43
- Contribution directions go here.
71
+
72
+ TODO
44
73
 
45
74
  ## License
75
+
46
76
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,5 +1,5 @@
1
1
  module CustomElements
2
2
  module Rails
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
@@ -0,0 +1,8 @@
1
+ class CustomElementGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path("templates", __dir__)
3
+
4
+ def copy_custom_element
5
+ template "custom_element.js", "app/javascript/custom_elements/#{file_name}_element.js"
6
+ end
7
+ end
8
+
@@ -0,0 +1,9 @@
1
+ export default class extends HTMLElement {
2
+ constructor() {
3
+ super()
4
+ }
5
+
6
+ connectedCallback() {
7
+ console.log("<%= file_name %>")
8
+ }
9
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: custom_elements-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Niklas Häusele
@@ -38,6 +38,8 @@ files:
38
38
  - lib/custom_elements/rails.rb
39
39
  - lib/custom_elements/rails/railtie.rb
40
40
  - lib/custom_elements/rails/version.rb
41
+ - lib/generators/custom_element_generator.rb
42
+ - lib/generators/templates/custom_element.js.tt
41
43
  - lib/install/install.rb
42
44
  - lib/tasks/custom_elements/rails_tasks.rake
43
45
  homepage: https://github.com/codergeek121/custom_elements-rails