clapton 0.0.6 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -0
- data/app/helpers/clapton/clapton_helper.rb +10 -0
- data/lib/clapton/javascripts/dist/client.js +7 -3
- data/lib/clapton/javascripts/src/client.ts +7 -3
- data/lib/clapton/version.rb +2 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 046d950b41177907e9ab5aeeecddbed15ba622b5f4af1b68be7931ac5b50ee81
|
4
|
+
data.tar.gz: 673129d40cb46bbdd4b98083d79d256acfc04c6361ae275c71db2cbc0fc22f6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 922bfbd2feae17c2ae3a040ce2eb573e7a9a1b951f93775c0f24b44bc90569177eb93e95bfb16f2fe515dcaec5d3526c92d976f29779d3a31d4024eeae4b42aa
|
7
|
+
data.tar.gz: 8157150ab886370b4dbff0cd38fcd064ba9e044422cb45a8d9940b67b77ed3e781679ee38c01604cb000ef59f3e0360c2e785c69d725925e809d2021a4a6aedb
|
data/README.md
CHANGED
@@ -137,6 +137,17 @@ mount Clapton::Engine => "/clapton"
|
|
137
137
|
|
138
138
|
![TODO APP DEMO](./docs/todo-app-demo.gif)
|
139
139
|
|
140
|
+
### Component rendering
|
141
|
+
|
142
|
+
```html
|
143
|
+
<%= clapton_component_tag(
|
144
|
+
:TaskListComponent,
|
145
|
+
{
|
146
|
+
tasks: @tasks.map { |task| { id: task.id, title: task.title, due: task.due, done: task.done } }
|
147
|
+
}
|
148
|
+
) %>
|
149
|
+
```
|
150
|
+
|
140
151
|
### Generate Component and State
|
141
152
|
|
142
153
|
```bash
|
@@ -17,5 +17,15 @@ module Clapton
|
|
17
17
|
end
|
18
18
|
tag.div(id: "clapton", data: { clapton: datas })
|
19
19
|
end
|
20
|
+
|
21
|
+
def clapton_component_tag(component, params)
|
22
|
+
state_class = component.to_s.gsub("Component", "State")
|
23
|
+
if Object.const_defined?(state_class)
|
24
|
+
data = { component: component.to_s, state: Object.const_get(state_class).new(params).to_h }
|
25
|
+
else
|
26
|
+
data = { component: component.to_s, state: {} }
|
27
|
+
end
|
28
|
+
tag.div(class: "clapton-component", data: { clapton: data })
|
29
|
+
end
|
20
30
|
end
|
21
31
|
end
|
@@ -1393,15 +1393,19 @@ const initializeInputs$1 = () => {
|
|
1393
1393
|
|
1394
1394
|
const initializeComponents = () => {
|
1395
1395
|
const components = document.querySelector("#clapton")?.getAttribute("data-clapton") || "[]";
|
1396
|
-
JSON.parse(components).forEach(createAndAppendComponent);
|
1396
|
+
JSON.parse(components).forEach((component) => createAndAppendComponent(component, document.querySelector("#clapton")));
|
1397
|
+
document.querySelectorAll(".clapton-component").forEach((element) => {
|
1398
|
+
const component = JSON.parse(element.getAttribute("data-clapton") || "{}");
|
1399
|
+
createAndAppendComponent(component, element);
|
1400
|
+
});
|
1397
1401
|
};
|
1398
|
-
const createAndAppendComponent = (component) => {
|
1402
|
+
const createAndAppendComponent = (component, element) => {
|
1399
1403
|
const componentDom = document.createElement('div');
|
1400
1404
|
const instance = new window[component.component](component.state);
|
1401
1405
|
componentDom.innerHTML = instance.render;
|
1402
1406
|
const firstChild = componentDom.firstChild;
|
1403
1407
|
if (firstChild) {
|
1404
|
-
|
1408
|
+
element.appendChild(firstChild);
|
1405
1409
|
}
|
1406
1410
|
};
|
1407
1411
|
document.addEventListener("DOMContentLoaded", () => {
|
@@ -17,16 +17,20 @@ interface ComponentInstance {
|
|
17
17
|
|
18
18
|
const initializeComponents = () => {
|
19
19
|
const components = document.querySelector("#clapton")?.getAttribute("data-clapton") || "[]";
|
20
|
-
JSON.parse(components).forEach(createAndAppendComponent);
|
20
|
+
JSON.parse(components).forEach((component: ComponentDefinition) => createAndAppendComponent(component, document.querySelector("#clapton")!));
|
21
|
+
document.querySelectorAll(".clapton-component").forEach((element) => {
|
22
|
+
const component = JSON.parse(element.getAttribute("data-clapton") || "{}");
|
23
|
+
createAndAppendComponent(component, element as HTMLElement);
|
24
|
+
});
|
21
25
|
};
|
22
26
|
|
23
|
-
const createAndAppendComponent = (component: ComponentDefinition) => {
|
27
|
+
const createAndAppendComponent = (component: ComponentDefinition, element: HTMLElement) => {
|
24
28
|
const componentDom = document.createElement('div');
|
25
29
|
const instance = new (window[component.component as any] as any)(component.state);
|
26
30
|
componentDom.innerHTML = instance.render;
|
27
31
|
const firstChild = componentDom.firstChild as HTMLElement;
|
28
32
|
if (firstChild) {
|
29
|
-
|
33
|
+
element.appendChild(firstChild);
|
30
34
|
}
|
31
35
|
};
|
32
36
|
|
data/lib/clapton/version.rb
CHANGED