block-html 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +0 -0
- data/COPYING +18 -0
- data/README.rdoc +1 -0
- data/Rakefile +30 -0
- data/VERSION +1 -0
- data/lib/block-html/form.rb +113 -0
- data/lib/block-html.rb +294 -0
- data/spec/block-html/form_spec.rb +4 -0
- data/spec/block-html_spec.rb +188 -0
- metadata +64 -0
data/CHANGELOG
ADDED
File without changes
|
data/COPYING
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2008-2009 Jun Kikuchi
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to
|
5
|
+
deal in the Software without restriction, including without limitation the
|
6
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
16
|
+
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
= block-html
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec/rake/spectask'
|
3
|
+
|
4
|
+
NAME = 'block-html'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'jeweler'
|
8
|
+
Jeweler::Tasks.new do |s|
|
9
|
+
s.name = NAME
|
10
|
+
s.platform = Gem::Platform::RUBY
|
11
|
+
s.summary = NAME
|
12
|
+
s.description = NAME
|
13
|
+
s.author = "Jun Kikuchi"
|
14
|
+
s.email = "kikuchi@bonnou.com"
|
15
|
+
s.homepage = "http://github.com/JunKikuchi/block-html"
|
16
|
+
s.files = %w(
|
17
|
+
COPYING CHANGELOG README.rdoc Rakefile VERSION
|
18
|
+
) + Dir.glob("{bin,doc,spec,lib}/**/*")
|
19
|
+
s.require_path = "lib"
|
20
|
+
s.has_rdoc = true
|
21
|
+
end
|
22
|
+
rescue LoadError
|
23
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
24
|
+
end
|
25
|
+
|
26
|
+
Spec::Rake::SpecTask.new do |t|
|
27
|
+
#t.spec_opts = ['-c --format specdoc']
|
28
|
+
t.spec_opts = ['-c']
|
29
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
30
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.3
|
@@ -0,0 +1,113 @@
|
|
1
|
+
class BlockHTML
|
2
|
+
class Form < BlockHTML
|
3
|
+
def tag(tag, attrs={}, &block)
|
4
|
+
self << Tag.new(nil, tag, attrs, @env_instance, &block)
|
5
|
+
end
|
6
|
+
|
7
|
+
def form(attrs={}, &block)
|
8
|
+
tag(:form, attrs, &block)
|
9
|
+
end
|
10
|
+
|
11
|
+
class Tag < BlockHTML::Tag
|
12
|
+
def initialize(model, name, attrs={}, env_instance=nil, &block)
|
13
|
+
@model = model
|
14
|
+
super(name, attrs, env_instance, &block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def tag(tag, attrs={}, &block)
|
18
|
+
self << Tag.new(@model, tag, attrs, @env_instance, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def model(model, &block)
|
22
|
+
@model = model
|
23
|
+
block.call(self)
|
24
|
+
@model = nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def errors(name, params={})
|
28
|
+
return if @model.nil? || @model.errors[name].empty?
|
29
|
+
|
30
|
+
tag(:div, params) {
|
31
|
+
@model.errors.on(name).each do |val|
|
32
|
+
tag(:p).text(val)
|
33
|
+
end
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def edit(name, attrs={})
|
38
|
+
self << Element::Input.new(
|
39
|
+
@model,
|
40
|
+
attrs.merge(:name => name, :type => :text)
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
def password(name, attrs={})
|
45
|
+
self << Element::Input.new(
|
46
|
+
@model,
|
47
|
+
attrs.merge(:name => name, :type => :password, :value => nil)
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
%w(file hidden).each do |type|
|
52
|
+
class_eval %Q{
|
53
|
+
def #{type}(name, attrs={})
|
54
|
+
self << Element::Input.new(
|
55
|
+
@model,
|
56
|
+
attrs.merge(:name => name, :type => :#{type})
|
57
|
+
)
|
58
|
+
end
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
%w(submit reset button radio).each do |type|
|
63
|
+
class_eval %Q{
|
64
|
+
def #{type}(name, attrs={})
|
65
|
+
self << Element::Button.new(
|
66
|
+
@model,
|
67
|
+
attrs.merge(:name => name, :type => :#{type})
|
68
|
+
)
|
69
|
+
end
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
def checkbox(name, attrs={})
|
74
|
+
self << Element::Checkbox.new(
|
75
|
+
@model,
|
76
|
+
attrs.merge(:name => name, :type => :checkbox)
|
77
|
+
)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class Element < BlockHTML
|
82
|
+
def initialize(model, attrs)
|
83
|
+
super()
|
84
|
+
@model = model
|
85
|
+
@attrs = attrs
|
86
|
+
@name = @attrs[:name]
|
87
|
+
@id = @attrs[:id] || @name
|
88
|
+
@value = @model ? @model.__send__(@name) : @attrs[:value]
|
89
|
+
end
|
90
|
+
|
91
|
+
class Input < Element
|
92
|
+
def initialize(model, attrs)
|
93
|
+
super(model, attrs)
|
94
|
+
tag(:input, @attrs.merge(:id => @id, :value => @value))
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
class Button < Element
|
99
|
+
def initialize(model, attrs)
|
100
|
+
super(model, attrs)
|
101
|
+
tag(:input, @attrs.merge(:id => @id, :value => @value || @name))
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
class Checkbox < Element
|
106
|
+
def initialize(model, attrs)
|
107
|
+
super(model, attrs)
|
108
|
+
tag(:input, @value ? @attrs.merge(:checked => '') : @attrs)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
data/lib/block-html.rb
ADDED
@@ -0,0 +1,294 @@
|
|
1
|
+
class BlockHTML
|
2
|
+
attr_accessor :parent
|
3
|
+
|
4
|
+
def initialize(env_instance=nil, &block)
|
5
|
+
@parent, @nodes, @env_instance = nil, [], env_instance
|
6
|
+
|
7
|
+
@env_instance && @env_instance.instance_variables.each do |v|
|
8
|
+
self.instance_variable_set(v, @env_instance.instance_variable_get(v))
|
9
|
+
end
|
10
|
+
|
11
|
+
instance_eval(&block) if block_given?
|
12
|
+
end
|
13
|
+
|
14
|
+
def <<(tree)
|
15
|
+
tree.parent = self
|
16
|
+
@nodes << tree
|
17
|
+
tree
|
18
|
+
end
|
19
|
+
|
20
|
+
def path(&block)
|
21
|
+
node = if block_given?
|
22
|
+
block.call(self)
|
23
|
+
else
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
if parent.nil?
|
28
|
+
[node]
|
29
|
+
else
|
30
|
+
parent.path(&block).push(node)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def root
|
35
|
+
path.shift
|
36
|
+
end
|
37
|
+
|
38
|
+
def each(&block)
|
39
|
+
@nodes.each(&block)
|
40
|
+
end
|
41
|
+
|
42
|
+
def empty?
|
43
|
+
@nodes.empty?
|
44
|
+
end
|
45
|
+
|
46
|
+
def xml(attrs={})
|
47
|
+
self << XML.new(attrs)
|
48
|
+
end
|
49
|
+
|
50
|
+
def doctype(attrs={})
|
51
|
+
self << DOCTYPE.new(attrs)
|
52
|
+
end
|
53
|
+
|
54
|
+
def tag(tag, attrs={}, &block)
|
55
|
+
self << Tag.new(tag, attrs, @env_instance, &block)
|
56
|
+
end
|
57
|
+
|
58
|
+
alias :_p :p
|
59
|
+
|
60
|
+
def p(attrs={}, &block)
|
61
|
+
tag('p', attrs, &block)
|
62
|
+
end
|
63
|
+
|
64
|
+
def text(text='')
|
65
|
+
self << Text.new(text)
|
66
|
+
self
|
67
|
+
end
|
68
|
+
|
69
|
+
def escaped_text(text='')
|
70
|
+
self << EscapedText.new(text)
|
71
|
+
self
|
72
|
+
end
|
73
|
+
|
74
|
+
def form(attrs={}, &block)
|
75
|
+
self << Form.new(@env_instance) {
|
76
|
+
form(attrs, &block)
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
def render(renderer)
|
81
|
+
each do |node|
|
82
|
+
node.render(renderer)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def method_missing(tag, attrs={}, &block)
|
87
|
+
tag(tag, attrs, &block)
|
88
|
+
end
|
89
|
+
|
90
|
+
def to_s(indent=0)
|
91
|
+
Renderer.new(self, indent).to_s
|
92
|
+
end
|
93
|
+
|
94
|
+
class Attrs < ::Hash
|
95
|
+
def to_s
|
96
|
+
unless empty?
|
97
|
+
' ' + sort do |a, b|
|
98
|
+
a.to_s <=> b.to_s
|
99
|
+
end.map do |key, val|
|
100
|
+
'%s="%s"' % [key, val]
|
101
|
+
end.join(' ')
|
102
|
+
else
|
103
|
+
''
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
class XML < BlockHTML
|
109
|
+
def initialize(attrs={})
|
110
|
+
super()
|
111
|
+
@attrs = {
|
112
|
+
:version => '1.0',
|
113
|
+
:encoding => 'utf8'
|
114
|
+
}.merge(attrs);
|
115
|
+
end
|
116
|
+
|
117
|
+
def render(renderer)
|
118
|
+
renderer.xml(@attrs)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
class DOCTYPE < BlockHTML
|
123
|
+
def initialize(attrs={})
|
124
|
+
super()
|
125
|
+
@attrs = {
|
126
|
+
:format => 'xhtml',
|
127
|
+
:version => '1.0',
|
128
|
+
:type => 'strict'
|
129
|
+
}.merge(attrs);
|
130
|
+
end
|
131
|
+
|
132
|
+
def render(renderer)
|
133
|
+
renderer.doctype(@attrs)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
class Tag < BlockHTML
|
138
|
+
attr_reader :attrs
|
139
|
+
|
140
|
+
def initialize(name, attrs={}, env_instance=nil, &block)
|
141
|
+
@name = name
|
142
|
+
@attrs = attrs.inject(Attrs.new) do |ret, (key, val)|
|
143
|
+
ret[key] = val
|
144
|
+
ret
|
145
|
+
end
|
146
|
+
super(env_instance, &block)
|
147
|
+
end
|
148
|
+
|
149
|
+
def render(renderer)
|
150
|
+
renderer.tag(self, @name, @attrs)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
class Text < BlockHTML
|
155
|
+
def initialize(text)
|
156
|
+
super()
|
157
|
+
@text = text
|
158
|
+
end
|
159
|
+
|
160
|
+
def render(renderer)
|
161
|
+
renderer.text(@text)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
class EscapedText < Text
|
166
|
+
def render(renderer)
|
167
|
+
renderer.escaped_text(@text)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
class Renderer
|
172
|
+
ESC = {
|
173
|
+
'&' => '&',
|
174
|
+
'"' => '"',
|
175
|
+
"'" => ''',
|
176
|
+
'>' => '>',
|
177
|
+
'<' => '<',
|
178
|
+
#' ' => ' '
|
179
|
+
}
|
180
|
+
|
181
|
+
ESC_STR = ESC.inject('') do |ret, (key, val)|
|
182
|
+
ret << key
|
183
|
+
ret
|
184
|
+
end
|
185
|
+
|
186
|
+
def initialize(html, indent)
|
187
|
+
@html = html
|
188
|
+
@indent = indent.to_i
|
189
|
+
@count = 0
|
190
|
+
@text = 0 < @indent
|
191
|
+
@buf = ''
|
192
|
+
end
|
193
|
+
|
194
|
+
def escape(text)
|
195
|
+
text.to_s.gsub(/[#{ESC_STR}]/) do |val|
|
196
|
+
ESC[val]
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def xml(attrs)
|
201
|
+
@buf << '<?xml version="%s" encoding="%s"?>' % [
|
202
|
+
attrs[:version],
|
203
|
+
attrs[:encoding]
|
204
|
+
]
|
205
|
+
@buf << "\n" if 0 < @indent
|
206
|
+
@text = true
|
207
|
+
end
|
208
|
+
|
209
|
+
def doctype(attrs)
|
210
|
+
case attrs[:format]
|
211
|
+
when 'html5'
|
212
|
+
@buf << '<!DOCTYPE html>'
|
213
|
+
when 'html4'
|
214
|
+
case attrs[:type]
|
215
|
+
when 'strict'
|
216
|
+
@buf << '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
|
217
|
+
when 'frameset'
|
218
|
+
@buf << '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'
|
219
|
+
else
|
220
|
+
@buf << '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'
|
221
|
+
end
|
222
|
+
when 'xhtml'
|
223
|
+
if attrs[:version] == '1.1'
|
224
|
+
@buf << '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'
|
225
|
+
else
|
226
|
+
case attrs[:type]
|
227
|
+
when 'strict'
|
228
|
+
@buf << '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
|
229
|
+
when 'frameset'
|
230
|
+
@buf << '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">'
|
231
|
+
else
|
232
|
+
@buf << '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
@buf << "\n" if 0 < @indent
|
238
|
+
@text = true
|
239
|
+
end
|
240
|
+
|
241
|
+
def tag(node, tag, attrs)
|
242
|
+
space = ' ' * @count * @indent
|
243
|
+
|
244
|
+
if node.empty?
|
245
|
+
if 0 < @indent && !@text
|
246
|
+
@buf << "\n%s<%s%s />" % [space, tag, attrs.to_s]
|
247
|
+
else
|
248
|
+
@buf << '<%s%s />' % [tag, attrs.to_s]
|
249
|
+
end
|
250
|
+
else
|
251
|
+
if 0 < @indent && !@text
|
252
|
+
@buf << "\n"
|
253
|
+
@buf << "%s<%s%s>" % [space, tag, attrs.to_s]
|
254
|
+
else
|
255
|
+
@buf << '<%s%s>' % [tag, attrs.to_s]
|
256
|
+
end
|
257
|
+
@text = false
|
258
|
+
|
259
|
+
@count += 1
|
260
|
+
node.each do |obj|
|
261
|
+
obj.render(self)
|
262
|
+
end
|
263
|
+
@count -= 1
|
264
|
+
|
265
|
+
if 0 < @indent && !@text
|
266
|
+
@buf << "\n"
|
267
|
+
@buf << "%s</%s>" % [space, tag]
|
268
|
+
else
|
269
|
+
@buf << '</%s>' % [tag]
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
@text = false
|
274
|
+
end
|
275
|
+
|
276
|
+
def text(text)
|
277
|
+
@buf << escape(text)
|
278
|
+
@text = true
|
279
|
+
end
|
280
|
+
|
281
|
+
def escaped_text(text)
|
282
|
+
@buf << text
|
283
|
+
@text = true
|
284
|
+
end
|
285
|
+
|
286
|
+
def to_s
|
287
|
+
@buf = ''
|
288
|
+
@html.render(self)
|
289
|
+
@buf
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
autoload :Form, 'block-html/form'
|
294
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
require 'lib/block-html'
|
2
|
+
|
3
|
+
describe BlockHTML do
|
4
|
+
describe 'インターフェース' do
|
5
|
+
before do
|
6
|
+
@bhtml = BlockHTML.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'インスタンス' do
|
10
|
+
%w'parent << path root each empty? xml doctype tag text escaped_text render to_s'.each do |val|
|
11
|
+
@bhtml.should respond_to val.to_sym
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '空の状態' do
|
17
|
+
before do
|
18
|
+
@bhtml = BlockHTML.new
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'parent == nil' do
|
22
|
+
@bhtml.parent.should be_nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'path == []' do
|
26
|
+
@bhtml.path.should == [@bhtml]
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'root == self' do
|
30
|
+
@bhtml.root.should == @bhtml
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'each' do
|
34
|
+
@bhtml.each do |b|
|
35
|
+
b.should == @bhtml
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'empty? == true' do
|
40
|
+
@bhtml.empty?.should be_true
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'to_s == ""' do
|
44
|
+
@bhtml.to_s.should == ''
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'ノードを1つ追加する操作' do
|
49
|
+
before do
|
50
|
+
@bhtml = BlockHTML.new
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'xml' do
|
54
|
+
@bhtml.xml
|
55
|
+
@bhtml.to_s.should == '<?xml version="1.0" encoding="utf8"?>'
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'xml(:version => "1.1", :encoding => "sjis")' do
|
59
|
+
@bhtml.xml :version => '1.1', :encoding => 'sjis'
|
60
|
+
@bhtml.to_s.should == '<?xml version="1.1" encoding="sjis"?>'
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'doctype(:version => "1.1")' do
|
64
|
+
@bhtml.doctype :version => '1.1'
|
65
|
+
@bhtml.to_s.should == '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'doctype' do
|
69
|
+
@bhtml.doctype
|
70
|
+
@bhtml.to_s.should == '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'doctype(:type => "strict")' do
|
74
|
+
@bhtml.doctype :type => 'strict'
|
75
|
+
@bhtml.to_s.should == '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'doctype(:type => "frameset")' do
|
79
|
+
@bhtml.doctype :type => 'frameset'
|
80
|
+
@bhtml.to_s.should =='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">'
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'doctype(:type => nil)' do
|
84
|
+
@bhtml.doctype :type => nil
|
85
|
+
@bhtml.to_s.should =='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'doctype(:format => "html4")' do
|
89
|
+
@bhtml.doctype :format => 'html4'
|
90
|
+
@bhtml.to_s.should == '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'doctype(:format => "html4", :type => "strict")' do
|
94
|
+
@bhtml.doctype :format => 'html4', :type => 'strict'
|
95
|
+
@bhtml.to_s.should == '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'doctype(:format => "html4", :type => "frameset")' do
|
99
|
+
@bhtml.doctype :format => 'html4', :type => 'frameset'
|
100
|
+
@bhtml.to_s.should == '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'doctype(:format => "html4", :type => nil)' do
|
104
|
+
@bhtml.doctype :format => 'html4', :type => nil
|
105
|
+
@bhtml.to_s.should == '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'doctype(:format => "html5")' do
|
109
|
+
@bhtml.doctype :format => 'html5'
|
110
|
+
@bhtml.to_s.should == '<!DOCTYPE html>'
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'tag' do
|
114
|
+
@bhtml.tag 'p'
|
115
|
+
@bhtml.to_s.should == '<p />'
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'tag("a", :href => "/", :id => "abc")' do
|
119
|
+
@bhtml.tag 'a', :href => '/', :id => 'abc'
|
120
|
+
@bhtml.to_s.should == '<a href="/" id="abc" />'
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'text("aaa")' do
|
124
|
+
@bhtml.text 'aaa'
|
125
|
+
@bhtml.to_s.should == 'aaa'
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'text("<a>")' do
|
129
|
+
@bhtml.text '<a>'
|
130
|
+
@bhtml.to_s.should == '<a>'
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'escaped_text("aaa")' do
|
134
|
+
@bhtml.escaped_text 'aaa'
|
135
|
+
@bhtml.to_s.should == 'aaa'
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'escaped_text("<a>")' do
|
139
|
+
@bhtml.escaped_text '<a>'
|
140
|
+
@bhtml.to_s.should == '<a>'
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe 'ノードを幾つか追加する操作' do
|
145
|
+
before do
|
146
|
+
@bhtml = BlockHTML.new(self)
|
147
|
+
end
|
148
|
+
|
149
|
+
it '@bhtml.tag("p").text("aaa")' do
|
150
|
+
@bhtml.tag("p").text("aaa").to_s.should == '<p>aaa</p>'
|
151
|
+
end
|
152
|
+
|
153
|
+
it '@bhtml.tag("p", :id => "abc").text("aaa")' do
|
154
|
+
@bhtml.tag("p", :id => "abc").text("aaa").to_s.should == '<p id="abc">aaa</p>'
|
155
|
+
end
|
156
|
+
|
157
|
+
it '@bhtml.tag("p") { tag("br") }' do
|
158
|
+
@bhtml.tag("p") { tag('br') }.to_s.should == '<p><br /></p>'
|
159
|
+
end
|
160
|
+
|
161
|
+
it '@bhtml.tag("p") { tag("p").text(hello) }' do
|
162
|
+
hello = 'Hello'
|
163
|
+
@bhtml.tag("p") {
|
164
|
+
tag('p').text(hello)
|
165
|
+
}.to_s.should == '<p><p>Hello</p></p>'
|
166
|
+
end
|
167
|
+
|
168
|
+
it '@bhtml.tag("p") { tag("p").text(@hello) }' do
|
169
|
+
@hello = 'Hello'
|
170
|
+
@bhtml.tag("p") {
|
171
|
+
tag('p').text(@hello)
|
172
|
+
}.to_s.should == '<p><p>Hello</p></p>'
|
173
|
+
end
|
174
|
+
|
175
|
+
describe 'インデントを設定' do
|
176
|
+
before do
|
177
|
+
@bhtml = BlockHTML.new
|
178
|
+
end
|
179
|
+
|
180
|
+
it '@bhtml.tag("div") { tag("p") { text("Hello") } }' do
|
181
|
+
@bhtml.tag("div") {
|
182
|
+
tag("p") { text("Hello") }
|
183
|
+
}
|
184
|
+
@bhtml.to_s(2).should == "<div>\n <p>Hello</p>\n</div>"
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: block-html
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jun Kikuchi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-03 00:00:00 +09:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: block-html
|
17
|
+
email: kikuchi@bonnou.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- CHANGELOG
|
26
|
+
- COPYING
|
27
|
+
- README.rdoc
|
28
|
+
- Rakefile
|
29
|
+
- VERSION
|
30
|
+
- lib/block-html.rb
|
31
|
+
- lib/block-html/form.rb
|
32
|
+
- spec/block-html/form_spec.rb
|
33
|
+
- spec/block-html_spec.rb
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://github.com/JunKikuchi/block-html
|
36
|
+
licenses: []
|
37
|
+
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options:
|
40
|
+
- --charset=UTF-8
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.3.5
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: block-html
|
62
|
+
test_files:
|
63
|
+
- spec/block-html/form_spec.rb
|
64
|
+
- spec/block-html_spec.rb
|