bob-compiler 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +35 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +38 -0
- data/LICENSE +22 -0
- data/README.md +8 -0
- data/Rakefile +9 -0
- data/bob-compiler.gemspec +27 -0
- data/lib/bob/compiler.rb +8 -0
- data/lib/bob/compiler/base.rb +132 -0
- data/lib/bob/compiler/block.rb +21 -0
- data/lib/bob/compiler/buffer.rb +79 -0
- data/lib/bob/compiler/editable.rb +86 -0
- data/lib/bob/compiler/layout.rb +51 -0
- data/lib/bob/compiler/message.rb +21 -0
- data/lib/bob/compiler/substitution.rb +57 -0
- data/lib/bob/compiler/template.rb +90 -0
- data/lib/bob/compiler/version.rb +5 -0
- data/lib/bob/compiler/walker.rb +112 -0
- data/test/blocks_test.rb +82 -0
- data/test/fixtures/blocks/bar.html +10 -0
- data/test/fixtures/blocks/bar.js +63 -0
- data/test/fixtures/blocks/foo.html +4 -0
- data/test/fixtures/blocks/foo.js +30 -0
- data/test/fixtures/blocks/foobar.html +5 -0
- data/test/fixtures/blocks/foobar.js +23 -0
- data/test/fixtures/blocks/substitions.html +15 -0
- data/test/fixtures/blocks/substitions.js +56 -0
- data/test/fixtures/layout/simple.html +31 -0
- data/test/fixtures/layout/simple.js +66 -0
- data/test/fixtures/templates/simple.html +55 -0
- data/test/fixtures/templates/simple.js +168 -0
- data/test/layouts_test.rb +76 -0
- data/test/templates_test.rb +51 -0
- data/test/test_helper.rb +43 -0
- metadata +180 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
function(dom, env) {
|
2
|
+
var descriptor = {
|
3
|
+
"type": "foo",
|
4
|
+
"element": null,
|
5
|
+
"editables": [
|
6
|
+
|
7
|
+
]
|
8
|
+
};
|
9
|
+
|
10
|
+
dom.createElement("div");
|
11
|
+
dom.appendTextNode("\n ");
|
12
|
+
dom.createElement("h3");
|
13
|
+
dom.appendTextNode("Foo");
|
14
|
+
dom.appendElement();
|
15
|
+
dom.appendTextNode("\n ");
|
16
|
+
dom.createElement("div");
|
17
|
+
descriptor.editables.push({
|
18
|
+
type: "html",
|
19
|
+
name: "zomg",
|
20
|
+
element: dom.getElement(),
|
21
|
+
options: {
|
22
|
+
}
|
23
|
+
});
|
24
|
+
dom.appendElement();
|
25
|
+
dom.appendTextNode("\n");
|
26
|
+
|
27
|
+
descriptor.element = dom.getElement();
|
28
|
+
|
29
|
+
return descriptor;
|
30
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
function(dom, env) {
|
2
|
+
var descriptor = {
|
3
|
+
"type": "foo-bar",
|
4
|
+
"element": null,
|
5
|
+
"editables": [
|
6
|
+
|
7
|
+
]
|
8
|
+
};
|
9
|
+
|
10
|
+
dom.createElement("div");
|
11
|
+
dom.appendTextNode("\n");
|
12
|
+
descriptor.editables.push({
|
13
|
+
type: "abc-de/f-123",
|
14
|
+
name: "foobar",
|
15
|
+
element: dom.getElement(),
|
16
|
+
options: {
|
17
|
+
}
|
18
|
+
});
|
19
|
+
|
20
|
+
descriptor.element = dom.getElement();
|
21
|
+
|
22
|
+
return descriptor;
|
23
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<div bob-block="substitions">
|
2
|
+
<!-- LINK ID: {{link.id}} -->
|
3
|
+
<h3>
|
4
|
+
<a href="{{link.url}}" target="_blank" bob-editable="plaintext">{{link.title}}</a>
|
5
|
+
</h3>
|
6
|
+
<img src="http://my.cdn/{{link.thumbnail_path}}?s={{link.thumbnail_size || '120'}}"
|
7
|
+
alt="{{link.title}}"
|
8
|
+
width="{{link.thumbnail_size || '120'}}"
|
9
|
+
height="{{link.thumbnail_size || '120'}}">
|
10
|
+
<div bob-editable="html" bob-option-link-id="{{link.id}}">
|
11
|
+
{{link.description}}
|
12
|
+
</div>
|
13
|
+
<!-- {{ some_stuff || "\" \{\{ 'escaped' \}\} \"" }} -->
|
14
|
+
\{{ escaped }}
|
15
|
+
</div>
|
@@ -0,0 +1,56 @@
|
|
1
|
+
function(dom, env) {
|
2
|
+
var descriptor = {
|
3
|
+
"type": "substitions",
|
4
|
+
"element": null,
|
5
|
+
"editables": [
|
6
|
+
|
7
|
+
]
|
8
|
+
};
|
9
|
+
|
10
|
+
dom.createElement("div");
|
11
|
+
dom.appendTextNode("\n ");
|
12
|
+
dom.appendComment(" LINK ID: " + env.get("link.id") + " ");
|
13
|
+
dom.appendTextNode("\n ");
|
14
|
+
dom.createElement("h3");
|
15
|
+
dom.appendTextNode("\n ");
|
16
|
+
dom.createElement("a");
|
17
|
+
dom.setAttribute("href", env.get("link.url"));
|
18
|
+
dom.setAttribute("target", "_blank");
|
19
|
+
dom.appendTextNode(env.get("link.title"));
|
20
|
+
descriptor.editables.push({
|
21
|
+
type: "plaintext",
|
22
|
+
name: "plaintext0",
|
23
|
+
element: dom.getElement(),
|
24
|
+
options: {
|
25
|
+
}
|
26
|
+
});
|
27
|
+
dom.appendElement();
|
28
|
+
dom.appendTextNode("\n ");
|
29
|
+
dom.appendElement();
|
30
|
+
dom.appendTextNode("\n ");
|
31
|
+
dom.createElement("img");
|
32
|
+
dom.setAttribute("src", "http://my.cdn/" + env.get("link.thumbnail_path") + "?s=" + env.get("link.thumbnail_size", "120"));
|
33
|
+
dom.setAttribute("alt", env.get("link.title"));
|
34
|
+
dom.setAttribute("width", env.get("link.thumbnail_size", "120"));
|
35
|
+
dom.setAttribute("height", env.get("link.thumbnail_size", "120"));
|
36
|
+
dom.appendElement();
|
37
|
+
dom.appendTextNode("\n ");
|
38
|
+
dom.createElement("div");
|
39
|
+
dom.appendTextNode("\n " + env.get("link.description") + "\n ");
|
40
|
+
descriptor.editables.push({
|
41
|
+
type: "html",
|
42
|
+
name: "html0",
|
43
|
+
element: dom.getElement(),
|
44
|
+
options: {
|
45
|
+
"link-id": env.get("link.id"),
|
46
|
+
}
|
47
|
+
});
|
48
|
+
dom.appendElement();
|
49
|
+
dom.appendTextNode("\n ");
|
50
|
+
dom.appendComment(" " + env.get("some_stuff", "\" {{ 'escaped' }} \"") + " ");
|
51
|
+
dom.appendTextNode("\n " + "\\{{ escaped }}" + "\n");
|
52
|
+
|
53
|
+
descriptor.element = dom.getElement();
|
54
|
+
|
55
|
+
return descriptor;
|
56
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<meta charset="utf-8"></meta>
|
4
|
+
<title>Simple</title>
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1"></meta>
|
6
|
+
<style type="text/css">
|
7
|
+
body {
|
8
|
+
background: #eee;
|
9
|
+
color: #999;
|
10
|
+
font-family: Arial, Helvetica, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
#container {
|
14
|
+
margin: 50px auto;
|
15
|
+
width: 480px;
|
16
|
+
padding: 20px;
|
17
|
+
min-height: 700px;
|
18
|
+
background: #fff;
|
19
|
+
}
|
20
|
+
</style>
|
21
|
+
</head>
|
22
|
+
<body>
|
23
|
+
<div id="container">
|
24
|
+
<h1 bob-editable="plaintext" bob-option-singleline="true" class="headline">Hello</h1>
|
25
|
+
|
26
|
+
<div id="content" bob-container>
|
27
|
+
<p>This should be ignored</p>
|
28
|
+
</div>
|
29
|
+
</div>
|
30
|
+
</body>
|
31
|
+
</html>
|
@@ -0,0 +1,66 @@
|
|
1
|
+
function(dom, env) {
|
2
|
+
var descriptor = {
|
3
|
+
"element": null,
|
4
|
+
"editables": [
|
5
|
+
|
6
|
+
]
|
7
|
+
};
|
8
|
+
|
9
|
+
dom.createElement("html");
|
10
|
+
dom.appendTextNode("\n ");
|
11
|
+
dom.createElement("head");
|
12
|
+
dom.appendTextNode("\n ");
|
13
|
+
dom.createElement("meta");
|
14
|
+
dom.setAttribute("charset", "utf-8");
|
15
|
+
dom.appendElement();
|
16
|
+
dom.appendTextNode("\n ");
|
17
|
+
dom.createElement("title");
|
18
|
+
dom.appendTextNode("Simple");
|
19
|
+
dom.appendElement();
|
20
|
+
dom.appendTextNode("\n ");
|
21
|
+
dom.createElement("meta");
|
22
|
+
dom.setAttribute("name", "viewport");
|
23
|
+
dom.setAttribute("content", "width=device-width, initial-scale=1");
|
24
|
+
dom.appendElement();
|
25
|
+
dom.appendTextNode("\n ");
|
26
|
+
dom.createElement("style");
|
27
|
+
dom.setAttribute("type", "text/css");
|
28
|
+
dom.appendTextNode("\n body {\n background: #eee;\n color: #999;\n font-family: Arial, Helvetica, sans-serif;\n }\n\n #container {\n margin: 50px auto;\n width: 480px;\n padding: 20px;\n min-height: 700px;\n background: #fff;\n }\n ");
|
29
|
+
dom.appendElement();
|
30
|
+
dom.appendTextNode("\n ");
|
31
|
+
dom.appendElement();
|
32
|
+
dom.appendTextNode("\n ");
|
33
|
+
dom.createElement("body");
|
34
|
+
dom.appendTextNode("\n ");
|
35
|
+
dom.createElement("div");
|
36
|
+
dom.setAttribute("id", "container");
|
37
|
+
dom.appendTextNode("\n ");
|
38
|
+
dom.createElement("h1");
|
39
|
+
dom.setAttribute("class", "headline");
|
40
|
+
dom.appendTextNode("Hello");
|
41
|
+
descriptor.editables.push({
|
42
|
+
type: "plaintext",
|
43
|
+
name: "plaintext0",
|
44
|
+
element: dom.getElement(),
|
45
|
+
options: {
|
46
|
+
"singleline": true,
|
47
|
+
}
|
48
|
+
});
|
49
|
+
dom.appendElement();
|
50
|
+
dom.appendTextNode("\n\n ");
|
51
|
+
dom.createElement("div");
|
52
|
+
dom.setAttribute("id", "content");
|
53
|
+
descriptor.container = {
|
54
|
+
element: dom.getElement()
|
55
|
+
};
|
56
|
+
dom.appendElement();
|
57
|
+
dom.appendTextNode("\n ");
|
58
|
+
dom.appendElement();
|
59
|
+
dom.appendTextNode("\n ");
|
60
|
+
dom.appendElement();
|
61
|
+
dom.appendTextNode("\n");
|
62
|
+
|
63
|
+
descriptor.element = dom.getElement();
|
64
|
+
|
65
|
+
return descriptor;
|
66
|
+
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8" />
|
5
|
+
<title>Simple</title>
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
7
|
+
<style type="text/css">
|
8
|
+
body {
|
9
|
+
background: #eee;
|
10
|
+
color: #999;
|
11
|
+
font-family: Arial, Helvetica, sans-serif;
|
12
|
+
}
|
13
|
+
|
14
|
+
#container {
|
15
|
+
margin: 50px auto;
|
16
|
+
width: 480px;
|
17
|
+
padding: 20px;
|
18
|
+
min-height: 700px;
|
19
|
+
background: #fff;
|
20
|
+
}
|
21
|
+
</style>
|
22
|
+
</head>
|
23
|
+
<body>
|
24
|
+
<div id="container">
|
25
|
+
<h1 bob-editable="plaintext" bob-option-singleline="true" class="headline">Hello</h1>
|
26
|
+
|
27
|
+
<div id="content" bob-container>
|
28
|
+
<div class="content-block header" bob-block="header">
|
29
|
+
<h1 bob-editable="plaintext" bob-option-singleline="true">Hello</h1>
|
30
|
+
</div>
|
31
|
+
<div class="content-block text" bob-block="text" bob-editable="html">
|
32
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
|
33
|
+
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
|
34
|
+
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
|
35
|
+
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
|
36
|
+
velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
|
37
|
+
occaecat cupidatat non proident, sunt in culpa qui officia deserunt
|
38
|
+
mollit anim id est laborum.
|
39
|
+
</div>
|
40
|
+
<div class="content-block image" bob-block="image">
|
41
|
+
<img
|
42
|
+
bob-editable="image"
|
43
|
+
src="http://placehold.it/480x320"
|
44
|
+
width="480"
|
45
|
+
height="320"
|
46
|
+
title="Placeholder Image"
|
47
|
+
alt="Placholder Image"
|
48
|
+
bob-option-width="480"
|
49
|
+
bob-option-crop="fill"
|
50
|
+
/>
|
51
|
+
</div>
|
52
|
+
</div>
|
53
|
+
</div>
|
54
|
+
</body>
|
55
|
+
</html>
|
@@ -0,0 +1,168 @@
|
|
1
|
+
Bob.registerTemplate("simple", {
|
2
|
+
|
3
|
+
doctype: "<!DOCTYPE html>",
|
4
|
+
|
5
|
+
name: "simple",
|
6
|
+
|
7
|
+
layout: function(dom, env) {
|
8
|
+
var descriptor = {
|
9
|
+
"element": null,
|
10
|
+
"editables": [
|
11
|
+
|
12
|
+
]
|
13
|
+
};
|
14
|
+
|
15
|
+
dom.createElement("html");
|
16
|
+
dom.appendTextNode("\n");
|
17
|
+
dom.createElement("head");
|
18
|
+
dom.appendTextNode("\n ");
|
19
|
+
dom.createElement("meta");
|
20
|
+
dom.setAttribute("charset", "utf-8");
|
21
|
+
dom.appendElement();
|
22
|
+
dom.appendTextNode("\n ");
|
23
|
+
dom.createElement("title");
|
24
|
+
dom.appendTextNode("Simple");
|
25
|
+
dom.appendElement();
|
26
|
+
dom.appendTextNode("\n ");
|
27
|
+
dom.createElement("meta");
|
28
|
+
dom.setAttribute("name", "viewport");
|
29
|
+
dom.setAttribute("content", "width=device-width, initial-scale=1");
|
30
|
+
dom.appendElement();
|
31
|
+
dom.appendTextNode("\n ");
|
32
|
+
dom.createElement("style");
|
33
|
+
dom.setAttribute("type", "text/css");
|
34
|
+
dom.appendTextNode("\n body {\n background: #eee;\n color: #999;\n font-family: Arial, Helvetica, sans-serif;\n }\n\n #container {\n margin: 50px auto;\n width: 480px;\n padding: 20px;\n min-height: 700px;\n background: #fff;\n }\n ");
|
35
|
+
dom.appendElement();
|
36
|
+
dom.appendTextNode("\n");
|
37
|
+
dom.appendElement();
|
38
|
+
dom.appendTextNode("\n");
|
39
|
+
dom.createElement("body");
|
40
|
+
dom.appendTextNode("\n ");
|
41
|
+
dom.createElement("div");
|
42
|
+
dom.setAttribute("id", "container");
|
43
|
+
dom.appendTextNode("\n ");
|
44
|
+
dom.createElement("h1");
|
45
|
+
dom.setAttribute("class", "headline");
|
46
|
+
dom.appendTextNode("Hello");
|
47
|
+
descriptor.editables.push({
|
48
|
+
type: "plaintext",
|
49
|
+
name: "plaintext0",
|
50
|
+
element: dom.getElement(),
|
51
|
+
options: {
|
52
|
+
"singleline": true,
|
53
|
+
}
|
54
|
+
});
|
55
|
+
dom.appendElement();
|
56
|
+
dom.appendTextNode("\n\n ");
|
57
|
+
dom.createElement("div");
|
58
|
+
dom.setAttribute("id", "content");
|
59
|
+
descriptor.container = {
|
60
|
+
element: dom.getElement()
|
61
|
+
};
|
62
|
+
dom.appendElement();
|
63
|
+
dom.appendTextNode("\n ");
|
64
|
+
dom.appendElement();
|
65
|
+
dom.appendTextNode("\n");
|
66
|
+
dom.appendElement();
|
67
|
+
dom.appendTextNode("\n");
|
68
|
+
|
69
|
+
descriptor.element = dom.getElement();
|
70
|
+
|
71
|
+
return descriptor;
|
72
|
+
},
|
73
|
+
|
74
|
+
blocks: {
|
75
|
+
|
76
|
+
"header": function(dom, env) {
|
77
|
+
var descriptor = {
|
78
|
+
"type": "header",
|
79
|
+
"element": null,
|
80
|
+
"editables": [
|
81
|
+
|
82
|
+
]
|
83
|
+
};
|
84
|
+
|
85
|
+
dom.createElement("div");
|
86
|
+
dom.setAttribute("class", "content-block header");
|
87
|
+
dom.appendTextNode("\n ");
|
88
|
+
dom.createElement("h1");
|
89
|
+
dom.appendTextNode("Hello");
|
90
|
+
descriptor.editables.push({
|
91
|
+
type: "plaintext",
|
92
|
+
name: "plaintext0",
|
93
|
+
element: dom.getElement(),
|
94
|
+
options: {
|
95
|
+
"singleline": true,
|
96
|
+
}
|
97
|
+
});
|
98
|
+
dom.appendElement();
|
99
|
+
dom.appendTextNode("\n ");
|
100
|
+
|
101
|
+
descriptor.element = dom.getElement();
|
102
|
+
|
103
|
+
return descriptor;
|
104
|
+
},
|
105
|
+
|
106
|
+
"text": function(dom, env) {
|
107
|
+
var descriptor = {
|
108
|
+
"type": "text",
|
109
|
+
"element": null,
|
110
|
+
"editables": [
|
111
|
+
|
112
|
+
]
|
113
|
+
};
|
114
|
+
|
115
|
+
dom.createElement("div");
|
116
|
+
dom.setAttribute("class", "content-block text");
|
117
|
+
dom.appendTextNode("\n Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod\n tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim\n veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea\n commodo consequat. Duis aute irure dolor in reprehenderit in voluptate\n velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint\n occaecat cupidatat non proident, sunt in culpa qui officia deserunt\n mollit anim id est laborum.\n ");
|
118
|
+
descriptor.editables.push({
|
119
|
+
type: "html",
|
120
|
+
name: "html0",
|
121
|
+
element: dom.getElement(),
|
122
|
+
options: {
|
123
|
+
}
|
124
|
+
});
|
125
|
+
|
126
|
+
descriptor.element = dom.getElement();
|
127
|
+
|
128
|
+
return descriptor;
|
129
|
+
},
|
130
|
+
|
131
|
+
"image": function(dom, env) {
|
132
|
+
var descriptor = {
|
133
|
+
"type": "image",
|
134
|
+
"element": null,
|
135
|
+
"editables": [
|
136
|
+
|
137
|
+
]
|
138
|
+
};
|
139
|
+
|
140
|
+
dom.createElement("div");
|
141
|
+
dom.setAttribute("class", "content-block image");
|
142
|
+
dom.appendTextNode("\n ");
|
143
|
+
dom.createElement("img");
|
144
|
+
dom.setAttribute("src", "http://placehold.it/480x320");
|
145
|
+
dom.setAttribute("width", "480");
|
146
|
+
dom.setAttribute("height", "320");
|
147
|
+
dom.setAttribute("title", "Placeholder Image");
|
148
|
+
dom.setAttribute("alt", "Placholder Image");
|
149
|
+
descriptor.editables.push({
|
150
|
+
type: "image",
|
151
|
+
name: "image0",
|
152
|
+
element: dom.getElement(),
|
153
|
+
options: {
|
154
|
+
"width": 480,
|
155
|
+
"crop": "fill",
|
156
|
+
}
|
157
|
+
});
|
158
|
+
dom.appendElement();
|
159
|
+
dom.appendTextNode("\n ");
|
160
|
+
|
161
|
+
descriptor.element = dom.getElement();
|
162
|
+
|
163
|
+
return descriptor;
|
164
|
+
},
|
165
|
+
|
166
|
+
}
|
167
|
+
|
168
|
+
});
|