arbre 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +1 -1
- data/lib/arbre/context.rb +2 -1
- data/lib/arbre/element.rb +2 -1
- data/lib/arbre/version.rb +1 -1
- metadata +35 -46
- data/.gitignore +0 -10
- data/.rubocop.yml +0 -15
- data/.travis.yml +0 -16
- data/Gemfile +0 -25
- data/Gemfile.lock +0 -224
- data/Rakefile +0 -21
- data/arbre.gemspec +0 -24
- data/spec/arbre/integration/html_spec.rb +0 -249
- 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/changelog_spec.rb +0 -27
- data/spec/rails/integration/forms_spec.rb +0 -105
- data/spec/rails/integration/rendering_spec.rb +0 -99
- data/spec/rails/rails_spec_helper.rb +0 -42
- 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
- data/tasks/lint.rake +0 -69
- data/tasks/release.rake +0 -6
@@ -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
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Arbre::HTML::ClassList do
|
4
|
-
|
5
|
-
describe ".build_from_string" do
|
6
|
-
|
7
|
-
it "should build a new list from a string of classes" do
|
8
|
-
list = Arbre::HTML::ClassList.build_from_string("first second")
|
9
|
-
expect(list.size).to eq(2)
|
10
|
-
|
11
|
-
expect(list).to match_array(%w{first second})
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Arbre::HTML::Tag, "Attributes" do
|
4
|
-
|
5
|
-
let(:tag){ Arbre::HTML::Tag.new }
|
6
|
-
|
7
|
-
describe "attributes" do
|
8
|
-
|
9
|
-
before { tag.build id: "my_id" }
|
10
|
-
|
11
|
-
it "should have an attributes hash" do
|
12
|
-
expect(tag.attributes).to eq({id: "my_id"})
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should render the attributes to html" do
|
16
|
-
expect(tag.to_s).to eq "<tag id=\"my_id\"></tag>\n"
|
17
|
-
end
|
18
|
-
|
19
|
-
it "shouldn't render attributes that are empty" do
|
20
|
-
tag.class_list # initializes an empty ClassList
|
21
|
-
tag.set_attribute :foo, ''
|
22
|
-
tag.set_attribute :bar, nil
|
23
|
-
|
24
|
-
expect(tag.to_s).to eq "<tag id=\"my_id\"></tag>\n"
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should get an attribute value" do
|
28
|
-
expect(tag.attr(:id)).to eq("my_id")
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "#has_attribute?" do
|
32
|
-
context "when the attribute exists" do
|
33
|
-
it "should return true" do
|
34
|
-
expect(tag.has_attribute?(:id)).to eq(true)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context "when the attribute does not exist" do
|
39
|
-
it "should return false" do
|
40
|
-
expect(tag.has_attribute?(:class)).to eq(false)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should remove an attribute" do
|
46
|
-
expect(tag.attributes).to eq({id: "my_id"})
|
47
|
-
expect(tag.remove_attribute(:id)).to eq("my_id")
|
48
|
-
expect(tag.attributes).to eq({})
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "rendering attributes" do
|
53
|
-
it "should html safe the attribute values" do
|
54
|
-
tag.set_attribute(:class, '">bad things!')
|
55
|
-
expect(tag.to_s).to eq "<tag class=\"">bad things!\"></tag>\n"
|
56
|
-
end
|
57
|
-
it "should should escape the attribute names" do
|
58
|
-
tag.set_attribute(">bad", "things")
|
59
|
-
expect(tag.to_s).to eq "<tag >bad=\"things\"></tag>\n"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,115 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Arbre::HTML::Tag do
|
4
|
-
|
5
|
-
let(:tag){ Arbre::HTML::Tag.new }
|
6
|
-
|
7
|
-
describe "building a new tag" do
|
8
|
-
before { tag.build "Hello World", id: "my_id" }
|
9
|
-
|
10
|
-
it "should set the contents to a string" do
|
11
|
-
expect(tag.content).to eq("Hello World")
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should set the hash of options to the attributes" do
|
15
|
-
expect(tag.attributes).to eq({ id: "my_id" })
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "creating a tag 'for' an object" do
|
20
|
-
let(:model_name){ double(singular: "resource_class")}
|
21
|
-
let(:resource_class){ double(model_name: model_name) }
|
22
|
-
let(:resource){ double(class: resource_class, to_key: ['5'])}
|
23
|
-
|
24
|
-
before do
|
25
|
-
tag.build for: resource
|
26
|
-
end
|
27
|
-
it "should set the id to the type and id" do
|
28
|
-
expect(tag.id).to eq("resource_class_5")
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should add a class name" do
|
32
|
-
expect(tag.class_list).to include("resource_class")
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
describe "for an object that doesn't have a model_name" do
|
37
|
-
let(:resource_class){ double(name: 'ResourceClass') }
|
38
|
-
|
39
|
-
before do
|
40
|
-
tag.build for: resource
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should set the id to the type and id" do
|
44
|
-
expect(tag.id).to eq("resource_class_5")
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should add a class name" do
|
48
|
-
expect(tag.class_list).to include("resource_class")
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "with a default_id_for_prefix" do
|
53
|
-
|
54
|
-
let(:tag) do
|
55
|
-
Class.new(Arbre::HTML::Tag) do
|
56
|
-
def default_id_for_prefix
|
57
|
-
"a_prefix"
|
58
|
-
end
|
59
|
-
end.new
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should set the id to the type and id" do
|
63
|
-
expect(tag.id).to eq("a_prefix_resource_class_5")
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe "creating a tag with a for attribute" do
|
70
|
-
it "sets the `for` attribute when a string is given" do
|
71
|
-
tag.build for: "email"
|
72
|
-
expect(tag.attributes[:for]).to eq "email"
|
73
|
-
end
|
74
|
-
|
75
|
-
it "sets the `for` attribute when a symbol is given" do
|
76
|
-
tag.build for: :email
|
77
|
-
expect(tag.attributes[:for]).to eq :email
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe "css class names" do
|
82
|
-
|
83
|
-
it "should add a class" do
|
84
|
-
tag.add_class "hello_world"
|
85
|
-
expect(tag.class_names).to eq("hello_world")
|
86
|
-
end
|
87
|
-
|
88
|
-
it "should remove_class" do
|
89
|
-
tag.add_class "hello_world"
|
90
|
-
expect(tag.class_names).to eq("hello_world")
|
91
|
-
tag.remove_class "hello_world"
|
92
|
-
expect(tag.class_names).to eq("")
|
93
|
-
end
|
94
|
-
|
95
|
-
it "should not add a class if it already exists" do
|
96
|
-
tag.add_class "hello_world"
|
97
|
-
tag.add_class "hello_world"
|
98
|
-
expect(tag.class_names).to eq("hello_world")
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should seperate classes with space" do
|
102
|
-
tag.add_class "hello world"
|
103
|
-
expect(tag.class_list.size).to eq(2)
|
104
|
-
end
|
105
|
-
|
106
|
-
it "should create a class list from a string" do
|
107
|
-
tag = Arbre::HTML::Tag.new
|
108
|
-
tag.build(class: "first-class")
|
109
|
-
tag.add_class "second-class"
|
110
|
-
expect(tag.class_list.size).to eq(2)
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|
114
|
-
|
115
|
-
end
|