markaby 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Markaby.gemspec +78 -93
- data/README.rdoc +8 -2
- data/Rakefile +7 -6
- data/VERSION +1 -1
- data/lib/markaby.rb +1 -1
- data/lib/markaby/builder.rb +10 -3
- data/lib/markaby/tags.rb +7 -0
- data/lib/markaby/tilt.rb +2 -36
- data/spec/markaby/{css_proxy_spec.rb → css_proxy_test.rb} +0 -0
- data/spec/markaby/{fragment_spec.rb → fragment_test.rb} +0 -0
- data/spec/markaby/markaby_spec.rb +9 -68
- data/spec/markaby/markaby_test.rb +251 -0
- data/spec/markaby/{rails_spec.rb → rails_test.rb} +1 -1
- data/spec/spec_helper.rb +5 -2
- metadata +34 -69
- data/.gitignore +0 -5
data/Markaby.gemspec
CHANGED
@@ -1,115 +1,100 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{markaby}
|
8
|
-
s.version = "0.7.
|
8
|
+
s.version = "0.7.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = [
|
12
|
-
s.date = %q{
|
11
|
+
s.authors = [%q{_why}, %q{Tim Fletcher}, %q{John Barton}, %q{spox}, %q{smtlaissezfaire}]
|
12
|
+
s.date = %q{2011-08-23}
|
13
13
|
s.description = %q{Tim Fletcher and _why's ruby driven HTML templating system}
|
14
14
|
s.email = %q{scott@railsnewbie.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"README.rdoc"
|
17
17
|
]
|
18
18
|
s.files = [
|
19
|
-
".
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
19
|
+
"CHANGELOG.rdoc",
|
20
|
+
"Markaby.gemspec",
|
21
|
+
"README.rdoc",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"garlic.rb",
|
25
|
+
"init.rb",
|
26
|
+
"lib/markaby.rb",
|
27
|
+
"lib/markaby/builder.rb",
|
28
|
+
"lib/markaby/builder_tags.rb",
|
29
|
+
"lib/markaby/cssproxy.rb",
|
30
|
+
"lib/markaby/kernel_method.rb",
|
31
|
+
"lib/markaby/rails.rb",
|
32
|
+
"lib/markaby/rails/current.rb",
|
33
|
+
"lib/markaby/rails/deprecated.rb",
|
34
|
+
"lib/markaby/rails/rails_builder.rb",
|
35
|
+
"lib/markaby/sinatra.rb",
|
36
|
+
"lib/markaby/tags.rb",
|
37
|
+
"lib/markaby/tilt.rb",
|
38
|
+
"spec/markaby/builder_spec.rb",
|
39
|
+
"spec/markaby/css_proxy_test.rb",
|
40
|
+
"spec/markaby/fragment_test.rb",
|
41
|
+
"spec/markaby/markaby_other_static.mab",
|
42
|
+
"spec/markaby/markaby_spec.rb",
|
43
|
+
"spec/markaby/markaby_test.rb",
|
44
|
+
"spec/markaby/rails/spec_helper.rb",
|
45
|
+
"spec/markaby/rails/views/layouts/layout.mab",
|
46
|
+
"spec/markaby/rails/views/markaby/_a_partial.mab",
|
47
|
+
"spec/markaby/rails/views/markaby/_form_for_with_body_in_erb.erb",
|
48
|
+
"spec/markaby/rails/views/markaby/_partial_child_with_locals.mab",
|
49
|
+
"spec/markaby/rails/views/markaby/access_to_helpers.mab",
|
50
|
+
"spec/markaby/rails/views/markaby/broken.mab",
|
51
|
+
"spec/markaby/rails/views/markaby/commented_out_template.mab",
|
52
|
+
"spec/markaby/rails/views/markaby/correct_template_values.mab",
|
53
|
+
"spec/markaby/rails/views/markaby/double_output.mab",
|
54
|
+
"spec/markaby/rails/views/markaby/form_for.mab",
|
55
|
+
"spec/markaby/rails/views/markaby/form_for_with_fields.mab",
|
56
|
+
"spec/markaby/rails/views/markaby/form_for_with_multiple_fields.mab",
|
57
|
+
"spec/markaby/rails/views/markaby/no_values_passed.mab",
|
58
|
+
"spec/markaby/rails/views/markaby/partial_parent.mab",
|
59
|
+
"spec/markaby/rails/views/markaby/partial_parent_with_locals.mab",
|
60
|
+
"spec/markaby/rails/views/markaby/render_erb_without_explicit_render_call.erb",
|
61
|
+
"spec/markaby/rails/views/markaby/render_explicit_but_empty_markaby_layout.mab",
|
62
|
+
"spec/markaby/rails/views/markaby/render_mab_without_explicit_render_call.mab",
|
63
|
+
"spec/markaby/rails/views/markaby/render_with_ivar.mab",
|
64
|
+
"spec/markaby/rails/views/markaby/renders_erb.rhtml",
|
65
|
+
"spec/markaby/rails/views/markaby/renders_form_for_with_erb_body.mab",
|
66
|
+
"spec/markaby/rails/views/markaby/routes.mab",
|
67
|
+
"spec/markaby/rails/views/markaby/yielding.mab",
|
68
|
+
"spec/markaby/rails/views/markaby/yielding_content_for_with_block_helper.mab",
|
69
|
+
"spec/markaby/rails/views/markaby/yielding_two.mab",
|
70
|
+
"spec/markaby/rails/views/markaby/yielding_with_content_for.mab",
|
71
|
+
"spec/markaby/rails_test.rb",
|
72
|
+
"spec/markaby/rails_version_spec.rb",
|
73
|
+
"spec/markaby/sinatra/app.rb",
|
74
|
+
"spec/markaby/sinatra/sinatra_spec.rb",
|
75
|
+
"spec/markaby/sinatra/views/helpers.mab",
|
76
|
+
"spec/markaby/sinatra/views/layout.mab",
|
77
|
+
"spec/markaby/sinatra/views/markaby_template.mab",
|
78
|
+
"spec/markaby/sinatra/views/scope_instance_variables.mab",
|
79
|
+
"spec/markaby/sinatra/views/simple_html.mab",
|
80
|
+
"spec/markaby/sinatra/views/variables.mab",
|
81
|
+
"spec/markaby/tilt/erb.erb",
|
82
|
+
"spec/markaby/tilt/locals.mab",
|
83
|
+
"spec/markaby/tilt/markaby.mab",
|
84
|
+
"spec/markaby/tilt/markaby_other_static.mab",
|
85
|
+
"spec/markaby/tilt/render_twice.mab",
|
86
|
+
"spec/markaby/tilt/scope.mab",
|
87
|
+
"spec/markaby/tilt/yielding.mab",
|
88
|
+
"spec/markaby/tilt_spec.rb",
|
89
|
+
"spec/spec.opts",
|
90
|
+
"spec/spec_helper.rb"
|
91
91
|
]
|
92
92
|
s.homepage = %q{http://markaby.github.com/markaby/}
|
93
|
-
s.
|
94
|
-
s.
|
95
|
-
s.rubygems_version = %q{1.3.7}
|
93
|
+
s.require_paths = [%q{lib}]
|
94
|
+
s.rubygems_version = %q{1.8.6}
|
96
95
|
s.summary = %q{Markup as Ruby, write HTML in your native Ruby tongue}
|
97
|
-
s.test_files = [
|
98
|
-
"spec/markaby/builder_spec.rb",
|
99
|
-
"spec/markaby/css_proxy_spec.rb",
|
100
|
-
"spec/markaby/fragment_spec.rb",
|
101
|
-
"spec/markaby/markaby_spec.rb",
|
102
|
-
"spec/markaby/rails/spec_helper.rb",
|
103
|
-
"spec/markaby/rails_spec.rb",
|
104
|
-
"spec/markaby/rails_version_spec.rb",
|
105
|
-
"spec/markaby/sinatra/app.rb",
|
106
|
-
"spec/markaby/sinatra/sinatra_spec.rb",
|
107
|
-
"spec/markaby/tilt_spec.rb",
|
108
|
-
"spec/spec_helper.rb"
|
109
|
-
]
|
110
96
|
|
111
97
|
if s.respond_to? :specification_version then
|
112
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
113
98
|
s.specification_version = 3
|
114
99
|
|
115
100
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
data/README.rdoc
CHANGED
@@ -72,8 +72,10 @@ If you are looking for sinatra support pre 0.7, see http://github.com/sbfaulkner
|
|
72
72
|
|
73
73
|
== Using Markaby with other frameworks
|
74
74
|
|
75
|
-
|
76
|
-
Tilt
|
75
|
+
Tilt has a Markaby module, so in principle, any web framework that supports
|
76
|
+
Tilt will also support Markaby. See the appropriate tilt documentation:
|
77
|
+
|
78
|
+
http://github.com/rtomayko/tilt
|
77
79
|
|
78
80
|
|
79
81
|
== Using Markaby as a Ruby class
|
@@ -309,3 +311,7 @@ Thankyou for giving it a whirl.
|
|
309
311
|
Markaby is inspired by the HTML library within cgi.rb. Hopefully it will
|
310
312
|
turn around and take some cues.
|
311
313
|
|
314
|
+
== Patches from contributors:
|
315
|
+
|
316
|
+
aredridel (Aria Stewart - aredridel@nbtsc.org)
|
317
|
+
- Make exceptions inherit from StandardError (f259c0)
|
data/Rakefile
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rake'
|
2
|
-
require '
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'rake/testtask'
|
3
4
|
require 'rake/clean'
|
4
5
|
|
5
6
|
begin
|
@@ -14,14 +15,14 @@ rescue LoadError
|
|
14
15
|
puts "Could not load hanna-rdoc. Please install with mislav-hanna package"
|
15
16
|
end
|
16
17
|
|
17
|
-
task :default => :spec
|
18
|
+
task :default => [:spec, :test]
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
t.warning = false
|
22
|
-
t.spec_opts = ["--color"]
|
20
|
+
Rake::TestTask.new(:test) do |t|
|
21
|
+
t.pattern = 'spec/markaby/*_test.rb'
|
23
22
|
end
|
24
23
|
|
24
|
+
RSpec::Core::RakeTask.new(:spec)
|
25
|
+
|
25
26
|
begin
|
26
27
|
require 'jeweler'
|
27
28
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.2
|
data/lib/markaby.rb
CHANGED
@@ -22,7 +22,7 @@ module Markaby
|
|
22
22
|
version_file = File.expand_path(File.dirname(__FILE__) + "/../VERSION")
|
23
23
|
VERSION = File.read(version_file).strip
|
24
24
|
|
25
|
-
class InvalidXhtmlError <
|
25
|
+
class InvalidXhtmlError < StandardError; end
|
26
26
|
end
|
27
27
|
|
28
28
|
require 'builder' unless defined?(Builder)
|
data/lib/markaby/builder.rb
CHANGED
@@ -178,6 +178,13 @@ module Markaby
|
|
178
178
|
raise InvalidXhtmlError, "id `#{ele_id}' already used (id's must be unique)."
|
179
179
|
end
|
180
180
|
end
|
181
|
+
if AttrsBoolean.include? atname
|
182
|
+
if v
|
183
|
+
attrs[k] = atname.to_s
|
184
|
+
else
|
185
|
+
attrs.delete k
|
186
|
+
end
|
187
|
+
end
|
181
188
|
end
|
182
189
|
end
|
183
190
|
end
|
@@ -187,7 +194,7 @@ module Markaby
|
|
187
194
|
block = proc { text(str) }
|
188
195
|
end
|
189
196
|
|
190
|
-
f = fragment { @builder.
|
197
|
+
f = fragment { @builder.tag!(tag, *args, &block) }
|
191
198
|
@used_ids[ele_id] = f if ele_id
|
192
199
|
f
|
193
200
|
end
|
@@ -276,8 +283,8 @@ module Markaby
|
|
276
283
|
@transformed_stream = false
|
277
284
|
end
|
278
285
|
|
279
|
-
|
280
|
-
undef_method
|
286
|
+
[:to_s, :inspect, :==].each do |method|
|
287
|
+
undef_method method if method_defined?(method)
|
281
288
|
end
|
282
289
|
|
283
290
|
private
|
data/lib/markaby/tags.rb
CHANGED
@@ -19,6 +19,13 @@ module Markaby
|
|
19
19
|
AttrHAlign = [:align, :char, :charoff]
|
20
20
|
AttrVAlign = [:valign]
|
21
21
|
Attrs = AttrCore + AttrI18n + AttrEvents
|
22
|
+
|
23
|
+
AttrsBoolean = [
|
24
|
+
:checked, :disabled, :multiple, :readonly, :selected, # standard forms
|
25
|
+
:autofocus, :required, :novalidate, :formnovalidate, # HTML5 forms
|
26
|
+
:defer, :ismap, # <script defer>, <img ismap>
|
27
|
+
:compact, :declare, :noresize, :noshade, :nowrap # deprecated or unused
|
28
|
+
]
|
22
29
|
|
23
30
|
# All the tags and attributes from XHTML 1.0 Strict
|
24
31
|
class XHTMLStrict
|
data/lib/markaby/tilt.rb
CHANGED
@@ -3,40 +3,6 @@ require 'tilt'
|
|
3
3
|
|
4
4
|
module Markaby
|
5
5
|
module Tilt
|
6
|
-
|
7
|
-
class TiltBuilder < Markaby::Builder
|
8
|
-
def __capture_markaby_tilt__(&block)
|
9
|
-
__run_markaby_tilt__ do
|
10
|
-
text capture(&block)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def evaluate(scope, locals, &block)
|
16
|
-
builder = TiltBuilder.new({}, scope)
|
17
|
-
builder.locals = locals
|
18
|
-
|
19
|
-
if block
|
20
|
-
builder.instance_eval <<-CODE, __FILE__, __LINE__
|
21
|
-
def __run_markaby_tilt__
|
22
|
-
#{data}
|
23
|
-
end
|
24
|
-
CODE
|
25
|
-
|
26
|
-
builder.__capture_markaby_tilt__(&block)
|
27
|
-
else
|
28
|
-
builder.instance_eval(data, __FILE__, __LINE__)
|
29
|
-
end
|
30
|
-
|
31
|
-
builder.to_s
|
32
|
-
end
|
33
|
-
|
34
|
-
def prepare; end
|
35
|
-
end
|
6
|
+
Template = ::Tilt::MarkabyTemplate
|
36
7
|
end
|
37
|
-
end
|
38
|
-
|
39
|
-
module Tilt
|
40
|
-
MarkabyTemplate = Markaby::Tilt::Template
|
41
|
-
register :mab, MarkabyTemplate
|
42
|
-
end
|
8
|
+
end
|
File without changes
|
File without changes
|
@@ -1,78 +1,12 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
2
|
|
3
|
-
|
4
|
-
def teardown
|
5
|
-
Markaby::Builder.restore_defaults!
|
6
|
-
end
|
7
|
-
|
8
|
-
def test_simple
|
9
|
-
assert_equal "<hr/>", mab { hr }
|
10
|
-
assert_equal "<hr/><br/>", mab { hr; br }
|
11
|
-
assert_equal "<p>foo</p>", mab { p 'foo' }
|
12
|
-
assert_equal "<p>foo</p>", mab { p { 'foo' } }
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_classes_and_ids
|
16
|
-
assert_equal %{<div class="one"></div>}, mab { div.one '' }
|
17
|
-
assert_equal %{<div class="one two"></div>}, mab { div.one.two '' }
|
18
|
-
assert_equal %{<div id="three"></div>}, mab { div.three! '' }
|
19
|
-
assert_equal %{<hr class="hidden"/>}, mab { hr.hidden }
|
20
|
-
|
21
|
-
out = mab { input.foo :id => 'bar' }
|
22
|
-
out.should match("<input.*class=\"foo\".*/>")
|
23
|
-
out.should match("<input.*name=\"bar\".*/>")
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_escaping
|
27
|
-
assert_equal "<h1>Apples & Oranges</h1>", mab { h1 'Apples & Oranges' }
|
28
|
-
assert_equal "<h1>Apples & Oranges</h1>", mab { h1 { 'Apples & Oranges' } }
|
29
|
-
assert_equal "<h1 class=\"fruits&floots\">Apples</h1>", mab { h1 'Apples', :class => 'fruits&floots' }
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_capture
|
33
|
-
builder = Markaby::Builder.new
|
34
|
-
assert builder.to_s.empty?
|
35
|
-
assert_equal "<h1>TEST</h1>", builder.capture { h1 'TEST' }
|
36
|
-
assert builder.to_s.empty?
|
37
|
-
assert mab { capture { h1 'hello world' }; nil }.empty?
|
38
|
-
assert_equal mab { div { h1 'TEST' } }, mab { div { capture { h1 'TEST' } } }
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_ivars
|
42
|
-
html = "<div><h1>Steve</h1><div><h2>Gerald</h2></div><h3>Gerald</h3></div>"
|
43
|
-
assert_equal html, mab { div { @name = 'Steve'; h1 @name; div { @name = 'Gerald'; h2 @name }; h3 @name } }
|
44
|
-
assert_equal html, mab { div { @name = 'Steve'; h1 @name; self << capture { div { @name = 'Gerald'; h2 @name } }; h3 @name } }
|
45
|
-
assert_equal html, mab(:name => 'Steve') { div { h1 @name; self << capture { div { @name = 'Gerald'; h2 @name } }; h3 @name } }
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_ivars_without_at_symbol
|
49
|
-
assert_equal "<h1>Hello World</h1>", mab { @message = 'Hello World'; h1 message }
|
50
|
-
end
|
51
|
-
|
52
|
-
def spec_helpers
|
53
|
-
Markaby::Builder.ignored_helpers.clear
|
54
|
-
assert_equal %{squirrels}, mab({}, MarkabyTestHelpers) { pluralize('squirrel') }
|
55
|
-
assert_equal %{<a href="">edit</a>}, mab({}, MarkabyTestHelpers) { link_to('edit') }
|
56
|
-
assert mab({}, MarkabyTestHelpers) { @output_helpers = false; link_to('edit'); nil }.empty?
|
57
|
-
Markaby::Builder.ignore_helpers :pluralize
|
58
|
-
assert_exception(NoMethodError, "undefined method `pluralize'", {}, MarkabyTestHelpers) { pluralize('squirrel') }
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_uses_helper_instance_variable
|
62
|
-
helper = Module.new do
|
63
|
-
@some_ivar = :ivar_value
|
64
|
-
end
|
65
|
-
|
66
|
-
builder = Markaby::Builder.new({}, helper)
|
67
|
-
assert_equal :ivar_value, builder.some_ivar
|
68
|
-
end
|
69
|
-
|
3
|
+
describe Markaby do
|
70
4
|
it "can assign helpers after instantiation" do
|
71
5
|
helper = mock 'helper', :foo => :bar
|
72
6
|
|
73
7
|
builder = Markaby::Builder.new
|
74
8
|
builder.helper = helper
|
75
|
-
|
9
|
+
builder.foo.should == :bar
|
76
10
|
end
|
77
11
|
|
78
12
|
it "should be able to set a local" do
|
@@ -240,4 +174,11 @@ class MarkabyTest < Test::Unit::TestCase
|
|
240
174
|
builder = Markaby::Builder.new({}, klass.new)
|
241
175
|
builder.capture { @hello }.should == "hello there"
|
242
176
|
end
|
177
|
+
|
178
|
+
describe Markaby::InvalidXhtmlError do
|
179
|
+
it "should inherit from StandardError" do
|
180
|
+
Markaby::InvalidXhtmlError.superclass.should == StandardError
|
181
|
+
end
|
182
|
+
end
|
243
183
|
end
|
184
|
+
|
@@ -0,0 +1,251 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
class MarkabyTest < Test::Unit::TestCase
|
4
|
+
def teardown
|
5
|
+
Markaby::Builder.restore_defaults!
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_simple
|
9
|
+
assert_equal "<hr/>", mab { hr }
|
10
|
+
assert_equal "<hr/><br/>", mab { hr; br }
|
11
|
+
assert_equal "<p>foo</p>", mab { p 'foo' }
|
12
|
+
assert_equal "<p>foo</p>", mab { p { 'foo' } }
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_classes_and_ids
|
16
|
+
assert_equal %{<div class="one"></div>}, mab { div.one '' }
|
17
|
+
assert_equal %{<div class="one two"></div>}, mab { div.one.two '' }
|
18
|
+
assert_equal %{<div id="three"></div>}, mab { div.three! '' }
|
19
|
+
assert_equal %{<hr class="hidden"/>}, mab { hr.hidden }
|
20
|
+
|
21
|
+
out = mab { input.foo :id => 'bar' }
|
22
|
+
out.should match("<input.*class=\"foo\".*/>")
|
23
|
+
out.should match("<input.*name=\"bar\".*/>")
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_escaping
|
27
|
+
assert_equal "<h1>Apples & Oranges</h1>", mab { h1 'Apples & Oranges' }
|
28
|
+
assert_equal "<h1>Apples & Oranges</h1>", mab { h1 { 'Apples & Oranges' } }
|
29
|
+
assert_equal "<h1 class=\"fruits&floots\">Apples</h1>", mab { h1 'Apples', :class => 'fruits&floots' }
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_capture
|
33
|
+
builder = Markaby::Builder.new
|
34
|
+
assert builder.to_s.empty?
|
35
|
+
assert_equal "<h1>TEST</h1>", builder.capture { h1 'TEST' }
|
36
|
+
assert builder.to_s.empty?
|
37
|
+
assert mab { capture { h1 'hello world' }; nil }.empty?
|
38
|
+
assert_equal mab { div { h1 'TEST' } }, mab { div { capture { h1 'TEST' } } }
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_ivars
|
42
|
+
html = "<div><h1>Steve</h1><div><h2>Gerald</h2></div><h3>Gerald</h3></div>"
|
43
|
+
assert_equal html, mab { div { @name = 'Steve'; h1 @name; div { @name = 'Gerald'; h2 @name }; h3 @name } }
|
44
|
+
assert_equal html, mab { div { @name = 'Steve'; h1 @name; self << capture { div { @name = 'Gerald'; h2 @name } }; h3 @name } }
|
45
|
+
assert_equal html, mab(:name => 'Steve') { div { h1 @name; self << capture { div { @name = 'Gerald'; h2 @name } }; h3 @name } }
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_ivars_without_at_symbol
|
49
|
+
assert_equal "<h1>Hello World</h1>", mab { @message = 'Hello World'; h1 message }
|
50
|
+
end
|
51
|
+
|
52
|
+
def spec_helpers
|
53
|
+
Markaby::Builder.ignored_helpers.clear
|
54
|
+
assert_equal %{squirrels}, mab({}, MarkabyTestHelpers) { pluralize('squirrel') }
|
55
|
+
assert_equal %{<a href="">edit</a>}, mab({}, MarkabyTestHelpers) { link_to('edit') }
|
56
|
+
assert mab({}, MarkabyTestHelpers) { @output_helpers = false; link_to('edit'); nil }.empty?
|
57
|
+
Markaby::Builder.ignore_helpers :pluralize
|
58
|
+
assert_exception(NoMethodError, "undefined method `pluralize'", {}, MarkabyTestHelpers) { pluralize('squirrel') }
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_uses_helper_instance_variable
|
62
|
+
helper = Module.new do
|
63
|
+
@some_ivar = :ivar_value
|
64
|
+
end
|
65
|
+
|
66
|
+
builder = Markaby::Builder.new({}, helper)
|
67
|
+
assert_equal :ivar_value, builder.some_ivar
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe Markaby do
|
72
|
+
it "can assign helpers after instantiation" do
|
73
|
+
helper = mock 'helper', :foo => :bar
|
74
|
+
|
75
|
+
builder = Markaby::Builder.new
|
76
|
+
builder.helper = helper
|
77
|
+
builder.foo.should == :bar
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should be able to set a local" do
|
81
|
+
builder = Markaby::Builder.new
|
82
|
+
builder.locals = { :foo => "bar" }
|
83
|
+
builder.foo.should == "bar"
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should be able to set a different local value" do
|
87
|
+
builder = Markaby::Builder.new
|
88
|
+
builder.locals = { :foo => "baz" }
|
89
|
+
builder.foo.should == "baz"
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should assign the correct key" do
|
93
|
+
builder = Markaby::Builder.new
|
94
|
+
builder.locals = { :key => :value }
|
95
|
+
builder.key.should == :value
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should be able to assign multiple locals" do
|
99
|
+
builder = Markaby::Builder.new
|
100
|
+
|
101
|
+
builder.locals = { :one => "two", :three => "four" }
|
102
|
+
|
103
|
+
builder.one.should == "two"
|
104
|
+
builder.three.should == "four"
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_builder_bang_methods
|
108
|
+
assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", mab { instruct! }
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should be able to produce the correct html from a fragment" do
|
112
|
+
str = ""
|
113
|
+
str += "<div>"
|
114
|
+
str += "<h1>Monkeys</h1>"
|
115
|
+
str += "<h2>Giraffes <small>Miniature</small> and <strong>Large</strong></h2>"
|
116
|
+
str += "<h3>Donkeys</h3>"
|
117
|
+
str += "<h4>Parakeet <b><i>Innocent IV</i></b> in Classic Chartreuse</h4>"
|
118
|
+
str += "</div>"
|
119
|
+
|
120
|
+
generated = mab {
|
121
|
+
div {
|
122
|
+
h1 "Monkeys"
|
123
|
+
h2 {
|
124
|
+
"Giraffes #{small('Miniature')} and #{strong 'Large'}"
|
125
|
+
}
|
126
|
+
h3 "Donkeys"
|
127
|
+
h4 { "Parakeet #{b { i 'Innocent IV' }} in Classic Chartreuse" }
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
generated.should == str
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_fragments
|
135
|
+
assert_equal %{<div><h1>Monkeys</h1><h2>Giraffes <strong>Miniature</strong></h2><h3>Donkeys</h3></div>},
|
136
|
+
mab { div { h1 "Monkeys"; h2 { "Giraffes #{strong 'Miniature' }" }; h3 "Donkeys" } }
|
137
|
+
|
138
|
+
assert_equal %{<div><h1>Monkeys</h1><h2>Giraffes <small>Miniature</small> and <strong>Large</strong></h2><h3>Donkeys</h3><h4>Parakeet <strong>Large</strong> as well...</h4></div>},
|
139
|
+
mab { div { @a = small 'Miniature'; @b = strong 'Large'; h1 "Monkeys"; h2 { "Giraffes #{@a} and #{@b}" }; h3 "Donkeys"; h4 { "Parakeet #{@b} as well..." } } }
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_invalid_xhtml
|
143
|
+
assert_exception(NoMethodError, "undefined method `dav'") { dav {} }
|
144
|
+
assert_exception(Markaby::InvalidXhtmlError, "no attribute `styl' on div elements") { div(:styl => 'ok') {} }
|
145
|
+
assert_exception(Markaby::InvalidXhtmlError, "no attribute `class' on tbody elements") { tbody.okay {} }
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_full_doc_transitional
|
149
|
+
doc = mab { xhtml_transitional { head { title 'OKay' } } }
|
150
|
+
assert doc =~ /^<\?xml version="1.0" encoding="UTF-8"\?>/
|
151
|
+
assert doc.include?(%{"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">})
|
152
|
+
assert doc.include?(%{<title>OKay</title>})
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_full_doc_strict
|
156
|
+
doc = mab { xhtml_strict { head { title 'OKay' } } }
|
157
|
+
assert doc =~ /^<\?xml version="1.0" encoding="UTF-8"\?>/
|
158
|
+
assert doc.include?(%{"-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">})
|
159
|
+
assert doc.include?(%{<title>OKay</title>})
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_full_doc_frameset
|
163
|
+
doc = mab { xhtml_frameset { head { title 'OKay' } } }
|
164
|
+
assert doc =~ /^<\?xml version="1.0" encoding="UTF-8"\?>/
|
165
|
+
assert doc.include?(%{"-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">})
|
166
|
+
assert doc.include?(%{<title>OKay</title>})
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_root_attributes_can_be_changed
|
170
|
+
doc = mab { xhtml_strict(:lang => 'fr') { head { title { 'Salut!' } } } }
|
171
|
+
assert doc.include?(%{"-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">})
|
172
|
+
assert doc.include?(%{<title>Salut!</title>})
|
173
|
+
assert doc.include?(%{ lang="fr"})
|
174
|
+
end
|
175
|
+
|
176
|
+
def version_file
|
177
|
+
File.expand_path(File.dirname(__FILE__) + "/../../VERSION")
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_markaby_should_have_correct_version
|
181
|
+
assert_equal Markaby::VERSION, File.read(version_file).strip
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_duplicate_usage_of_same_id
|
185
|
+
assert_raises Markaby::InvalidXhtmlError do
|
186
|
+
mab do
|
187
|
+
p.one!
|
188
|
+
p.one!
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
# auto validation
|
194
|
+
|
195
|
+
def test_tagging_with_invalid_tag_should_raise_error
|
196
|
+
assert_raises Markaby::InvalidXhtmlError do
|
197
|
+
mab do
|
198
|
+
tag! :an_invalid_tag
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_self_closing_html_tag_with_block_throws_errors
|
204
|
+
assert_raises Markaby::InvalidXhtmlError do
|
205
|
+
mab do
|
206
|
+
html_tag :img do
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_local_assigning
|
213
|
+
builder = Markaby::Builder.new(:variable => :a_value)
|
214
|
+
|
215
|
+
assert_equal :a_value, builder.variable
|
216
|
+
end
|
217
|
+
|
218
|
+
def test_local_assignment_with_strings
|
219
|
+
builder = Markaby::Builder.new("variable" => :a_value)
|
220
|
+
assert_equal :a_value, builder.variable
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_local_assignment_prefers_symbols_to_strings
|
224
|
+
builder = Markaby::Builder.new("variable" => "string_value", :variable => :symbol_value)
|
225
|
+
assert_equal :symbol_value, builder.variable
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_method_missing_should_call_tag_if_no_tagset_present
|
229
|
+
Markaby::Builder.set(:tagset, nil)
|
230
|
+
|
231
|
+
builder = Markaby::Builder.new
|
232
|
+
builder.something.should == "<something/>"
|
233
|
+
end
|
234
|
+
|
235
|
+
it "should copy instance variables from a helper object" do
|
236
|
+
klass = Class.new do
|
237
|
+
def initialize
|
238
|
+
@hello = "hello there"
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
builder = Markaby::Builder.new({}, klass.new)
|
243
|
+
builder.capture { @hello }.should == "hello there"
|
244
|
+
end
|
245
|
+
|
246
|
+
describe Markaby::InvalidXhtmlError do
|
247
|
+
it "should inherit from StandardError" do
|
248
|
+
Markaby::InvalidXhtmlError.superclass.should == StandardError
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test/unit'
|
2
|
-
require '
|
3
|
-
require '
|
2
|
+
require 'test/unit/autorunner'
|
3
|
+
require 'rspec'
|
4
4
|
|
5
5
|
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
6
|
|
@@ -36,6 +36,9 @@ module Test
|
|
36
36
|
module Unit
|
37
37
|
class TestCase
|
38
38
|
include TestHelpers
|
39
|
+
def self.it(name, &blk)
|
40
|
+
define_method("test_#{name}", &blk)
|
41
|
+
end
|
39
42
|
end
|
40
43
|
end
|
41
44
|
end
|
metadata
CHANGED
@@ -1,15 +1,10 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: markaby
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 7
|
9
|
-
- 1
|
10
|
-
version: 0.7.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.2
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- _why
|
14
9
|
- Tim Fletcher
|
15
10
|
- John Barton
|
@@ -18,36 +13,26 @@ authors:
|
|
18
13
|
autorequire:
|
19
14
|
bindir: bin
|
20
15
|
cert_chain: []
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
dependencies:
|
25
|
-
- !ruby/object:Gem::Dependency
|
16
|
+
date: 2011-08-23 00:00:00.000000000Z
|
17
|
+
dependencies:
|
18
|
+
- !ruby/object:Gem::Dependency
|
26
19
|
name: builder
|
27
|
-
|
28
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
requirement: &70326085518080 !ruby/object:Gem::Requirement
|
29
21
|
none: false
|
30
|
-
requirements:
|
31
|
-
- -
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
hash: 15
|
34
|
-
segments:
|
35
|
-
- 2
|
36
|
-
- 0
|
37
|
-
- 0
|
22
|
+
requirements:
|
23
|
+
- - ! '>='
|
24
|
+
- !ruby/object:Gem::Version
|
38
25
|
version: 2.0.0
|
39
26
|
type: :runtime
|
40
|
-
|
27
|
+
prerelease: false
|
28
|
+
version_requirements: *70326085518080
|
41
29
|
description: Tim Fletcher and _why's ruby driven HTML templating system
|
42
30
|
email: scott@railsnewbie.com
|
43
31
|
executables: []
|
44
|
-
|
45
32
|
extensions: []
|
46
|
-
|
47
|
-
extra_rdoc_files:
|
33
|
+
extra_rdoc_files:
|
48
34
|
- README.rdoc
|
49
|
-
files:
|
50
|
-
- .gitignore
|
35
|
+
files:
|
51
36
|
- CHANGELOG.rdoc
|
52
37
|
- Markaby.gemspec
|
53
38
|
- README.rdoc
|
@@ -68,10 +53,11 @@ files:
|
|
68
53
|
- lib/markaby/tags.rb
|
69
54
|
- lib/markaby/tilt.rb
|
70
55
|
- spec/markaby/builder_spec.rb
|
71
|
-
- spec/markaby/
|
72
|
-
- spec/markaby/
|
56
|
+
- spec/markaby/css_proxy_test.rb
|
57
|
+
- spec/markaby/fragment_test.rb
|
73
58
|
- spec/markaby/markaby_other_static.mab
|
74
59
|
- spec/markaby/markaby_spec.rb
|
60
|
+
- spec/markaby/markaby_test.rb
|
75
61
|
- spec/markaby/rails/spec_helper.rb
|
76
62
|
- spec/markaby/rails/views/layouts/layout.mab
|
77
63
|
- spec/markaby/rails/views/markaby/_a_partial.mab
|
@@ -99,7 +85,7 @@ files:
|
|
99
85
|
- spec/markaby/rails/views/markaby/yielding_content_for_with_block_helper.mab
|
100
86
|
- spec/markaby/rails/views/markaby/yielding_two.mab
|
101
87
|
- spec/markaby/rails/views/markaby/yielding_with_content_for.mab
|
102
|
-
- spec/markaby/
|
88
|
+
- spec/markaby/rails_test.rb
|
103
89
|
- spec/markaby/rails_version_spec.rb
|
104
90
|
- spec/markaby/sinatra/app.rb
|
105
91
|
- spec/markaby/sinatra/sinatra_spec.rb
|
@@ -119,49 +105,28 @@ files:
|
|
119
105
|
- spec/markaby/tilt_spec.rb
|
120
106
|
- spec/spec.opts
|
121
107
|
- spec/spec_helper.rb
|
122
|
-
has_rdoc: true
|
123
108
|
homepage: http://markaby.github.com/markaby/
|
124
109
|
licenses: []
|
125
|
-
|
126
110
|
post_install_message:
|
127
|
-
rdoc_options:
|
128
|
-
|
129
|
-
require_paths:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
130
113
|
- lib
|
131
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
115
|
none: false
|
133
|
-
requirements:
|
134
|
-
- -
|
135
|
-
- !ruby/object:Gem::Version
|
136
|
-
|
137
|
-
|
138
|
-
- 0
|
139
|
-
version: "0"
|
140
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ! '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
121
|
none: false
|
142
|
-
requirements:
|
143
|
-
- -
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
|
146
|
-
segments:
|
147
|
-
- 0
|
148
|
-
version: "0"
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
149
126
|
requirements: []
|
150
|
-
|
151
127
|
rubyforge_project:
|
152
|
-
rubygems_version: 1.
|
128
|
+
rubygems_version: 1.8.6
|
153
129
|
signing_key:
|
154
130
|
specification_version: 3
|
155
131
|
summary: Markup as Ruby, write HTML in your native Ruby tongue
|
156
|
-
test_files:
|
157
|
-
- spec/markaby/builder_spec.rb
|
158
|
-
- spec/markaby/css_proxy_spec.rb
|
159
|
-
- spec/markaby/fragment_spec.rb
|
160
|
-
- spec/markaby/markaby_spec.rb
|
161
|
-
- spec/markaby/rails/spec_helper.rb
|
162
|
-
- spec/markaby/rails_spec.rb
|
163
|
-
- spec/markaby/rails_version_spec.rb
|
164
|
-
- spec/markaby/sinatra/app.rb
|
165
|
-
- spec/markaby/sinatra/sinatra_spec.rb
|
166
|
-
- spec/markaby/tilt_spec.rb
|
167
|
-
- spec/spec_helper.rb
|
132
|
+
test_files: []
|