arbre 1.0.0.rc4 → 1.2.1
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 +7 -0
- data/.gitignore +6 -3
- data/.rubocop.yml +15 -0
- data/.travis.yml +16 -0
- data/CHANGELOG.md +86 -3
- data/Gemfile +17 -5
- data/Gemfile.lock +224 -0
- data/LICENSE +20 -0
- data/README.md +43 -0
- data/Rakefile +19 -0
- data/arbre.gemspec +3 -0
- data/docs/Gemfile +2 -0
- data/docs/_config.yml +7 -0
- data/docs/_includes/footer.html +8 -0
- data/docs/_includes/google-analytics.html +16 -0
- data/docs/_includes/head.html +7 -0
- data/docs/_includes/toc.html +12 -0
- data/docs/_includes/top-menu.html +8 -0
- data/docs/_layouts/default.html +21 -0
- data/docs/index.md +106 -0
- data/docs/stylesheets/main.css +1152 -0
- data/lib/arbre/context.rb +34 -3
- data/lib/arbre/element/builder_methods.rb +4 -5
- data/lib/arbre/element/proxy.rb +28 -0
- data/lib/arbre/element.rb +12 -6
- data/lib/arbre/element_collection.rb +1 -1
- data/lib/arbre/html/attributes.rb +11 -2
- data/lib/arbre/html/class_list.rb +4 -0
- data/lib/arbre/html/document.rb +1 -1
- data/lib/arbre/html/html5_elements.rb +4 -4
- data/lib/arbre/html/tag.rb +24 -9
- data/lib/arbre/html/text_node.rb +4 -0
- data/lib/arbre/rails/forms.rb +70 -67
- data/lib/arbre/rails/template_handler.rb +7 -5
- data/lib/arbre/version.rb +1 -1
- data/spec/arbre/integration/html_spec.rb +118 -110
- data/spec/arbre/unit/component_spec.rb +9 -9
- data/spec/arbre/unit/context_spec.rb +8 -8
- data/spec/arbre/unit/element_finder_methods_spec.rb +44 -29
- data/spec/arbre/unit/element_spec.rb +64 -45
- data/spec/arbre/unit/html/class_list_spec.rb +16 -0
- data/spec/arbre/unit/html/tag_attributes_spec.rb +20 -18
- data/spec/arbre/unit/html/tag_spec.rb +51 -15
- data/spec/changelog_spec.rb +27 -0
- data/spec/rails/integration/forms_spec.rb +14 -30
- data/spec/rails/integration/rendering_spec.rb +46 -20
- data/spec/rails/rails_spec_helper.rb +8 -11
- data/spec/rails/stub_app/log/.gitignore +1 -1
- data/spec/rails/support/mock_person.rb +15 -0
- data/spec/rails/templates/arbre/_partial_with_assignment.arb +1 -0
- data/spec/rails/templates/arbre/page_with_arb_partial_and_assignment.arb +3 -0
- data/tasks/lint.rake +69 -0
- data/tasks/release.rake +6 -0
- metadata +43 -47
- data/.DS_Store +0 -0
- data/README.rdoc +0 -69
- data/lib/.DS_Store +0 -0
@@ -6,184 +6,192 @@ describe Arbre do
|
|
6
6
|
let(:assigns){ {} }
|
7
7
|
|
8
8
|
it "should render a single element" do
|
9
|
-
arbre {
|
9
|
+
expect(arbre {
|
10
10
|
span "Hello World"
|
11
|
-
}.to_s.
|
11
|
+
}.to_s).to eq("<span>Hello World</span>\n")
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should render a child element" do
|
15
|
-
arbre {
|
15
|
+
expect(arbre {
|
16
16
|
span do
|
17
17
|
span "Hello World"
|
18
18
|
end
|
19
|
-
}.to_s.
|
20
|
-
<span>
|
21
|
-
|
22
|
-
</span>
|
23
|
-
HTML
|
19
|
+
}.to_s).to eq <<~HTML
|
20
|
+
<span>
|
21
|
+
<span>Hello World</span>
|
22
|
+
</span>
|
23
|
+
HTML
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should render an unordered list" do
|
27
|
-
arbre {
|
27
|
+
expect(arbre {
|
28
28
|
ul do
|
29
29
|
li "First"
|
30
30
|
li "Second"
|
31
31
|
li "Third"
|
32
32
|
end
|
33
|
-
}.to_s.
|
34
|
-
<ul>
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
</ul>
|
39
|
-
HTML
|
33
|
+
}.to_s).to eq <<~HTML
|
34
|
+
<ul>
|
35
|
+
<li>First</li>
|
36
|
+
<li>Second</li>
|
37
|
+
<li>Third</li>
|
38
|
+
</ul>
|
39
|
+
HTML
|
40
40
|
end
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
<ul>
|
52
|
-
|
53
|
-
|
54
|
-
</ul>
|
55
|
-
HTML
|
56
|
-
|
57
|
-
|
42
|
+
it "should allow local variables inside the tags" do
|
43
|
+
expect(arbre {
|
44
|
+
first = "First"
|
45
|
+
second = "Second"
|
46
|
+
ul do
|
47
|
+
li first
|
48
|
+
li second
|
49
|
+
end
|
50
|
+
}.to_s).to eq <<~HTML
|
51
|
+
<ul>
|
52
|
+
<li>First</li>
|
53
|
+
<li>Second</li>
|
54
|
+
</ul>
|
55
|
+
HTML
|
56
|
+
end
|
58
57
|
|
59
58
|
it "should add children and nested" do
|
60
|
-
arbre {
|
59
|
+
expect(arbre {
|
61
60
|
div do
|
62
61
|
ul
|
63
62
|
li do
|
64
63
|
li
|
65
64
|
end
|
66
65
|
end
|
67
|
-
}.to_s.
|
68
|
-
<div>
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
</div>
|
74
|
-
HTML
|
66
|
+
}.to_s).to eq <<~HTML
|
67
|
+
<div>
|
68
|
+
<ul></ul>
|
69
|
+
<li>
|
70
|
+
<li></li>
|
71
|
+
</li>
|
72
|
+
</div>
|
73
|
+
HTML
|
75
74
|
end
|
76
75
|
|
77
76
|
|
78
77
|
it "should pass the element in to the block if asked for" do
|
79
|
-
arbre {
|
78
|
+
expect(arbre {
|
80
79
|
div do |d|
|
81
80
|
d.ul do
|
82
81
|
li
|
83
82
|
end
|
84
83
|
end
|
85
|
-
}.to_s.
|
86
|
-
<div>
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
</div>
|
91
|
-
HTML
|
84
|
+
}.to_s).to eq <<~HTML
|
85
|
+
<div>
|
86
|
+
<ul>
|
87
|
+
<li></li>
|
88
|
+
</ul>
|
89
|
+
</div>
|
90
|
+
HTML
|
92
91
|
end
|
93
92
|
|
94
93
|
|
95
94
|
it "should move content tags between parents" do
|
96
|
-
arbre {
|
95
|
+
expect(arbre {
|
97
96
|
div do
|
98
97
|
span(ul(li))
|
99
98
|
end
|
100
|
-
}.to_s.
|
101
|
-
<div>
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
</div>
|
108
|
-
HTML
|
99
|
+
}.to_s).to eq <<~HTML
|
100
|
+
<div>
|
101
|
+
<span>
|
102
|
+
<ul>
|
103
|
+
<li></li>
|
104
|
+
</ul>
|
105
|
+
</span>
|
106
|
+
</div>
|
107
|
+
HTML
|
109
108
|
end
|
110
109
|
|
111
110
|
it "should add content to the parent if the element is passed into block" do
|
112
|
-
arbre {
|
111
|
+
expect(arbre {
|
113
112
|
div do |d|
|
114
113
|
d.id = "my-tag"
|
115
114
|
ul do
|
116
115
|
li
|
117
116
|
end
|
118
117
|
end
|
119
|
-
}.to_s.
|
120
|
-
<div id="my-tag">
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
</div>
|
125
|
-
HTML
|
118
|
+
}.to_s).to eq <<~HTML
|
119
|
+
<div id="my-tag">
|
120
|
+
<ul>
|
121
|
+
<li></li>
|
122
|
+
</ul>
|
123
|
+
</div>
|
124
|
+
HTML
|
126
125
|
end
|
127
126
|
|
128
127
|
it "should have the parent set on it" do
|
128
|
+
list, item = nil
|
129
129
|
arbre {
|
130
|
-
item = nil
|
131
130
|
list = ul do
|
132
131
|
li "Hello"
|
133
132
|
item = li "World"
|
134
133
|
end
|
135
|
-
item.parent.should == list
|
136
134
|
}
|
135
|
+
expect(item.parent).to eq list
|
137
136
|
end
|
138
137
|
|
139
138
|
it "should set a string content return value with no children" do
|
140
|
-
arbre {
|
139
|
+
expect(arbre {
|
141
140
|
li do
|
142
141
|
"Hello World"
|
143
142
|
end
|
144
|
-
}.to_s.
|
145
|
-
<li>Hello World</li>
|
146
|
-
HTML
|
143
|
+
}.to_s).to eq <<~HTML
|
144
|
+
<li>Hello World</li>
|
145
|
+
HTML
|
147
146
|
end
|
148
147
|
|
149
148
|
it "should turn string return values into text nodes" do
|
149
|
+
node = nil
|
150
150
|
arbre {
|
151
151
|
list = li do
|
152
152
|
"Hello World"
|
153
153
|
end
|
154
154
|
node = list.children.first
|
155
|
-
node.class.should == Arbre::HTML::TextNode
|
156
155
|
}
|
156
|
+
expect(node).to be_a Arbre::HTML::TextNode
|
157
157
|
end
|
158
158
|
|
159
159
|
it "should not render blank arrays" do
|
160
|
-
arbre {
|
160
|
+
expect(arbre {
|
161
161
|
tbody do
|
162
162
|
[]
|
163
163
|
end
|
164
|
-
}.to_s.
|
165
|
-
<tbody></tbody>
|
166
|
-
HTML
|
164
|
+
}.to_s).to eq <<~HTML
|
165
|
+
<tbody></tbody>
|
166
|
+
HTML
|
167
167
|
end
|
168
168
|
|
169
169
|
describe "self-closing nodes" do
|
170
170
|
|
171
171
|
it "should not self-close script tags" do
|
172
|
-
arbre {
|
173
|
-
script :
|
174
|
-
}.to_s.
|
172
|
+
expect(arbre {
|
173
|
+
script type: 'text/javascript'
|
174
|
+
}.to_s).to eq("<script type=\"text/javascript\"></script>\n")
|
175
175
|
end
|
176
176
|
|
177
177
|
it "should self-close meta tags" do
|
178
|
-
arbre {
|
179
|
-
meta :
|
180
|
-
}.to_s.
|
178
|
+
expect(arbre {
|
179
|
+
meta content: "text/html; charset=utf-8"
|
180
|
+
}.to_s).to eq("<meta content=\"text/html; charset=utf-8\"/>\n")
|
181
181
|
end
|
182
182
|
|
183
183
|
it "should self-close link tags" do
|
184
|
-
arbre {
|
185
|
-
link :
|
186
|
-
}.to_s.
|
184
|
+
expect(arbre {
|
185
|
+
link rel: "stylesheet"
|
186
|
+
}.to_s).to eq("<link rel=\"stylesheet\"/>\n")
|
187
|
+
end
|
188
|
+
|
189
|
+
Arbre::HTML::Tag::SELF_CLOSING_ELEMENTS.each do |tag|
|
190
|
+
it "should self-close #{tag} tags" do
|
191
|
+
expect(arbre {
|
192
|
+
send(tag)
|
193
|
+
}.to_s).to eq("<#{tag}/>\n")
|
194
|
+
end
|
187
195
|
end
|
188
196
|
|
189
197
|
end
|
@@ -191,49 +199,49 @@ HTML
|
|
191
199
|
describe "html safe" do
|
192
200
|
|
193
201
|
it "should escape the contents" do
|
194
|
-
arbre {
|
202
|
+
expect(arbre {
|
195
203
|
span("<br />")
|
196
|
-
}.to_s.
|
197
|
-
<span><br /></span>
|
198
|
-
HTML
|
204
|
+
}.to_s).to eq <<~HTML
|
205
|
+
<span><br /></span>
|
206
|
+
HTML
|
199
207
|
end
|
200
208
|
|
201
209
|
it "should return html safe strings" do
|
202
|
-
arbre {
|
210
|
+
expect(arbre {
|
203
211
|
span("<br />")
|
204
|
-
}.to_s.
|
212
|
+
}.to_s).to be_html_safe
|
205
213
|
end
|
206
214
|
|
207
215
|
it "should not escape html passed in" do
|
208
|
-
arbre {
|
216
|
+
expect(arbre {
|
209
217
|
span(span("<br />"))
|
210
|
-
}.to_s.
|
211
|
-
<span>
|
212
|
-
|
213
|
-
</span>
|
214
|
-
HTML
|
218
|
+
}.to_s).to eq <<~HTML
|
219
|
+
<span>
|
220
|
+
<span><br /></span>
|
221
|
+
</span>
|
222
|
+
HTML
|
215
223
|
end
|
216
224
|
|
217
225
|
it "should escape string contents when passed in block" do
|
218
|
-
arbre {
|
226
|
+
expect(arbre {
|
219
227
|
span {
|
220
228
|
span {
|
221
229
|
"<br />"
|
222
230
|
}
|
223
231
|
}
|
224
|
-
}.to_s.
|
225
|
-
<span>
|
226
|
-
|
227
|
-
</span>
|
228
|
-
HTML
|
232
|
+
}.to_s).to eq <<~HTML
|
233
|
+
<span>
|
234
|
+
<span><br /></span>
|
235
|
+
</span>
|
236
|
+
HTML
|
229
237
|
end
|
230
238
|
|
231
239
|
it "should escape the contents of attributes" do
|
232
|
-
arbre {
|
233
|
-
span(:
|
234
|
-
}.to_s.
|
235
|
-
<span class="<br />"></span>
|
236
|
-
HTML
|
240
|
+
expect(arbre {
|
241
|
+
span(class: "<br />")
|
242
|
+
}.to_s).to eq <<~HTML
|
243
|
+
<span class="<br />"></span>
|
244
|
+
HTML
|
237
245
|
end
|
238
246
|
|
239
247
|
end
|
@@ -20,25 +20,25 @@ describe Arbre::Component do
|
|
20
20
|
let(:component){ component_class.new }
|
21
21
|
|
22
22
|
it "should be a subclass of an html div" do
|
23
|
-
Arbre::Component.ancestors.
|
23
|
+
expect(Arbre::Component.ancestors).to include(Arbre::HTML::Div)
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should render to a div, even as a subclass" do
|
27
|
-
component.tag_name.
|
27
|
+
expect(component.tag_name).to eq('div')
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should add a class by default" do
|
31
|
-
component.class_list.
|
31
|
+
expect(component.class_list).to include("mock_component")
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should render the object using the builder method name" do
|
35
|
-
comp = arbre {
|
35
|
+
comp = expect(arbre {
|
36
36
|
mock_component
|
37
|
-
}.to_s.
|
38
|
-
<div class="mock_component">
|
39
|
-
|
40
|
-
</div>
|
41
|
-
HTML
|
37
|
+
}.to_s).to eq <<~HTML
|
38
|
+
<div class="mock_component">
|
39
|
+
<h2>Hello World</h2>
|
40
|
+
</div>
|
41
|
+
HTML
|
42
42
|
end
|
43
43
|
|
44
44
|
end
|
@@ -10,26 +10,26 @@ describe Arbre::Context do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should not increment the indent_level" do
|
13
|
-
context.indent_level.
|
13
|
+
expect(context.indent_level).to eq(-1)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should return a bytesize" do
|
17
|
-
context.bytesize.
|
17
|
+
expect(context.bytesize).to eq(25)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should return a length" do
|
21
|
-
context.length.
|
21
|
+
expect(context.length).to eq(25)
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should delegate missing methods to the html string" do
|
25
|
-
context.
|
26
|
-
context.index('<').
|
25
|
+
expect(context).to respond_to(:index)
|
26
|
+
expect(context.index('<')).to eq(0)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should use a cached version of the HTML for method delegation" do
|
30
|
-
context.
|
31
|
-
context.index('<').
|
32
|
-
context.index('<').
|
30
|
+
expect(context).to receive(:to_s).once.and_return("<h1>札幌市北区</h1>")
|
31
|
+
expect(context.index('<')).to eq(0)
|
32
|
+
expect(context.index('<')).to eq(0)
|
33
33
|
end
|
34
34
|
|
35
35
|
end
|
@@ -7,9 +7,9 @@ describe Arbre::Element, "Finder Methods" do
|
|
7
7
|
describe "finding elements by tag name" do
|
8
8
|
|
9
9
|
it "should return 0 when no elements exist" do
|
10
|
-
arbre {
|
10
|
+
expect(arbre {
|
11
11
|
div
|
12
|
-
}.get_elements_by_tag_name("li").size.
|
12
|
+
}.get_elements_by_tag_name("li").size).to eq(0)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should return a child element" do
|
@@ -19,8 +19,8 @@ describe Arbre::Element, "Finder Methods" do
|
|
19
19
|
ul
|
20
20
|
end
|
21
21
|
elements = html.get_elements_by_tag_name("li")
|
22
|
-
elements.size.
|
23
|
-
elements[0].
|
22
|
+
expect(elements.size).to eq(1)
|
23
|
+
expect(elements[0]).to be_instance_of(Arbre::HTML::Li)
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should return multple child elements" do
|
@@ -31,9 +31,9 @@ describe Arbre::Element, "Finder Methods" do
|
|
31
31
|
li
|
32
32
|
end
|
33
33
|
elements = html.get_elements_by_tag_name("li")
|
34
|
-
elements.size.
|
35
|
-
elements[0].
|
36
|
-
elements[1].
|
34
|
+
expect(elements.size).to eq(2)
|
35
|
+
expect(elements[0]).to be_instance_of(Arbre::HTML::Li)
|
36
|
+
expect(elements[1]).to be_instance_of(Arbre::HTML::Li)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should return children's child elements" do
|
@@ -44,10 +44,10 @@ describe Arbre::Element, "Finder Methods" do
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
elements = html.get_elements_by_tag_name("li")
|
47
|
-
elements.size.
|
48
|
-
elements[0].
|
49
|
-
elements[1].
|
50
|
-
elements[1].parent.
|
47
|
+
expect(elements.size).to eq(2)
|
48
|
+
expect(elements[0]).to be_instance_of(Arbre::HTML::Li)
|
49
|
+
expect(elements[1]).to be_instance_of(Arbre::HTML::Li)
|
50
|
+
expect(elements[1].parent).to eq(elements[0])
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -56,46 +56,61 @@ describe Arbre::Element, "Finder Methods" do
|
|
56
56
|
describe "finding an element by a class name" do
|
57
57
|
|
58
58
|
it "should return 0 when no elements exist" do
|
59
|
-
arbre {
|
59
|
+
expect(arbre {
|
60
60
|
div
|
61
|
-
}.get_elements_by_class_name("my_class").size.
|
61
|
+
}.get_elements_by_class_name("my_class").size).to eq(0)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should allow text nodes on tree" do
|
65
|
+
expect(arbre {
|
66
|
+
text_node "text"
|
67
|
+
}.get_elements_by_class_name("my_class").size).to eq(0)
|
62
68
|
end
|
63
69
|
|
64
70
|
it "should return a child element" do
|
65
71
|
html = arbre do
|
66
|
-
div :
|
67
|
-
div :
|
72
|
+
div class: "some_class"
|
73
|
+
div class: "my_class"
|
68
74
|
end
|
69
75
|
elements = html.get_elements_by_class_name("my_class")
|
70
|
-
elements.size.
|
71
|
-
elements[0].
|
76
|
+
expect(elements.size).to eq(1)
|
77
|
+
expect(elements[0]).to be_instance_of(Arbre::HTML::Div)
|
72
78
|
end
|
73
79
|
|
74
80
|
it "should return multple child elements" do
|
75
81
|
html = arbre do
|
76
|
-
div :
|
77
|
-
div :
|
78
|
-
div :
|
82
|
+
div class: "some_class"
|
83
|
+
div class: "my_class"
|
84
|
+
div class: "my_class"
|
79
85
|
end
|
80
86
|
elements = html.get_elements_by_class_name("my_class")
|
81
|
-
elements.size.
|
82
|
-
elements[0].
|
83
|
-
elements[1].
|
87
|
+
expect(elements.size).to eq(2)
|
88
|
+
expect(elements[0]).to be_instance_of(Arbre::HTML::Div)
|
89
|
+
expect(elements[1]).to be_instance_of(Arbre::HTML::Div)
|
84
90
|
end
|
85
91
|
|
86
92
|
it "should return elements that match one of several classes" do
|
87
93
|
html = arbre do
|
88
|
-
div :
|
89
|
-
div :
|
90
|
-
div :
|
94
|
+
div class: "some_class this_class"
|
95
|
+
div class: "some_class"
|
96
|
+
div class: "other_class"
|
91
97
|
|
92
98
|
end
|
93
99
|
elements = html.get_elements_by_class_name("this_class")
|
94
|
-
elements.size.
|
95
|
-
elements[0].
|
100
|
+
expect(elements.size).to eq(1)
|
101
|
+
expect(elements[0]).to be_instance_of(Arbre::HTML::Div)
|
96
102
|
end
|
97
103
|
|
98
|
-
|
104
|
+
it "should return a grandchild element" do
|
105
|
+
html = arbre do
|
106
|
+
div class: "some_class" do
|
107
|
+
div class: "my_class"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
elements = html.get_elements_by_class_name("my_class")
|
111
|
+
expect(elements.size).to eq(1)
|
112
|
+
expect(elements[0]).to be_instance_of(Arbre::HTML::Div)
|
113
|
+
end
|
99
114
|
|
100
115
|
end
|
101
116
|
end
|