Changeset 61
- Timestamp:
- 05/29/2006 05:44:17 (2 years ago)
- Location:
- trunk
- Files:
-
- 2 modified
-
lib/markaby/builder.rb (modified) (3 diffs)
-
test/test_markaby.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/markaby/builder.rb
r60 r61 30 30 end 31 31 32 def self.ignored_helpers 33 @@ignored_helpers ||= [] 34 end 35 36 def self.ignore_helpers(*helpers) 37 ignored_helpers.concat helpers 38 end 39 32 40 XHTMLTransitional = ["-//W3C//DTD XHTML 1.0 Transitional//EN", "DTD/xhtml1-transitional.dtd"] 33 41 … … 174 182 # * Otherwise, +sym+ and its arguments are passed to tag! 175 183 def method_missing(sym, *args, &block) 176 if @helpers.respond_to?(sym) 184 if @helpers.respond_to?(sym) && !self.class.ignored_helpers.include?(sym) 177 185 r = @helpers.send(sym, *args, &block) 178 186 @output_helpers ? fragment { @builder << r } : r … … 191 199 end 192 200 end 193 if not @tagset_self_closing.include?(sym) and args.first.respond_to?(:to_hash)194 block ||= proc{}195 end201 #if not @tagset_self_closing.include?(sym) and args.first.respond_to?(:to_hash) 202 # block ||= proc{} 203 #end 196 204 tag!(sym, *args, &block) 197 205 elsif instance_variable_get("@#{sym}") -
trunk/test/test_markaby.rb
r60 r61 6 6 %{<a href="">#{obj}</a>} 7 7 end 8 def pluralize( n,string)9 n == 1 ? string :string + "s"8 def pluralize(string) 9 string + "s" 10 10 end 11 11 module_function :link_to, :pluralize … … 26 26 end 27 27 end 28 28 29 29 def test_simple 30 30 assert_equal "<hr/>\n", mab { hr } … … 65 65 end 66 66 67 def test_output_helpers 67 def test_helpers 68 Markaby::Builder.ignored_helpers.clear 69 assert_equal %{squirrels}, mab({}, MarkabyTestHelpers) { pluralize('squirrel') } 68 70 assert_equal %{<a href="">edit</a>}, mab({}, MarkabyTestHelpers) { link_to('edit') } 69 71 assert mab({}, MarkabyTestHelpers) { @output_helpers = false; link_to('edit') }.empty? 72 Markaby::Builder.ignore_helpers :pluralize 73 assert_exception(NoMethodError, "no such method `pluralize'", {}, MarkabyTestHelpers) { pluralize('squirrel') } 70 74 end 71 75 … … 90 94 91 95 def test_full_doc_transitional 92 doc = %{<?xml version=\"1.0\" encoding=\"UTF-8\"?> 93 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\"> 94 <html xml:lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\"> 95 <head>\n<meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\"/>\n<title>OKay</title>\n</head>\n</html>\n} 96 assert_equal doc, mab { instruct!; html { head { title 'OKay' } } } 96 doc = mab { instruct!; html { head { title 'OKay' } } } 97 assert doc =~ /^<\?xml version="1.0" encoding="UTF-8"\?>/ 98 assert doc.include?(%{"-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">}) 99 assert doc.include?(%{<title>OKay</title>}) 97 100 end 98 101 99 def test_full_doc_transitional 100 doc = %{<?xml version=\"1.0\" encoding=\"UTF-8\"?> 101 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"DTD/xhtml1-strict.dtd\"> 102 <html lang=\"en\" xml:lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"> 103 <head>\n<meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\"/>\n<title>OKay</title>\n</head>\n</html>\n} 104 assert_equal doc, mab { xhtml_strict { head { title 'OKay' } } } 102 def test_full_doc_strict 103 doc = mab { xhtml_strict { head { title 'OKay' } } } 104 assert doc =~ /^<\?xml version="1.0" encoding="UTF-8"\?>/ 105 assert doc.include?(%{"-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">}) 106 assert doc.include?(%{<title>OKay</title>}) 105 107 end 106 108