Changeset 61

Show
Ignore:
Timestamp:
05/29/2006 05:44:17 (2 years ago)
Author:
tec
Message:
  • lib/markaby/builder.rb: allow certain helpers to be ignored (in favour of tags)
  • test/test_markaby.rb: tests for above, improvement on others
Location:
trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/markaby/builder.rb

    r60 r61  
    3030    end 
    3131 
     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 
    3240    XHTMLTransitional = ["-//W3C//DTD XHTML 1.0 Transitional//EN", "DTD/xhtml1-transitional.dtd"] 
    3341     
     
    174182    # * Otherwise, +sym+ and its arguments are passed to tag! 
    175183    def method_missing(sym, *args, &block) 
    176       if @helpers.respond_to?(sym) 
     184      if @helpers.respond_to?(sym) && !self.class.ignored_helpers.include?(sym) 
    177185        r = @helpers.send(sym, *args, &block) 
    178186        @output_helpers ? fragment { @builder << r } : r 
     
    191199          end 
    192200        end 
    193         if not @tagset_self_closing.include?(sym) and args.first.respond_to?(:to_hash) 
    194           block ||= proc{} 
    195         end 
     201        #if not @tagset_self_closing.include?(sym) and args.first.respond_to?(:to_hash) 
     202        #  block ||= proc{} 
     203        #end 
    196204        tag!(sym, *args, &block) 
    197205      elsif instance_variable_get("@#{sym}") 
  • trunk/test/test_markaby.rb

    r60 r61  
    66    %{<a href="">#{obj}</a>} 
    77  end 
    8   def pluralize(n, string) 
    9     n == 1 ? string : string + "s" 
     8  def pluralize(string) 
     9    string + "s" 
    1010  end 
    1111  module_function :link_to, :pluralize 
     
    2626    end 
    2727  end 
    28  
     28   
    2929  def test_simple 
    3030    assert_equal "<hr/>\n", mab { hr } 
     
    6565  end 
    6666   
    67   def test_output_helpers 
     67  def test_helpers 
     68    Markaby::Builder.ignored_helpers.clear 
     69    assert_equal %{squirrels}, mab({}, MarkabyTestHelpers) { pluralize('squirrel') } 
    6870    assert_equal %{<a href="">edit</a>}, mab({}, MarkabyTestHelpers) { link_to('edit') } 
    6971    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') } 
    7074  end 
    7175 
     
    9094 
    9195  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>}) 
    97100  end 
    98101 
    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>}) 
    105107  end 
    106108