arbre 1.0.0 → 1.0.2
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 +4 -2
- data/.travis.yml +1 -2
- data/CHANGELOG.md +13 -0
- data/Gemfile +8 -5
- data/LICENSE +20 -0
- data/README.md +110 -0
- data/Rakefile +11 -0
- data/arbre.gemspec +1 -0
- data/lib/arbre/element.rb +9 -4
- data/lib/arbre/element/proxy.rb +28 -0
- data/lib/arbre/element_collection.rb +1 -1
- data/lib/arbre/html/attributes.rb +11 -2
- data/lib/arbre/html/class_list.rb +7 -0
- data/lib/arbre/html/tag.rb +12 -4
- data/lib/arbre/html/text_node.rb +4 -0
- data/lib/arbre/rails/template_handler.rb +5 -5
- data/lib/arbre/version.rb +1 -1
- data/spec/arbre/integration/html_spec.rb +46 -39
- data/spec/arbre/unit/component_spec.rb +5 -5
- data/spec/arbre/unit/context_spec.rb +8 -8
- data/spec/arbre/unit/element_finder_methods_spec.rb +36 -21
- data/spec/arbre/unit/element_spec.rb +62 -43
- data/spec/arbre/unit/html/class_list_spec.rb +16 -0
- data/spec/arbre/unit/html/tag_attributes_spec.rb +19 -17
- data/spec/arbre/unit/html/tag_spec.rb +23 -16
- data/spec/rails/integration/forms_spec.rb +9 -9
- data/spec/rails/integration/rendering_spec.rb +20 -10
- data/spec/rails/rails_spec_helper.rb +6 -7
- 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
- metadata +27 -17
- data/README.rdoc +0 -71
@@ -9,52 +9,54 @@ describe Arbre::HTML::Tag, "Attributes" do
|
|
9
9
|
before { tag.build :id => "my_id" }
|
10
10
|
|
11
11
|
it "should have an attributes hash" do
|
12
|
-
tag.attributes.
|
12
|
+
expect(tag.attributes).to eq({:id => "my_id"})
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should render the attributes to html" do
|
16
|
-
tag.to_s.
|
17
|
-
|
18
|
-
|
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"
|
19
25
|
end
|
20
26
|
|
21
27
|
it "should get an attribute value" do
|
22
|
-
tag.attr(:id).
|
28
|
+
expect(tag.attr(:id)).to eq("my_id")
|
23
29
|
end
|
24
30
|
|
25
31
|
describe "#has_attribute?" do
|
26
32
|
context "when the attribute exists" do
|
27
33
|
it "should return true" do
|
28
|
-
tag.has_attribute?(:id).
|
34
|
+
expect(tag.has_attribute?(:id)).to eq(true)
|
29
35
|
end
|
30
36
|
end
|
31
37
|
|
32
38
|
context "when the attribute does not exist" do
|
33
39
|
it "should return false" do
|
34
|
-
tag.has_attribute?(:class).
|
40
|
+
expect(tag.has_attribute?(:class)).to eq(false)
|
35
41
|
end
|
36
42
|
end
|
37
43
|
end
|
38
44
|
|
39
45
|
it "should remove an attribute" do
|
40
|
-
tag.attributes.
|
41
|
-
tag.remove_attribute(:id).
|
42
|
-
tag.attributes.
|
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({})
|
43
49
|
end
|
44
50
|
end
|
45
51
|
|
46
52
|
describe "rendering attributes" do
|
47
53
|
it "should html safe the attribute values" do
|
48
|
-
tag.set_attribute(:class, "
|
49
|
-
tag.to_s.
|
50
|
-
<tag class="">bad things!"></tag>
|
51
|
-
HTML
|
54
|
+
tag.set_attribute(:class, '">bad things!')
|
55
|
+
expect(tag.to_s).to eq "<tag class=\"">bad things!\"></tag>\n"
|
52
56
|
end
|
53
57
|
it "should should escape the attribute names" do
|
54
58
|
tag.set_attribute(">bad", "things")
|
55
|
-
tag.to_s.
|
56
|
-
<tag >bad="things"></tag>
|
57
|
-
HTML
|
59
|
+
expect(tag.to_s).to eq "<tag >bad=\"things\"></tag>\n"
|
58
60
|
end
|
59
61
|
end
|
60
62
|
end
|
@@ -8,44 +8,44 @@ describe Arbre::HTML::Tag do
|
|
8
8
|
before { tag.build "Hello World", :id => "my_id" }
|
9
9
|
|
10
10
|
it "should set the contents to a string" do
|
11
|
-
tag.content.
|
11
|
+
expect(tag.content).to eq("Hello World")
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should set the hash of options to the attributes" do
|
15
|
-
tag.attributes.
|
15
|
+
expect(tag.attributes).to eq({ :id => "my_id" })
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
describe "creating a tag 'for' an object" do
|
20
|
-
let(:model_name){
|
21
|
-
let(:resource_class){
|
22
|
-
let(:resource){
|
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
23
|
|
24
24
|
before do
|
25
25
|
tag.build :for => resource
|
26
26
|
end
|
27
27
|
it "should set the id to the type and id" do
|
28
|
-
tag.id.
|
28
|
+
expect(tag.id).to eq("resource_class_5")
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should add a class name" do
|
32
|
-
tag.class_list.
|
32
|
+
expect(tag.class_list).to include("resource_class")
|
33
33
|
end
|
34
34
|
|
35
35
|
|
36
36
|
describe "for an object that doesn't have a model_name" do
|
37
|
-
let(:resource_class){
|
37
|
+
let(:resource_class){ double(:name => 'ResourceClass') }
|
38
38
|
|
39
39
|
before do
|
40
40
|
tag.build :for => resource
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should set the id to the type and id" do
|
44
|
-
tag.id.
|
44
|
+
expect(tag.id).to eq("resource_class_5")
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should add a class name" do
|
48
|
-
tag.class_list.
|
48
|
+
expect(tag.class_list).to include("resource_class")
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -60,7 +60,7 @@ describe Arbre::HTML::Tag do
|
|
60
60
|
end
|
61
61
|
|
62
62
|
it "should set the id to the type and id" do
|
63
|
-
tag.id.
|
63
|
+
expect(tag.id).to eq("a_prefix_resource_class_5")
|
64
64
|
end
|
65
65
|
|
66
66
|
end
|
@@ -70,25 +70,32 @@ describe Arbre::HTML::Tag do
|
|
70
70
|
|
71
71
|
it "should add a class" do
|
72
72
|
tag.add_class "hello_world"
|
73
|
-
tag.class_names.
|
73
|
+
expect(tag.class_names).to eq("hello_world")
|
74
74
|
end
|
75
75
|
|
76
76
|
it "should remove_class" do
|
77
77
|
tag.add_class "hello_world"
|
78
|
-
tag.class_names.
|
78
|
+
expect(tag.class_names).to eq("hello_world")
|
79
79
|
tag.remove_class "hello_world"
|
80
|
-
tag.class_names.
|
80
|
+
expect(tag.class_names).to eq("")
|
81
81
|
end
|
82
82
|
|
83
83
|
it "should not add a class if it already exists" do
|
84
84
|
tag.add_class "hello_world"
|
85
85
|
tag.add_class "hello_world"
|
86
|
-
tag.class_names.
|
86
|
+
expect(tag.class_names).to eq("hello_world")
|
87
87
|
end
|
88
88
|
|
89
89
|
it "should seperate classes with space" do
|
90
90
|
tag.add_class "hello world"
|
91
|
-
tag.class_list.size.
|
91
|
+
expect(tag.class_list.size).to eq(2)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should create a class list from a string" do
|
95
|
+
tag = Arbre::HTML::Tag.new
|
96
|
+
tag.build(:class => "first-class")
|
97
|
+
tag.add_class "second-class"
|
98
|
+
expect(tag.class_list.size).to eq(2)
|
92
99
|
end
|
93
100
|
|
94
101
|
end
|
@@ -18,19 +18,19 @@ describe "Building forms" do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should build a form" do
|
21
|
-
html.
|
21
|
+
expect(html).to have_selector("form")
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should include the hidden authenticity token" do
|
25
|
-
html.
|
25
|
+
expect(html).to include '<input name="authenticity_token" type="hidden" value="AUTH_TOKEN" />'
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should create a label" do
|
29
|
-
html.
|
29
|
+
expect(html).to have_selector("form label[for=mock_person_name]")
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should create a text field" do
|
33
|
-
html.
|
33
|
+
expect(html).to have_selector("form input[type=text]")
|
34
34
|
end
|
35
35
|
|
36
36
|
end
|
@@ -51,15 +51,15 @@ describe "Building forms" do
|
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should render nested label" do
|
54
|
-
html.
|
54
|
+
expect(html).to have_selector("form label[for=mock_person_permission_admin]", :text => "Admin")
|
55
55
|
end
|
56
56
|
|
57
57
|
it "should render nested label" do
|
58
|
-
html.
|
58
|
+
expect(html).to have_selector("form input[type=checkbox][name='mock_person[permission][admin]']")
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should not render a div for the proxy" do
|
62
|
-
html.
|
62
|
+
expect(html).not_to have_selector("form div.fields_for_proxy")
|
63
63
|
end
|
64
64
|
|
65
65
|
end
|
@@ -93,11 +93,11 @@ describe "Building forms" do
|
|
93
93
|
end
|
94
94
|
|
95
95
|
it "should correctly nest elements" do
|
96
|
-
html.
|
96
|
+
expect(html).to have_selector("form > p > label")
|
97
97
|
end
|
98
98
|
|
99
99
|
it "should correnctly nest elements within fields for" do
|
100
|
-
html.
|
100
|
+
expect(html).to have_selector("form > div.permissions > div.permissions_label label")
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
@@ -25,6 +25,11 @@ class TestController < ActionController::Base
|
|
25
25
|
@my_instance_var = "From Instance Var"
|
26
26
|
render "arbre/page_with_assignment"
|
27
27
|
end
|
28
|
+
|
29
|
+
def render_partial_with_instance_variable
|
30
|
+
@my_instance_var = "From Instance Var"
|
31
|
+
render "arbre/page_with_arb_partial_and_assignment"
|
32
|
+
end
|
28
33
|
end
|
29
34
|
|
30
35
|
|
@@ -33,20 +38,20 @@ describe TestController, "Rendering with Arbre", :type => :request do
|
|
33
38
|
|
34
39
|
it "should render the empty template" do
|
35
40
|
get "/test/render_empty"
|
36
|
-
response.
|
41
|
+
expect(response).to be_success
|
37
42
|
end
|
38
43
|
|
39
44
|
it "should render a simple page" do
|
40
45
|
get "/test/render_simple_page"
|
41
|
-
response.
|
42
|
-
body.
|
43
|
-
body.
|
46
|
+
expect(response).to be_success
|
47
|
+
expect(body).to have_selector("h1", :text => "Hello World")
|
48
|
+
expect(body).to have_selector("p", :text => "Hello again!")
|
44
49
|
end
|
45
50
|
|
46
51
|
it "should render an arb partial" do
|
47
52
|
get "/test/render_partial"
|
48
|
-
response.
|
49
|
-
body.
|
53
|
+
expect(response).to be_success
|
54
|
+
expect(body).to eq <<-EOS
|
50
55
|
<h1>Before Partial</h1>
|
51
56
|
<p>Hello from a partial</p>
|
52
57
|
<h2>After Partial</h2>
|
@@ -55,8 +60,8 @@ EOS
|
|
55
60
|
|
56
61
|
it "should render an erb (or other) partial" do
|
57
62
|
get "/test/render_erb_partial"
|
58
|
-
response.
|
59
|
-
body.
|
63
|
+
expect(response).to be_success
|
64
|
+
expect(body).to eq <<-EOS
|
60
65
|
<h1>Before Partial</h1>
|
61
66
|
<p>Hello from an erb partial</p>
|
62
67
|
<h2>After Partial</h2>
|
@@ -65,9 +70,14 @@ EOS
|
|
65
70
|
|
66
71
|
it "should render with instance variables" do
|
67
72
|
get "test/render_with_instance_variable"
|
68
|
-
response.
|
69
|
-
body.
|
73
|
+
expect(response).to be_success
|
74
|
+
expect(body).to have_selector("h1", :text => "From Instance Var")
|
70
75
|
end
|
71
76
|
|
77
|
+
it "should render an arbre partial with assignments" do
|
78
|
+
get "test/render_partial_with_instance_variable"
|
79
|
+
expect(response).to be_success
|
80
|
+
expect(body).to have_selector("p", :text => "Partial: From Instance Var")
|
81
|
+
end
|
72
82
|
|
73
83
|
end
|
@@ -1,15 +1,14 @@
|
|
1
|
-
require '
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
2
3
|
|
3
|
-
require 'capybara/rspec'
|
4
|
-
|
5
|
-
# Combustion
|
6
4
|
require 'combustion'
|
5
|
+
|
7
6
|
Combustion.path = 'spec/rails/stub_app'
|
8
7
|
Combustion.initialize! :action_controller,
|
9
|
-
:action_view
|
10
|
-
:sprockets
|
8
|
+
:action_view
|
11
9
|
|
12
10
|
require 'rspec/rails'
|
11
|
+
require 'capybara/rspec'
|
13
12
|
require 'capybara/rails'
|
14
13
|
|
15
14
|
require 'spec_helper'
|
@@ -20,7 +19,7 @@ require 'rails/support/mock_person'
|
|
20
19
|
require 'arbre/rails'
|
21
20
|
|
22
21
|
Rails.application.routes.draw do
|
23
|
-
|
22
|
+
get 'test/:action', :controller => "test"
|
24
23
|
end
|
25
24
|
|
26
25
|
module AdditionalHelpers
|
@@ -0,0 +1 @@
|
|
1
|
+
para "Partial: #{my_instance_var}"
|
metadata
CHANGED
@@ -1,27 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arbre
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Greg Bell
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-08-20 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activesupport
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 3.0.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.0
|
25
27
|
description: An Object Oriented DOM Tree in Ruby
|
26
28
|
email:
|
27
29
|
- gregdbell@gmail.com
|
@@ -29,11 +31,12 @@ executables: []
|
|
29
31
|
extensions: []
|
30
32
|
extra_rdoc_files: []
|
31
33
|
files:
|
32
|
-
- .gitignore
|
33
|
-
- .travis.yml
|
34
|
+
- ".gitignore"
|
35
|
+
- ".travis.yml"
|
34
36
|
- CHANGELOG.md
|
35
37
|
- Gemfile
|
36
|
-
-
|
38
|
+
- LICENSE
|
39
|
+
- README.md
|
37
40
|
- Rakefile
|
38
41
|
- arbre.gemspec
|
39
42
|
- lib/arbre.rb
|
@@ -41,6 +44,7 @@ files:
|
|
41
44
|
- lib/arbre/context.rb
|
42
45
|
- lib/arbre/element.rb
|
43
46
|
- lib/arbre/element/builder_methods.rb
|
47
|
+
- lib/arbre/element/proxy.rb
|
44
48
|
- lib/arbre/element_collection.rb
|
45
49
|
- lib/arbre/html/attributes.rb
|
46
50
|
- lib/arbre/html/class_list.rb
|
@@ -58,6 +62,7 @@ files:
|
|
58
62
|
- spec/arbre/unit/context_spec.rb
|
59
63
|
- spec/arbre/unit/element_finder_methods_spec.rb
|
60
64
|
- spec/arbre/unit/element_spec.rb
|
65
|
+
- spec/arbre/unit/html/class_list_spec.rb
|
61
66
|
- spec/arbre/unit/html/tag_attributes_spec.rb
|
62
67
|
- spec/arbre/unit/html/tag_spec.rb
|
63
68
|
- spec/arbre/unit/html/text_node_spec.rb
|
@@ -71,7 +76,9 @@ files:
|
|
71
76
|
- spec/rails/stub_app/public/favicon.ico
|
72
77
|
- spec/rails/support/mock_person.rb
|
73
78
|
- spec/rails/templates/arbre/_partial.arb
|
79
|
+
- spec/rails/templates/arbre/_partial_with_assignment.arb
|
74
80
|
- spec/rails/templates/arbre/empty.arb
|
81
|
+
- spec/rails/templates/arbre/page_with_arb_partial_and_assignment.arb
|
75
82
|
- spec/rails/templates/arbre/page_with_assignment.arb
|
76
83
|
- spec/rails/templates/arbre/page_with_erb_partial.arb
|
77
84
|
- spec/rails/templates/arbre/page_with_partial.arb
|
@@ -80,28 +87,28 @@ files:
|
|
80
87
|
- spec/spec_helper.rb
|
81
88
|
- spec/support/bundle.rb
|
82
89
|
homepage: ''
|
83
|
-
licenses:
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
84
93
|
post_install_message:
|
85
94
|
rdoc_options: []
|
86
95
|
require_paths:
|
87
96
|
- lib
|
88
97
|
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
98
|
requirements:
|
91
|
-
- -
|
99
|
+
- - ">="
|
92
100
|
- !ruby/object:Gem::Version
|
93
101
|
version: '0'
|
94
102
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
-
none: false
|
96
103
|
requirements:
|
97
|
-
- -
|
104
|
+
- - ">="
|
98
105
|
- !ruby/object:Gem::Version
|
99
106
|
version: '0'
|
100
107
|
requirements: []
|
101
108
|
rubyforge_project:
|
102
|
-
rubygems_version:
|
109
|
+
rubygems_version: 2.2.2
|
103
110
|
signing_key:
|
104
|
-
specification_version:
|
111
|
+
specification_version: 4
|
105
112
|
summary: An Object Oriented DOM Tree in Ruby
|
106
113
|
test_files:
|
107
114
|
- spec/arbre/integration/html_spec.rb
|
@@ -109,6 +116,7 @@ test_files:
|
|
109
116
|
- spec/arbre/unit/context_spec.rb
|
110
117
|
- spec/arbre/unit/element_finder_methods_spec.rb
|
111
118
|
- spec/arbre/unit/element_spec.rb
|
119
|
+
- spec/arbre/unit/html/class_list_spec.rb
|
112
120
|
- spec/arbre/unit/html/tag_attributes_spec.rb
|
113
121
|
- spec/arbre/unit/html/tag_spec.rb
|
114
122
|
- spec/arbre/unit/html/text_node_spec.rb
|
@@ -122,7 +130,9 @@ test_files:
|
|
122
130
|
- spec/rails/stub_app/public/favicon.ico
|
123
131
|
- spec/rails/support/mock_person.rb
|
124
132
|
- spec/rails/templates/arbre/_partial.arb
|
133
|
+
- spec/rails/templates/arbre/_partial_with_assignment.arb
|
125
134
|
- spec/rails/templates/arbre/empty.arb
|
135
|
+
- spec/rails/templates/arbre/page_with_arb_partial_and_assignment.arb
|
126
136
|
- spec/rails/templates/arbre/page_with_assignment.arb
|
127
137
|
- spec/rails/templates/arbre/page_with_erb_partial.arb
|
128
138
|
- spec/rails/templates/arbre/page_with_partial.arb
|