markaby 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 the gemspec command
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.1"
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 = ["_why", "Tim Fletcher", "John Barton", "spox", "smtlaissezfaire"]
12
- s.date = %q{2010-08-19}
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
- ".gitignore",
20
- "CHANGELOG.rdoc",
21
- "Markaby.gemspec",
22
- "README.rdoc",
23
- "Rakefile",
24
- "VERSION",
25
- "garlic.rb",
26
- "init.rb",
27
- "lib/markaby.rb",
28
- "lib/markaby/builder.rb",
29
- "lib/markaby/builder_tags.rb",
30
- "lib/markaby/cssproxy.rb",
31
- "lib/markaby/kernel_method.rb",
32
- "lib/markaby/rails.rb",
33
- "lib/markaby/rails/current.rb",
34
- "lib/markaby/rails/deprecated.rb",
35
- "lib/markaby/rails/rails_builder.rb",
36
- "lib/markaby/sinatra.rb",
37
- "lib/markaby/tags.rb",
38
- "lib/markaby/tilt.rb",
39
- "spec/markaby/builder_spec.rb",
40
- "spec/markaby/css_proxy_spec.rb",
41
- "spec/markaby/fragment_spec.rb",
42
- "spec/markaby/markaby_other_static.mab",
43
- "spec/markaby/markaby_spec.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_spec.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"
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.rdoc_options = ["--charset=UTF-8"]
94
- s.require_paths = ["lib"]
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
@@ -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
- Markaby has a Tilt module, so in principle, any web framework that supports
76
- Tilt can/will also support Markaby.
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 'spec/rake/spectask'
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
- desc 'Run the specs'
20
- Spec::Rake::SpecTask.new do |t|
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
1
+ 0.7.2
@@ -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 < Exception; end
25
+ class InvalidXhtmlError < StandardError; end
26
26
  end
27
27
 
28
28
  require 'builder' unless defined?(Builder)
@@ -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.method_missing(tag, *args, &block) }
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
- if RUBY_VERSION_ID >= 191
280
- undef_method :to_s, :inspect, :==
286
+ [:to_s, :inspect, :==].each do |method|
287
+ undef_method method if method_defined?(method)
281
288
  end
282
289
 
283
290
  private
@@ -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
@@ -3,40 +3,6 @@ require 'tilt'
3
3
 
4
4
  module Markaby
5
5
  module Tilt
6
- class Template < ::Tilt::Template
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
@@ -1,78 +1,12 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
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 &amp; Oranges</h1>", mab { h1 'Apples & Oranges' }
28
- assert_equal "<h1>Apples & Oranges</h1>", mab { h1 { 'Apples & Oranges' } }
29
- assert_equal "<h1 class=\"fruits&amp;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
- assert_equal :bar, builder.foo
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 &amp; Oranges</h1>", mab { h1 'Apples & Oranges' }
28
+ assert_equal "<h1>Apples & Oranges</h1>", mab { h1 { 'Apples & Oranges' } }
29
+ assert_equal "<h1 class=\"fruits&amp;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
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), 'rails', 'spec_helper')
1
+ require File.expand_path('../rails/spec_helper', __FILE__)
2
2
 
3
3
  if RUNNING_RAILS
4
4
  class NonSpecificTestController < ActionController::Base
@@ -1,6 +1,6 @@
1
1
  require 'test/unit'
2
- require 'spec'
3
- require 'spec/interop/test'
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
- hash: 1
5
- prerelease: false
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
- date: 2010-08-19 00:00:00 -04:00
23
- default_executable:
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
- prerelease: false
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
- version_requirements: *id001
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/css_proxy_spec.rb
72
- - spec/markaby/fragment_spec.rb
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/rails_spec.rb
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
- - --charset=UTF-8
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
- hash: 3
137
- segments:
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
- hash: 3
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.3.7
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: []
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- doc
2
- coverage
3
- .garlic
4
- pkg
5
- _site