arbre 1.0.3 → 1.3.0
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 +5 -5
- data/CHANGELOG.md +51 -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/html/tag.rb +4 -1
- data/lib/arbre/rails/template_handler.rb +4 -2
- data/lib/arbre/version.rb +1 -1
- metadata +46 -73
- data/.gitignore +0 -10
- data/.travis.yml +0 -4
- data/Gemfile +0 -16
- 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 -103
- 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
data/lib/arbre/context.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'arbre/element'
|
2
|
+
require 'ruby2_keywords'
|
2
3
|
|
3
4
|
module Arbre
|
4
5
|
|
@@ -42,7 +43,7 @@ module Arbre
|
|
42
43
|
@_current_arbre_element_buffer = [self]
|
43
44
|
|
44
45
|
super(self)
|
45
|
-
instance_eval
|
46
|
+
instance_eval(&block) if block_given?
|
46
47
|
end
|
47
48
|
|
48
49
|
def arbre_context
|
@@ -74,7 +75,7 @@ module Arbre
|
|
74
75
|
# Webservers treat Arbre::Context as a string. We override
|
75
76
|
# method_missing to delegate to the string representation
|
76
77
|
# of the html.
|
77
|
-
def method_missing(method, *args, &block)
|
78
|
+
ruby2_keywords def method_missing(method, *args, &block)
|
78
79
|
if cached_html.respond_to? method
|
79
80
|
cached_html.send method, *args, &block
|
80
81
|
else
|
data/lib/arbre/element.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
require 'arbre/element/builder_methods'
|
2
2
|
require 'arbre/element/proxy'
|
3
3
|
require 'arbre/element_collection'
|
4
|
+
require 'ruby2_keywords'
|
4
5
|
|
5
6
|
module Arbre
|
6
7
|
|
7
8
|
class Element
|
8
9
|
include BuilderMethods
|
9
10
|
|
10
|
-
|
11
|
+
attr_reader :parent
|
11
12
|
attr_reader :children, :arbre_context
|
12
13
|
|
13
14
|
def initialize(arbre_context = Arbre::Context.new)
|
14
15
|
@arbre_context = arbre_context
|
15
16
|
@children = ElementCollection.new
|
17
|
+
@parent = nil
|
16
18
|
end
|
17
19
|
|
18
20
|
def assigns
|
@@ -171,7 +173,7 @@ module Arbre
|
|
171
173
|
# 3. Call the method on the helper object
|
172
174
|
# 4. Call super
|
173
175
|
#
|
174
|
-
def method_missing(name, *args, &block)
|
176
|
+
ruby2_keywords def method_missing(name, *args, &block)
|
175
177
|
if current_arbre_element.respond_to?(name)
|
176
178
|
current_arbre_element.send name, *args, &block
|
177
179
|
elsif assigns && assigns.has_key?(name)
|
@@ -65,17 +65,16 @@ module Arbre
|
|
65
65
|
# Returns true if the object should be converted into a text node
|
66
66
|
# and appended into the DOM.
|
67
67
|
def appendable_tag?(tag)
|
68
|
-
|
69
|
-
|
70
|
-
# In ruby 1.9, Arraay.new.to_s prints out an empty array ("[]"). In
|
68
|
+
# Array.new.to_s prints out an empty array ("[]"). In
|
71
69
|
# Arbre, we append the return value of blocks to the output, which
|
72
70
|
# can cause empty arrays to show up within the output. To get
|
73
71
|
# around this, we check if the object responds to #empty?
|
74
72
|
if tag.respond_to?(:empty?) && tag.empty?
|
75
|
-
|
73
|
+
false
|
74
|
+
else
|
75
|
+
!tag.is_a?(Arbre::Element) && tag.respond_to?(:to_s)
|
76
76
|
end
|
77
77
|
|
78
|
-
is_appendable
|
79
78
|
end
|
80
79
|
end
|
81
80
|
|
data/lib/arbre/html/tag.rb
CHANGED
@@ -20,7 +20,10 @@ module Arbre
|
|
20
20
|
attributes = extract_arguments(args)
|
21
21
|
self.content = args.first if args.first
|
22
22
|
|
23
|
-
|
23
|
+
for_value = attributes[:for]
|
24
|
+
unless for_value.is_a?(String) || for_value.is_a?(Symbol)
|
25
|
+
set_for_attribute(attributes.delete(:for))
|
26
|
+
end
|
24
27
|
|
25
28
|
attributes.each do |key, value|
|
26
29
|
set_attribute(key, value)
|
@@ -1,10 +1,12 @@
|
|
1
1
|
module Arbre
|
2
2
|
module Rails
|
3
3
|
class TemplateHandler
|
4
|
-
def call(template)
|
4
|
+
def call(template, source = nil)
|
5
|
+
source = template.source unless source
|
6
|
+
|
5
7
|
<<-END
|
6
8
|
Arbre::Context.new(assigns, self) {
|
7
|
-
#{
|
9
|
+
#{source}
|
8
10
|
}.to_s
|
9
11
|
END
|
10
12
|
end
|
data/lib/arbre/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arbre
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Bell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -17,6 +17,9 @@ dependencies:
|
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 3.0.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '6.1'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,21 +27,51 @@ dependencies:
|
|
24
27
|
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: 3.0.0
|
27
|
-
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '6.1'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: ruby2_keywords
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 0.0.2
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '1.0'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 0.0.2
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '1.0'
|
53
|
+
description: Arbre makes it easy to generate HTML directly in Ruby
|
28
54
|
email:
|
29
55
|
- gregdbell@gmail.com
|
30
56
|
executables: []
|
31
57
|
extensions: []
|
32
|
-
extra_rdoc_files:
|
58
|
+
extra_rdoc_files:
|
59
|
+
- CHANGELOG.md
|
60
|
+
- README.md
|
33
61
|
files:
|
34
|
-
- ".gitignore"
|
35
|
-
- ".travis.yml"
|
36
62
|
- CHANGELOG.md
|
37
|
-
- Gemfile
|
38
63
|
- LICENSE
|
39
64
|
- README.md
|
40
|
-
-
|
41
|
-
-
|
65
|
+
- docs/Gemfile
|
66
|
+
- docs/_config.yml
|
67
|
+
- docs/_includes/footer.html
|
68
|
+
- docs/_includes/google-analytics.html
|
69
|
+
- docs/_includes/head.html
|
70
|
+
- docs/_includes/toc.html
|
71
|
+
- docs/_includes/top-menu.html
|
72
|
+
- docs/_layouts/default.html
|
73
|
+
- docs/index.md
|
74
|
+
- docs/stylesheets/main.css
|
42
75
|
- lib/arbre.rb
|
43
76
|
- lib/arbre/component.rb
|
44
77
|
- lib/arbre/context.rb
|
@@ -57,36 +90,7 @@ files:
|
|
57
90
|
- lib/arbre/rails/rendering.rb
|
58
91
|
- lib/arbre/rails/template_handler.rb
|
59
92
|
- lib/arbre/version.rb
|
60
|
-
|
61
|
-
- spec/arbre/unit/component_spec.rb
|
62
|
-
- spec/arbre/unit/context_spec.rb
|
63
|
-
- spec/arbre/unit/element_finder_methods_spec.rb
|
64
|
-
- spec/arbre/unit/element_spec.rb
|
65
|
-
- spec/arbre/unit/html/class_list_spec.rb
|
66
|
-
- spec/arbre/unit/html/tag_attributes_spec.rb
|
67
|
-
- spec/arbre/unit/html/tag_spec.rb
|
68
|
-
- spec/arbre/unit/html/text_node_spec.rb
|
69
|
-
- spec/rails/integration/forms_spec.rb
|
70
|
-
- spec/rails/integration/rendering_spec.rb
|
71
|
-
- spec/rails/rails_spec_helper.rb
|
72
|
-
- spec/rails/stub_app/config/database.yml
|
73
|
-
- spec/rails/stub_app/config/routes.rb
|
74
|
-
- spec/rails/stub_app/db/schema.rb
|
75
|
-
- spec/rails/stub_app/log/.gitignore
|
76
|
-
- spec/rails/stub_app/public/favicon.ico
|
77
|
-
- spec/rails/support/mock_person.rb
|
78
|
-
- spec/rails/templates/arbre/_partial.arb
|
79
|
-
- spec/rails/templates/arbre/_partial_with_assignment.arb
|
80
|
-
- spec/rails/templates/arbre/empty.arb
|
81
|
-
- spec/rails/templates/arbre/page_with_arb_partial_and_assignment.arb
|
82
|
-
- spec/rails/templates/arbre/page_with_assignment.arb
|
83
|
-
- spec/rails/templates/arbre/page_with_erb_partial.arb
|
84
|
-
- spec/rails/templates/arbre/page_with_partial.arb
|
85
|
-
- spec/rails/templates/arbre/simple_page.arb
|
86
|
-
- spec/rails/templates/erb/_partial.erb
|
87
|
-
- spec/spec_helper.rb
|
88
|
-
- spec/support/bundle.rb
|
89
|
-
homepage: ''
|
93
|
+
homepage: https://github.com/activeadmin/arbre
|
90
94
|
licenses:
|
91
95
|
- MIT
|
92
96
|
metadata: {}
|
@@ -98,46 +102,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
98
102
|
requirements:
|
99
103
|
- - ">="
|
100
104
|
- !ruby/object:Gem::Version
|
101
|
-
version: '
|
105
|
+
version: '2.5'
|
102
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
107
|
requirements:
|
104
108
|
- - ">="
|
105
109
|
- !ruby/object:Gem::Version
|
106
110
|
version: '0'
|
107
111
|
requirements: []
|
108
|
-
|
109
|
-
rubygems_version: 2.4.5
|
112
|
+
rubygems_version: 3.2.0.rc.1
|
110
113
|
signing_key:
|
111
114
|
specification_version: 4
|
112
115
|
summary: An Object Oriented DOM Tree in Ruby
|
113
|
-
test_files:
|
114
|
-
- spec/arbre/integration/html_spec.rb
|
115
|
-
- spec/arbre/unit/component_spec.rb
|
116
|
-
- spec/arbre/unit/context_spec.rb
|
117
|
-
- spec/arbre/unit/element_finder_methods_spec.rb
|
118
|
-
- spec/arbre/unit/element_spec.rb
|
119
|
-
- spec/arbre/unit/html/class_list_spec.rb
|
120
|
-
- spec/arbre/unit/html/tag_attributes_spec.rb
|
121
|
-
- spec/arbre/unit/html/tag_spec.rb
|
122
|
-
- spec/arbre/unit/html/text_node_spec.rb
|
123
|
-
- spec/rails/integration/forms_spec.rb
|
124
|
-
- spec/rails/integration/rendering_spec.rb
|
125
|
-
- spec/rails/rails_spec_helper.rb
|
126
|
-
- spec/rails/stub_app/config/database.yml
|
127
|
-
- spec/rails/stub_app/config/routes.rb
|
128
|
-
- spec/rails/stub_app/db/schema.rb
|
129
|
-
- spec/rails/stub_app/log/.gitignore
|
130
|
-
- spec/rails/stub_app/public/favicon.ico
|
131
|
-
- spec/rails/support/mock_person.rb
|
132
|
-
- spec/rails/templates/arbre/_partial.arb
|
133
|
-
- spec/rails/templates/arbre/_partial_with_assignment.arb
|
134
|
-
- spec/rails/templates/arbre/empty.arb
|
135
|
-
- spec/rails/templates/arbre/page_with_arb_partial_and_assignment.arb
|
136
|
-
- spec/rails/templates/arbre/page_with_assignment.arb
|
137
|
-
- spec/rails/templates/arbre/page_with_erb_partial.arb
|
138
|
-
- spec/rails/templates/arbre/page_with_partial.arb
|
139
|
-
- spec/rails/templates/arbre/simple_page.arb
|
140
|
-
- spec/rails/templates/erb/_partial.erb
|
141
|
-
- spec/spec_helper.rb
|
142
|
-
- spec/support/bundle.rb
|
143
|
-
has_rdoc:
|
116
|
+
test_files: []
|
data/.gitignore
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'bundler'
|
2
|
-
Bundler::GemHelper.install_tasks
|
3
|
-
|
4
|
-
require 'rspec/core/rake_task'
|
5
|
-
RSpec::Core::RakeTask.new(:spec)
|
6
|
-
|
7
|
-
task default: :spec
|
8
|
-
|
9
|
-
task :console do
|
10
|
-
require 'irb'
|
11
|
-
require 'irb/completion'
|
12
|
-
|
13
|
-
require 'pry'
|
14
|
-
require 'arbre'
|
15
|
-
|
16
|
-
ARGV.clear
|
17
|
-
IRB.start
|
18
|
-
end
|
data/arbre.gemspec
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "arbre/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = "arbre"
|
7
|
-
s.version = Arbre::VERSION
|
8
|
-
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = ["Greg Bell"]
|
10
|
-
s.email = ["gregdbell@gmail.com"]
|
11
|
-
s.homepage = ""
|
12
|
-
s.summary = %q{An Object Oriented DOM Tree in Ruby}
|
13
|
-
s.description = %q{An Object Oriented DOM Tree in Ruby}
|
14
|
-
s.license = "MIT"
|
15
|
-
|
16
|
-
s.files = `git ls-files`.split("\n")
|
17
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
-
s.require_paths = ["lib"]
|
20
|
-
|
21
|
-
s.add_dependency("activesupport", ">= 3.0.0")
|
22
|
-
end
|
@@ -1,250 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Arbre do
|
4
|
-
|
5
|
-
let(:helpers){ nil }
|
6
|
-
let(:assigns){ {} }
|
7
|
-
|
8
|
-
it "should render a single element" do
|
9
|
-
expect(arbre {
|
10
|
-
span "Hello World"
|
11
|
-
}.to_s).to eq("<span>Hello World</span>\n")
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should render a child element" do
|
15
|
-
expect(arbre {
|
16
|
-
span do
|
17
|
-
span "Hello World"
|
18
|
-
end
|
19
|
-
}.to_s).to eq <<-HTML
|
20
|
-
<span>
|
21
|
-
<span>Hello World</span>
|
22
|
-
</span>
|
23
|
-
HTML
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should render an unordered list" do
|
27
|
-
expect(arbre {
|
28
|
-
ul do
|
29
|
-
li "First"
|
30
|
-
li "Second"
|
31
|
-
li "Third"
|
32
|
-
end
|
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
|
-
end
|
41
|
-
|
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
|
57
|
-
|
58
|
-
|
59
|
-
it "should add children and nested" do
|
60
|
-
expect(arbre {
|
61
|
-
div do
|
62
|
-
ul
|
63
|
-
li do
|
64
|
-
li
|
65
|
-
end
|
66
|
-
end
|
67
|
-
}.to_s).to eq <<-HTML
|
68
|
-
<div>
|
69
|
-
<ul></ul>
|
70
|
-
<li>
|
71
|
-
<li></li>
|
72
|
-
</li>
|
73
|
-
</div>
|
74
|
-
HTML
|
75
|
-
end
|
76
|
-
|
77
|
-
|
78
|
-
it "should pass the element in to the block if asked for" do
|
79
|
-
expect(arbre {
|
80
|
-
div do |d|
|
81
|
-
d.ul do
|
82
|
-
li
|
83
|
-
end
|
84
|
-
end
|
85
|
-
}.to_s).to eq <<-HTML
|
86
|
-
<div>
|
87
|
-
<ul>
|
88
|
-
<li></li>
|
89
|
-
</ul>
|
90
|
-
</div>
|
91
|
-
HTML
|
92
|
-
end
|
93
|
-
|
94
|
-
|
95
|
-
it "should move content tags between parents" do
|
96
|
-
expect(arbre {
|
97
|
-
div do
|
98
|
-
span(ul(li))
|
99
|
-
end
|
100
|
-
}.to_s).to eq <<-HTML
|
101
|
-
<div>
|
102
|
-
<span>
|
103
|
-
<ul>
|
104
|
-
<li></li>
|
105
|
-
</ul>
|
106
|
-
</span>
|
107
|
-
</div>
|
108
|
-
HTML
|
109
|
-
end
|
110
|
-
|
111
|
-
it "should add content to the parent if the element is passed into block" do
|
112
|
-
expect(arbre {
|
113
|
-
div do |d|
|
114
|
-
d.id = "my-tag"
|
115
|
-
ul do
|
116
|
-
li
|
117
|
-
end
|
118
|
-
end
|
119
|
-
}.to_s).to eq <<-HTML
|
120
|
-
<div id="my-tag">
|
121
|
-
<ul>
|
122
|
-
<li></li>
|
123
|
-
</ul>
|
124
|
-
</div>
|
125
|
-
HTML
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should have the parent set on it" do
|
129
|
-
list, item = nil
|
130
|
-
arbre {
|
131
|
-
list = ul do
|
132
|
-
li "Hello"
|
133
|
-
item = li "World"
|
134
|
-
end
|
135
|
-
}
|
136
|
-
expect(item.parent).to eq list
|
137
|
-
end
|
138
|
-
|
139
|
-
it "should set a string content return value with no children" do
|
140
|
-
expect(arbre {
|
141
|
-
li do
|
142
|
-
"Hello World"
|
143
|
-
end
|
144
|
-
}.to_s).to eq <<-HTML
|
145
|
-
<li>Hello World</li>
|
146
|
-
HTML
|
147
|
-
end
|
148
|
-
|
149
|
-
it "should turn string return values into text nodes" do
|
150
|
-
node = nil
|
151
|
-
arbre {
|
152
|
-
list = li do
|
153
|
-
"Hello World"
|
154
|
-
end
|
155
|
-
node = list.children.first
|
156
|
-
}
|
157
|
-
expect(node).to be_a Arbre::HTML::TextNode
|
158
|
-
end
|
159
|
-
|
160
|
-
it "should not render blank arrays" do
|
161
|
-
expect(arbre {
|
162
|
-
tbody do
|
163
|
-
[]
|
164
|
-
end
|
165
|
-
}.to_s).to eq <<-HTML
|
166
|
-
<tbody></tbody>
|
167
|
-
HTML
|
168
|
-
end
|
169
|
-
|
170
|
-
describe "self-closing nodes" do
|
171
|
-
|
172
|
-
it "should not self-close script tags" do
|
173
|
-
expect(arbre {
|
174
|
-
script type: 'text/javascript'
|
175
|
-
}.to_s).to eq("<script type=\"text/javascript\"></script>\n")
|
176
|
-
end
|
177
|
-
|
178
|
-
it "should self-close meta tags" do
|
179
|
-
expect(arbre {
|
180
|
-
meta content: "text/html; charset=utf-8"
|
181
|
-
}.to_s).to eq("<meta content=\"text/html; charset=utf-8\"/>\n")
|
182
|
-
end
|
183
|
-
|
184
|
-
it "should self-close link tags" do
|
185
|
-
expect(arbre {
|
186
|
-
link rel: "stylesheet"
|
187
|
-
}.to_s).to eq("<link rel=\"stylesheet\"/>\n")
|
188
|
-
end
|
189
|
-
|
190
|
-
Arbre::HTML::Tag::SELF_CLOSING_ELEMENTS.each do |tag|
|
191
|
-
it "should self-close #{tag} tags" do
|
192
|
-
expect(arbre {
|
193
|
-
send(tag)
|
194
|
-
}.to_s).to eq("<#{tag}/>\n")
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
end
|
199
|
-
|
200
|
-
describe "html safe" do
|
201
|
-
|
202
|
-
it "should escape the contents" do
|
203
|
-
expect(arbre {
|
204
|
-
span("<br />")
|
205
|
-
}.to_s).to eq <<-HTML
|
206
|
-
<span><br /></span>
|
207
|
-
HTML
|
208
|
-
end
|
209
|
-
|
210
|
-
it "should return html safe strings" do
|
211
|
-
expect(arbre {
|
212
|
-
span("<br />")
|
213
|
-
}.to_s).to be_html_safe
|
214
|
-
end
|
215
|
-
|
216
|
-
it "should not escape html passed in" do
|
217
|
-
expect(arbre {
|
218
|
-
span(span("<br />"))
|
219
|
-
}.to_s).to eq <<-HTML
|
220
|
-
<span>
|
221
|
-
<span><br /></span>
|
222
|
-
</span>
|
223
|
-
HTML
|
224
|
-
end
|
225
|
-
|
226
|
-
it "should escape string contents when passed in block" do
|
227
|
-
expect(arbre {
|
228
|
-
span {
|
229
|
-
span {
|
230
|
-
"<br />"
|
231
|
-
}
|
232
|
-
}
|
233
|
-
}.to_s).to eq <<-HTML
|
234
|
-
<span>
|
235
|
-
<span><br /></span>
|
236
|
-
</span>
|
237
|
-
HTML
|
238
|
-
end
|
239
|
-
|
240
|
-
it "should escape the contents of attributes" do
|
241
|
-
expect(arbre {
|
242
|
-
span(class: "<br />")
|
243
|
-
}.to_s).to eq <<-HTML
|
244
|
-
<span class="<br />"></span>
|
245
|
-
HTML
|
246
|
-
end
|
247
|
-
|
248
|
-
end
|
249
|
-
|
250
|
-
end
|