JunKikuchi-block-html 0.0.1
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 +114 -0
- data/lib/block-html.rb +294 -0
- data/spec/block-html/form_spec.rb +5 -0
- data/spec/block-html_spec.rb +181 -0
- metadata +62 -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.1
|
@@ -0,0 +1,114 @@
|
|
1
|
+
class BlockHTML
|
2
|
+
def self.normalize_model_name(model)
|
3
|
+
model.class.name.gsub(/::/, '_').downcase
|
4
|
+
end
|
5
|
+
|
6
|
+
def normalize_params(_name, params)
|
7
|
+
if @model.nil?
|
8
|
+
id = params[:id] || _name
|
9
|
+
name = _name
|
10
|
+
else
|
11
|
+
model_name = self.class.normalize_model_name(@model)
|
12
|
+
id = params[:id] || "#{model_name}_#{_name}"
|
13
|
+
name = "#{model_name}[#{_name}]"
|
14
|
+
end
|
15
|
+
|
16
|
+
value = @model[_name.to_sym] unless @model.nil?
|
17
|
+
value ||= params[:value] || params[:default] || nil
|
18
|
+
|
19
|
+
label = params[:label] || _name
|
20
|
+
|
21
|
+
errors = @model.errors[_name.to_sym] unless @model.nil?
|
22
|
+
errors ||= params[:error] || []
|
23
|
+
|
24
|
+
[id, name, value, label, errors]
|
25
|
+
end
|
26
|
+
private :normalize_params
|
27
|
+
|
28
|
+
def error_tag(bhtml, errors)
|
29
|
+
bhtml.tag(:div, :class => :form_error_messages) do |div|
|
30
|
+
errors.each do |error|
|
31
|
+
div.tag(:p, :class => :form_error_message) do |_p|
|
32
|
+
_p.text error
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end unless errors.empty?
|
36
|
+
end
|
37
|
+
private :error_tag
|
38
|
+
|
39
|
+
def form(attrs={}, &block)
|
40
|
+
tag :form, attrs do |form|
|
41
|
+
form.tag :dl, &block
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def for(model, &block)
|
46
|
+
@model = model
|
47
|
+
block.call self
|
48
|
+
@model = nil
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# params[:id]
|
53
|
+
# params[:value]
|
54
|
+
# params[:default]
|
55
|
+
# params[:label]
|
56
|
+
#
|
57
|
+
def edit(_name, params={})
|
58
|
+
id, name, value, label, errors = normalize_params(_name, params)
|
59
|
+
|
60
|
+
tag(:dt).tag(:label, :for => id).text label
|
61
|
+
tag(:dd) do |dd|
|
62
|
+
dd.tag :input,
|
63
|
+
:type => :text,
|
64
|
+
:id => id,
|
65
|
+
:name => name,
|
66
|
+
:value => value
|
67
|
+
error_tag(dd, errors)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def password(_name, params={})
|
72
|
+
id, name, value, label, errors = normalize_params(_name, params)
|
73
|
+
|
74
|
+
tag(:dt).tag(:label, :for => id).text label
|
75
|
+
tag(:dd) do |dd|
|
76
|
+
dd.tag :input,
|
77
|
+
:type => :password,
|
78
|
+
:id => id,
|
79
|
+
:name => name
|
80
|
+
error_tag(dd, errors)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def checkbox(_name, params={})
|
85
|
+
id, name, value, label, errors = normalize_params(_name, params)
|
86
|
+
|
87
|
+
attrs = {
|
88
|
+
:type => 'submit',
|
89
|
+
:id => id,
|
90
|
+
:name => name
|
91
|
+
}
|
92
|
+
attrs[:checked] = '' if value
|
93
|
+
|
94
|
+
tag(:dt).tag(:label, :for => id).text label
|
95
|
+
tag(:dd) do |dd|
|
96
|
+
dd.tag :input, attrs
|
97
|
+
error_tag(dd, errors)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def submit(_name, params={})
|
102
|
+
id, name, value, label, errors = normalize_params(_name, params)
|
103
|
+
|
104
|
+
tag(:dt).text
|
105
|
+
tag(:dd) do |dd|
|
106
|
+
dd.tag :input,
|
107
|
+
:type => :submit,
|
108
|
+
:id => id,
|
109
|
+
:name => name,
|
110
|
+
:value => label || name
|
111
|
+
error_tag(dd, errors)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
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 render(renderer)
|
75
|
+
each do |node|
|
76
|
+
node.render(renderer)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def method_missing(tag, attrs={}, &block)
|
81
|
+
tag(tag, attrs, &block)
|
82
|
+
end
|
83
|
+
|
84
|
+
def to_s(indent=0)
|
85
|
+
Renderer.new(self, indent).to_s
|
86
|
+
end
|
87
|
+
|
88
|
+
class Attrs < ::Hash
|
89
|
+
def to_s
|
90
|
+
unless empty?
|
91
|
+
' ' + sort do |a, b|
|
92
|
+
a.to_s <=> b.to_s
|
93
|
+
end.map do |key, val|
|
94
|
+
'%s="%s"' % [key, val]
|
95
|
+
end.join(' ')
|
96
|
+
else
|
97
|
+
''
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
class XML < BlockHTML
|
103
|
+
def initialize(attrs={})
|
104
|
+
super()
|
105
|
+
@attrs = {
|
106
|
+
:version => '1.0',
|
107
|
+
:encoding => 'utf8'
|
108
|
+
}.merge(attrs);
|
109
|
+
end
|
110
|
+
|
111
|
+
def render(renderer)
|
112
|
+
renderer.xml(@attrs)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
class DOCTYPE < BlockHTML
|
117
|
+
def initialize(attrs={})
|
118
|
+
super()
|
119
|
+
@attrs = {
|
120
|
+
:format => 'xhtml',
|
121
|
+
:version => '1.0',
|
122
|
+
:type => 'strict'
|
123
|
+
}.merge(attrs);
|
124
|
+
end
|
125
|
+
|
126
|
+
def render(renderer)
|
127
|
+
renderer.doctype(@attrs)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
class Tag < BlockHTML
|
132
|
+
attr_reader :attrs
|
133
|
+
|
134
|
+
def initialize(name, attrs={}, env_instance=nil, &block)
|
135
|
+
@name = name
|
136
|
+
@attrs = attrs.inject(Attrs.new) do |ret, (key, val)|
|
137
|
+
ret[key] = val
|
138
|
+
ret
|
139
|
+
end
|
140
|
+
super(env_instance, &block)
|
141
|
+
end
|
142
|
+
|
143
|
+
def [](key)
|
144
|
+
@attrs[key]
|
145
|
+
end
|
146
|
+
|
147
|
+
def []=(key, val)
|
148
|
+
@attrs[key] = val
|
149
|
+
end
|
150
|
+
|
151
|
+
def render(renderer)
|
152
|
+
renderer.tag(self, @name, @attrs)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
class Text < BlockHTML
|
157
|
+
def initialize(text)
|
158
|
+
super()
|
159
|
+
@text = text
|
160
|
+
end
|
161
|
+
|
162
|
+
def render(renderer)
|
163
|
+
renderer.text(@text)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
class EscapedText < Text
|
168
|
+
def render(renderer)
|
169
|
+
renderer.escaped_text(@text)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
class Renderer
|
174
|
+
ESC = {
|
175
|
+
'&' => '&',
|
176
|
+
'"' => '"',
|
177
|
+
"'" => ''',
|
178
|
+
'>' => '>',
|
179
|
+
'<' => '<',
|
180
|
+
#' ' => ' '
|
181
|
+
}
|
182
|
+
|
183
|
+
ESC_STR = ESC.inject('') do |ret, (key, val)|
|
184
|
+
ret << key
|
185
|
+
ret
|
186
|
+
end
|
187
|
+
|
188
|
+
def initialize(html, indent)
|
189
|
+
@html = html
|
190
|
+
@indent = indent.to_i
|
191
|
+
@count = 0
|
192
|
+
@text = 0 < @indent
|
193
|
+
@buf = ''
|
194
|
+
end
|
195
|
+
|
196
|
+
def escape(text)
|
197
|
+
text.to_s.gsub(/[#{ESC_STR}]/) do |val|
|
198
|
+
ESC[val]
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def xml(attrs)
|
203
|
+
@buf << '<?xml version="%s" encoding="%s"?>' % [
|
204
|
+
attrs[:version],
|
205
|
+
attrs[:encoding]
|
206
|
+
]
|
207
|
+
@buf << "\n" if 0 < @indent
|
208
|
+
@text = true
|
209
|
+
end
|
210
|
+
|
211
|
+
def doctype(attrs)
|
212
|
+
case attrs[:format]
|
213
|
+
when 'html5'
|
214
|
+
@buf << '<!DOCTYPE html>'
|
215
|
+
when 'html4'
|
216
|
+
case attrs[:type]
|
217
|
+
when 'strict'
|
218
|
+
@buf << '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
|
219
|
+
when 'frameset'
|
220
|
+
@buf << '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'
|
221
|
+
else
|
222
|
+
@buf << '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'
|
223
|
+
end
|
224
|
+
when 'xhtml'
|
225
|
+
if attrs[:version] == '1.1'
|
226
|
+
@buf << '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'
|
227
|
+
else
|
228
|
+
case attrs[:type]
|
229
|
+
when 'strict'
|
230
|
+
@buf << '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
|
231
|
+
when 'frameset'
|
232
|
+
@buf << '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">'
|
233
|
+
else
|
234
|
+
@buf << '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
@buf << "\n" if 0 < @indent
|
240
|
+
@text = true
|
241
|
+
end
|
242
|
+
|
243
|
+
def tag(node, tag, attrs)
|
244
|
+
space = ' ' * @count * @indent
|
245
|
+
|
246
|
+
if node.empty?
|
247
|
+
if 0 < @indent && !@text
|
248
|
+
@buf << "\n%s<%s%s />" % [space, tag, attrs.to_s]
|
249
|
+
else
|
250
|
+
@buf << '<%s%s />' % [tag, attrs.to_s]
|
251
|
+
end
|
252
|
+
else
|
253
|
+
if 0 < @indent && !@text
|
254
|
+
@buf << "\n"
|
255
|
+
@buf << "%s<%s%s>" % [space, tag, attrs.to_s]
|
256
|
+
else
|
257
|
+
@buf << '<%s%s>' % [tag, attrs.to_s]
|
258
|
+
end
|
259
|
+
@text = false
|
260
|
+
|
261
|
+
@count += 1
|
262
|
+
node.each do |obj|
|
263
|
+
obj.render(self)
|
264
|
+
end
|
265
|
+
@count -= 1
|
266
|
+
|
267
|
+
if 0 < @indent && !@text
|
268
|
+
@buf << "\n"
|
269
|
+
@buf << "%s</%s>" % [space, tag]
|
270
|
+
else
|
271
|
+
@buf << '</%s>' % [tag]
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
@text = false
|
276
|
+
end
|
277
|
+
|
278
|
+
def text(text)
|
279
|
+
@buf << escape(text)
|
280
|
+
@text = true
|
281
|
+
end
|
282
|
+
|
283
|
+
def escaped_text(text)
|
284
|
+
@buf << text
|
285
|
+
@text = true
|
286
|
+
end
|
287
|
+
|
288
|
+
def to_s
|
289
|
+
@buf = ''
|
290
|
+
@html.render(self)
|
291
|
+
@buf
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
@@ -0,0 +1,181 @@
|
|
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
|
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
|
+
describe 'インデントを設定' do
|
169
|
+
before do
|
170
|
+
@bhtml = BlockHTML.new
|
171
|
+
end
|
172
|
+
|
173
|
+
it '@bhtml.tag("div") { tag("p") { text("Hello") } }' do
|
174
|
+
@bhtml.tag("div") {
|
175
|
+
tag("p") { text("Hello") }
|
176
|
+
}
|
177
|
+
@bhtml.to_s(2).should == "<div>\n <p>Hello</p>\n</div>"
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: JunKikuchi-block-html
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jun Kikuchi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-26 00:00:00 -07: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: false
|
35
|
+
homepage: http://github.com/JunKikuchi/block-html
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options:
|
38
|
+
- --charset=UTF-8
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
version:
|
53
|
+
requirements: []
|
54
|
+
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 1.2.0
|
57
|
+
signing_key:
|
58
|
+
specification_version: 3
|
59
|
+
summary: block-html
|
60
|
+
test_files:
|
61
|
+
- spec/block-html/form_spec.rb
|
62
|
+
- spec/block-html_spec.rb
|