clapton 0.0.18 → 0.0.20

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: 75a7ef3678828970fe19e84f474a8480a2b3aef73bb7cad48d771952560dc26f
4
- data.tar.gz: d183141896d4742b8481d03db28e1d38d1b0ba3d447c8a0c4444d46fa06cec72
3
+ metadata.gz: 81cd4cda35f3f05f9df998b38741783474c8ec88120fc4115bba162595299449
4
+ data.tar.gz: 281d54281936bcfd3f35136419f4ebadbc051809efa38749d60859032eeb4f4b
5
5
  SHA512:
6
- metadata.gz: d22f7c4bd63092f2f1e701f91d8e86d19bd7a7b1f2ea0fe2bc42709d94b84737e34eaacad59b3c58485407932c372b9535cf2649905f81c8a8e2f17b8bfcba3c
7
- data.tar.gz: ea1047109748b7b047c96823727fc3d681d74463d04ca97bb28bac3b354c1b4d3474a9ab001fb03be1029f769cf6fa0ccc69536b24131f75481ae673bd2b08b9
6
+ metadata.gz: bbcd0a11b60e9bae0c2e5e14332d3db99438dae9a1d97731bcb93c7ccd2757653ee1ac4e017864dbf4a90619b48e06817659d1051ebe87d2b28eeeeb074acd33
7
+ data.tar.gz: 02d6310b781922e927a83908aa1238790a63c745d2900990b74c6a1ef7c9ead4a9194826a38db6d9f86155e631a4d2f1008a64c0f0a2fbca90fa323d8f29d791
data/README.md CHANGED
@@ -34,12 +34,12 @@ To use a Clapton component in your view:
34
34
  # app/components/task_list_component.rb
35
35
  class TaskListComponent < Clapton::Component
36
36
  def render
37
- box = c.box
37
+ box = c(:box)
38
38
  @state.tasks.each do |task|
39
39
  box.add(TaskItemComponent.new(id: task[:id], title: task[:title], due: task[:due], done: task[:done]))
40
40
  end
41
- btn = c.button
42
- btn.add(c.text("Add Task"))
41
+ btn = c(:button)
42
+ btn.add(c(:text, "Add Task"))
43
43
  btn.add_action(:click, :TaskListState, :add_task)
44
44
  box.add(btn)
45
45
  end
@@ -51,15 +51,15 @@ end
51
51
  # app/components/task_item_component.rb
52
52
  class TaskItemComponent < Clapton::Component
53
53
  def render
54
- box = c.box
55
- btn = c.button
56
- btn.add(c.text(@state.done ? "✅" : "🟩"))
54
+ box = c(:box)
55
+ btn = c(:button)
56
+ btn.add(c(:text, @state.done ? "✅" : "🟩"))
57
57
  btn.add_action(:click, :TaskListState, :toggle_done)
58
58
 
59
- tf = c.input(@state, :title)
59
+ tf = c(:input, @state, :title)
60
60
  tf.add_action(:input, :TaskListState, :update_title)
61
61
 
62
- dt = c.datetime(@state, :due)
62
+ dt = c(:datetime, @state, :due)
63
63
  dt.add_action(:input, :TaskListState, :update_due)
64
64
 
65
65
  box.add(btn).add(tf).add(dt)
@@ -171,7 +171,7 @@ The `render` event is a special event that is triggered when the component is re
171
171
  class TaskListComponent < Clapton::Component
172
172
  def render
173
173
  # ...
174
- box = c.box
174
+ box = c(:box)
175
175
  box.add_action(:render, :TaskListState, :add_empty_task, debounce: 500)
176
176
  end
177
177
  end
@@ -256,31 +256,31 @@ text = Clapton::Text.new("Hello")`
256
256
  ### Preset Component Methods
257
257
 
258
258
  ```javascript
259
- c.bq(...props)
260
- c.box(...props)
261
- c.b(...props)
262
- c.button(...props)
263
- c.check(...props)
264
- c.code(...props)
265
- c.datetime(...props)
266
- c.el(...props)
267
- c.embed(...props)
268
- c.em(...props)
269
- c.form(...props)
270
- c.h(...props)
271
- c.img(...props)
272
- c.a(...props)
273
- c.li(...props)
274
- c.ul(...props)
275
- c.ol(...props)
276
- c.p(...props)
277
- c.q(...props)
278
- c.radio(...props)
279
- c.select(...props)
280
- c.span(...props)
281
- c.textarea(...props)
282
- c.input(...props)
283
- c.text(...props)
259
+ c(:bq, ...props)
260
+ c(:box, ...props)
261
+ c(:b, ...props)
262
+ c(:button, ...props)
263
+ c(:check, ...props)
264
+ c(:code, ...props)
265
+ c(:datetime, ...props)
266
+ c(:el, ...props)
267
+ c(:embed, ...props)
268
+ c(:em, ...props)
269
+ c(:form, ...props)
270
+ c(:h, ...props)
271
+ c(:img, ...props)
272
+ c(:a, ...props)
273
+ c(:li, ...props)
274
+ c(:ul, ...props)
275
+ c(:ol, ...props)
276
+ c(:p, ...props)
277
+ c(:q, ...props)
278
+ c(:radio, ...props)
279
+ c(:select, ...props)
280
+ c(:span, ...props)
281
+ c(:textarea, ...props)
282
+ c(:input, ...props)
283
+ c(:text, ...props)
284
284
  ```
285
285
 
286
286
  ### Streaming
@@ -349,6 +349,18 @@ module ApplicationCable
349
349
  end
350
350
  ```
351
351
 
352
+ ### Events
353
+
354
+ #### clapton:render
355
+
356
+ The `clapton:render` event is a custom event that is triggered when the component is rendered.
357
+
358
+ ```javascript
359
+ document.addEventListener("clapton:render", () => {
360
+ console.log("clapton:render");
361
+ });
362
+ ```
363
+
352
364
  ### Testing
353
365
 
354
366
  #### RSpec
@@ -9,6 +9,7 @@ module Clapton
9
9
  "imports": {
10
10
  "client": "/clapton/client.js",
11
11
  "components": "/clapton/components.js",
12
+ "c": "/clapton/c.js",
12
13
  #{ all_components.map do
13
14
  |component| "\"#{File.basename(component, ".rb").camelize}\": \"/clapton/#{File.basename(component, ".rb").camelize}.js\""
14
15
  end.join(",\n") }
@@ -24,6 +24,7 @@ module Clapton
24
24
  FileUtils.mkdir_p(Rails.root.join("public", "clapton")) unless Rails.root.join("public", "clapton").exist?
25
25
  File.write(Rails.root.join("public", "clapton", "components.js"), File.read(File.join(__dir__, "javascripts", "dist", "components.js")))
26
26
  File.write(Rails.root.join("public", "clapton", "client.js"), File.read(File.join(__dir__, "javascripts", "dist", "client.js")))
27
+ File.write(Rails.root.join("public", "clapton", "c.js"), File.read(File.join(__dir__, "javascripts", "dist", "c.js")))
27
28
 
28
29
  compile_components
29
30
 
@@ -44,6 +45,8 @@ module Clapton
44
45
  js = ""
45
46
  js += "import { Clapton } from 'components';"
46
47
  js += "\n"
48
+ js += "import { c } from 'c';"
49
+ js += "\n"
47
50
  code.scan(/(\w+)Component\.new/).each do |match|
48
51
  js += "import { #{match[0]}Component } from '#{match[0]}Component';"
49
52
  js += "\n"