arbre 1.1.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +50 -2
- data/README.md +25 -92
- 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 +3 -2
- data/lib/arbre/element.rb +4 -2
- data/lib/arbre/element/builder_methods.rb +4 -5
- data/lib/arbre/rails/template_handler.rb +4 -2
- data/lib/arbre/version.rb +1 -1
- metadata +46 -72
- data/.gitignore +0 -10
- data/.travis.yml +0 -6
- data/Gemfile +0 -18
- data/Rakefile +0 -18
- data/arbre.gemspec +0 -22
- data/spec/arbre/integration/html_spec.rb +0 -250
- data/spec/arbre/unit/component_spec.rb +0 -44
- data/spec/arbre/unit/context_spec.rb +0 -35
- data/spec/arbre/unit/element_finder_methods_spec.rb +0 -116
- data/spec/arbre/unit/element_spec.rb +0 -271
- data/spec/arbre/unit/html/class_list_spec.rb +0 -16
- data/spec/arbre/unit/html/tag_attributes_spec.rb +0 -62
- data/spec/arbre/unit/html/tag_spec.rb +0 -115
- data/spec/arbre/unit/html/text_node_spec.rb +0 -5
- data/spec/rails/integration/forms_spec.rb +0 -105
- data/spec/rails/integration/rendering_spec.rb +0 -83
- data/spec/rails/rails_spec_helper.rb +0 -46
- data/spec/rails/stub_app/config/database.yml +0 -3
- data/spec/rails/stub_app/config/routes.rb +0 -3
- data/spec/rails/stub_app/db/schema.rb +0 -3
- data/spec/rails/stub_app/log/.gitignore +0 -1
- data/spec/rails/stub_app/public/favicon.ico +0 -0
- data/spec/rails/support/mock_person.rb +0 -15
- data/spec/rails/templates/arbre/_partial.arb +0 -1
- data/spec/rails/templates/arbre/_partial_with_assignment.arb +0 -1
- data/spec/rails/templates/arbre/empty.arb +0 -0
- data/spec/rails/templates/arbre/page_with_arb_partial_and_assignment.arb +0 -3
- data/spec/rails/templates/arbre/page_with_assignment.arb +0 -1
- data/spec/rails/templates/arbre/page_with_erb_partial.arb +0 -3
- data/spec/rails/templates/arbre/page_with_partial.arb +0 -3
- data/spec/rails/templates/arbre/simple_page.arb +0 -8
- data/spec/rails/templates/erb/_partial.erb +0 -1
- data/spec/spec_helper.rb +0 -7
- data/spec/support/bundle.rb +0 -4
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
# A mock subclass to play with
|
4
|
-
class MockComponent < Arbre::Component
|
5
|
-
|
6
|
-
builder_method :mock_component
|
7
|
-
|
8
|
-
def build
|
9
|
-
h2 "Hello World"
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
describe Arbre::Component do
|
15
|
-
|
16
|
-
let(:assigns) { {} }
|
17
|
-
let(:helpers) { nil }
|
18
|
-
|
19
|
-
let(:component_class){ MockComponent }
|
20
|
-
let(:component){ component_class.new }
|
21
|
-
|
22
|
-
it "should be a subclass of an html div" do
|
23
|
-
expect(Arbre::Component.ancestors).to include(Arbre::HTML::Div)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should render to a div, even as a subclass" do
|
27
|
-
expect(component.tag_name).to eq('div')
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should add a class by default" do
|
31
|
-
expect(component.class_list).to include("mock_component")
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should render the object using the builder method name" do
|
35
|
-
comp = expect(arbre {
|
36
|
-
mock_component
|
37
|
-
}.to_s).to eq <<-HTML
|
38
|
-
<div class="mock_component">
|
39
|
-
<h2>Hello World</h2>
|
40
|
-
</div>
|
41
|
-
HTML
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Arbre::Context do
|
5
|
-
|
6
|
-
let(:context) do
|
7
|
-
Arbre::Context.new do
|
8
|
-
h1 "札幌市北区" # Add some HTML to the context
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should not increment the indent_level" do
|
13
|
-
expect(context.indent_level).to eq(-1)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should return a bytesize" do
|
17
|
-
expect(context.bytesize).to eq(25)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should return a length" do
|
21
|
-
expect(context.length).to eq(25)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should delegate missing methods to the html string" do
|
25
|
-
expect(context).to respond_to(:index)
|
26
|
-
expect(context.index('<')).to eq(0)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should use a cached version of the HTML for method delegation" do
|
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
|
-
end
|
34
|
-
|
35
|
-
end
|
@@ -1,116 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Arbre::Element, "Finder Methods" do
|
4
|
-
let(:assigns){ {} }
|
5
|
-
let(:helpers){ {} }
|
6
|
-
|
7
|
-
describe "finding elements by tag name" do
|
8
|
-
|
9
|
-
it "should return 0 when no elements exist" do
|
10
|
-
expect(arbre {
|
11
|
-
div
|
12
|
-
}.get_elements_by_tag_name("li").size).to eq(0)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should return a child element" do
|
16
|
-
html = arbre do
|
17
|
-
ul
|
18
|
-
li
|
19
|
-
ul
|
20
|
-
end
|
21
|
-
elements = html.get_elements_by_tag_name("li")
|
22
|
-
expect(elements.size).to eq(1)
|
23
|
-
expect(elements[0]).to be_instance_of(Arbre::HTML::Li)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should return multple child elements" do
|
27
|
-
html = arbre do
|
28
|
-
ul
|
29
|
-
li
|
30
|
-
ul
|
31
|
-
li
|
32
|
-
end
|
33
|
-
elements = html.get_elements_by_tag_name("li")
|
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
|
-
end
|
38
|
-
|
39
|
-
it "should return children's child elements" do
|
40
|
-
html = arbre do
|
41
|
-
ul
|
42
|
-
li do
|
43
|
-
li
|
44
|
-
end
|
45
|
-
end
|
46
|
-
elements = html.get_elements_by_tag_name("li")
|
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
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
#TODO: describe "finding an element by id"
|
55
|
-
|
56
|
-
describe "finding an element by a class name" do
|
57
|
-
|
58
|
-
it "should return 0 when no elements exist" do
|
59
|
-
expect(arbre {
|
60
|
-
div
|
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)
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should return a child element" do
|
71
|
-
html = arbre do
|
72
|
-
div class: "some_class"
|
73
|
-
div class: "my_class"
|
74
|
-
end
|
75
|
-
elements = html.get_elements_by_class_name("my_class")
|
76
|
-
expect(elements.size).to eq(1)
|
77
|
-
expect(elements[0]).to be_instance_of(Arbre::HTML::Div)
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should return multple child elements" do
|
81
|
-
html = arbre do
|
82
|
-
div class: "some_class"
|
83
|
-
div class: "my_class"
|
84
|
-
div class: "my_class"
|
85
|
-
end
|
86
|
-
elements = html.get_elements_by_class_name("my_class")
|
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)
|
90
|
-
end
|
91
|
-
|
92
|
-
it "should return elements that match one of several classes" do
|
93
|
-
html = arbre do
|
94
|
-
div class: "some_class this_class"
|
95
|
-
div class: "some_class"
|
96
|
-
div class: "other_class"
|
97
|
-
|
98
|
-
end
|
99
|
-
elements = html.get_elements_by_class_name("this_class")
|
100
|
-
expect(elements.size).to eq(1)
|
101
|
-
expect(elements[0]).to be_instance_of(Arbre::HTML::Div)
|
102
|
-
end
|
103
|
-
|
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
|
114
|
-
|
115
|
-
end
|
116
|
-
end
|
@@ -1,271 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Arbre::Element do
|
4
|
-
|
5
|
-
let(:element){ Arbre::Element.new }
|
6
|
-
|
7
|
-
context "when initialized" do
|
8
|
-
|
9
|
-
it "should have no children" do
|
10
|
-
expect(element.children).to be_empty
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should have no parent" do
|
14
|
-
expect(element.parent).to be_nil
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should respond to the HTML builder methods" do
|
18
|
-
expect(element).to respond_to(:span)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should have a set of local assigns" do
|
22
|
-
context = Arbre::Context.new hello: "World"
|
23
|
-
element = Arbre::Element.new(context)
|
24
|
-
expect(element.assigns[:hello]).to eq("World")
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should have an empty hash with no local assigns" do
|
28
|
-
expect(element.assigns).to eq({})
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
describe "passing in a helper object" do
|
34
|
-
|
35
|
-
let(:helper) do
|
36
|
-
Class.new do
|
37
|
-
def helper_method
|
38
|
-
"helper method"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
let(:element){ Arbre::Element.new(Arbre::Context.new(nil, helper.new)) }
|
44
|
-
|
45
|
-
it "should call methods on the helper object and return TextNode objects" do
|
46
|
-
expect(element.helper_method).to eq("helper method")
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should raise a NoMethodError if not found" do
|
50
|
-
expect {
|
51
|
-
element.a_method_that_doesnt_exist
|
52
|
-
}.to raise_error(NoMethodError)
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
describe "passing in assigns" do
|
58
|
-
let(:post){ double }
|
59
|
-
let(:assigns){ {post: post} }
|
60
|
-
|
61
|
-
it "should be accessible via a method call" do
|
62
|
-
element = Arbre::Element.new(Arbre::Context.new(assigns))
|
63
|
-
expect(element.post).to eq(post)
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
it "to_a.flatten should not infinitely recurse" do
|
69
|
-
Timeout.timeout(1) do
|
70
|
-
element.to_a.flatten
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe "adding a child" do
|
75
|
-
|
76
|
-
let(:child){ Arbre::Element.new }
|
77
|
-
|
78
|
-
before do
|
79
|
-
element.add_child child
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should add the child to the parent" do
|
83
|
-
expect(element.children.first).to eq(child)
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should set the parent of the child" do
|
87
|
-
expect(child.parent).to eq(element)
|
88
|
-
end
|
89
|
-
|
90
|
-
context "when the child is nil" do
|
91
|
-
|
92
|
-
let(:child){ nil }
|
93
|
-
|
94
|
-
it "should not add the child" do
|
95
|
-
expect(element.children).to be_empty
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
context "when the child is a string" do
|
101
|
-
|
102
|
-
let(:child){ "Hello World" }
|
103
|
-
|
104
|
-
it "should add as a TextNode" do
|
105
|
-
expect(element.children.first).to be_instance_of(Arbre::HTML::TextNode)
|
106
|
-
expect(element.children.first.to_s).to eq("Hello World")
|
107
|
-
end
|
108
|
-
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
describe "setting the content" do
|
113
|
-
|
114
|
-
context "when a string" do
|
115
|
-
|
116
|
-
before do
|
117
|
-
element.add_child "Hello World"
|
118
|
-
element.content = "Goodbye"
|
119
|
-
end
|
120
|
-
|
121
|
-
it "should clear the existing children" do
|
122
|
-
expect(element.children.size).to eq(1)
|
123
|
-
end
|
124
|
-
|
125
|
-
it "should add the string as a child" do
|
126
|
-
expect(element.children.first.to_s).to eq("Goodbye")
|
127
|
-
end
|
128
|
-
|
129
|
-
it "should html escape the string" do
|
130
|
-
string = "Goodbye <br />"
|
131
|
-
element.content = string
|
132
|
-
expect(element.content.to_s).to eq("Goodbye <br />")
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
context "when an element" do
|
137
|
-
let(:content_element){ Arbre::Element.new }
|
138
|
-
|
139
|
-
before do
|
140
|
-
element.content = content_element
|
141
|
-
end
|
142
|
-
|
143
|
-
it "should set the content tag" do
|
144
|
-
expect(element.children.first).to eq(content_element)
|
145
|
-
end
|
146
|
-
|
147
|
-
it "should set the tags parent" do
|
148
|
-
expect(content_element.parent).to eq(element)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
context "when an array of tags" do
|
153
|
-
let(:first){ Arbre::Element.new }
|
154
|
-
let(:second){ Arbre::Element.new }
|
155
|
-
|
156
|
-
before do
|
157
|
-
element.content = [first, second]
|
158
|
-
end
|
159
|
-
|
160
|
-
it "should set the content tag" do
|
161
|
-
expect(element.children.first).to eq(first)
|
162
|
-
end
|
163
|
-
|
164
|
-
it "should set the tags parent" do
|
165
|
-
expect(element.children.first.parent).to eq(element)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
end
|
170
|
-
|
171
|
-
describe "rendering to html" do
|
172
|
-
|
173
|
-
before { @separator = $, }
|
174
|
-
after { $, = @separator }
|
175
|
-
let(:collection){ element + "hello world" }
|
176
|
-
|
177
|
-
it "should render the children collection" do
|
178
|
-
expect(element.children).to receive(:to_s).and_return("content")
|
179
|
-
expect(element.to_s).to eq("content")
|
180
|
-
end
|
181
|
-
|
182
|
-
it "should render collection when is set the default separator" do
|
183
|
-
$, = "_"
|
184
|
-
expect(collection.to_s).to eq("hello world")
|
185
|
-
end
|
186
|
-
|
187
|
-
it "should render collection when is not set the default separator" do
|
188
|
-
expect(collection.to_s).to eq("hello world")
|
189
|
-
end
|
190
|
-
|
191
|
-
end
|
192
|
-
|
193
|
-
describe "adding elements together" do
|
194
|
-
|
195
|
-
context "when both elements are tags" do
|
196
|
-
let(:first){ Arbre::Element.new }
|
197
|
-
let(:second){ Arbre::Element.new }
|
198
|
-
let(:collection){ first + second }
|
199
|
-
|
200
|
-
it "should return an instance of Collection" do
|
201
|
-
expect(collection).to be_an_instance_of(Arbre::ElementCollection)
|
202
|
-
end
|
203
|
-
|
204
|
-
it "should return the elements in the collection" do
|
205
|
-
expect(collection.size).to eq(2)
|
206
|
-
expect(collection.first).to eq(first)
|
207
|
-
expect(collection[1]).to eq(second)
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
context "when the left is a collection and the right is a tag" do
|
212
|
-
let(:first){ Arbre::Element.new }
|
213
|
-
let(:second){ Arbre::Element.new }
|
214
|
-
let(:third){ Arbre::Element.new }
|
215
|
-
let(:collection){ Arbre::ElementCollection.new([first, second]) + third}
|
216
|
-
|
217
|
-
it "should return an instance of Collection" do
|
218
|
-
expect(collection).to be_an_instance_of(Arbre::ElementCollection)
|
219
|
-
end
|
220
|
-
|
221
|
-
it "should return the elements in the collection flattened" do
|
222
|
-
expect(collection.size).to eq(3)
|
223
|
-
expect(collection[0]).to eq(first)
|
224
|
-
expect(collection[1]).to eq(second)
|
225
|
-
expect(collection[2]).to eq(third)
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
context "when the right is a collection and the left is a tag" do
|
230
|
-
let(:first){ Arbre::Element.new }
|
231
|
-
let(:second){ Arbre::Element.new }
|
232
|
-
let(:third){ Arbre::Element.new }
|
233
|
-
let(:collection){ first + Arbre::ElementCollection.new([second,third]) }
|
234
|
-
|
235
|
-
it "should return an instance of Collection" do
|
236
|
-
expect(collection).to be_an_instance_of(Arbre::ElementCollection)
|
237
|
-
end
|
238
|
-
|
239
|
-
it "should return the elements in the collection flattened" do
|
240
|
-
expect(collection.size).to eq(3)
|
241
|
-
expect(collection[0]).to eq(first)
|
242
|
-
expect(collection[1]).to eq(second)
|
243
|
-
expect(collection[2]).to eq(third)
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
context "when the left is a tag and the right is a string" do
|
248
|
-
let(:element){ Arbre::Element.new }
|
249
|
-
let(:collection){ element + "Hello World"}
|
250
|
-
|
251
|
-
it "should return an instance of Collection" do
|
252
|
-
expect(collection).to be_an_instance_of(Arbre::ElementCollection)
|
253
|
-
end
|
254
|
-
|
255
|
-
it "should return the elements in the collection" do
|
256
|
-
expect(collection.size).to eq(2)
|
257
|
-
expect(collection[0]).to eq(element)
|
258
|
-
expect(collection[1]).to be_an_instance_of(Arbre::HTML::TextNode)
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
context "when the left is a string and the right is a tag" do
|
263
|
-
let(:collection){ "hello World" + Arbre::Element.new}
|
264
|
-
|
265
|
-
it "should return a string" do
|
266
|
-
expect(collection.strip.chomp).to eq("hello World")
|
267
|
-
end
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
end
|