Changeset 42
- Timestamp:
- 05/01/08 18:42:52 (4 months ago)
- Files:
-
- trunk/malline/lib/malline.rb (modified) (2 diffs)
- trunk/malline/lib/malline/template.rb (modified) (4 diffs)
- trunk/malline/test/malline_test.rb (modified) (3 diffs)
- trunk/malline/test/malline_test_helpers.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/malline/lib/malline.rb
r38 r42 24 24 25 25 module Malline 26 VERSION = '1.0.2' 26 # Always form ^\d+\.\d+\.\d+(-[^\s]*)?$ 27 VERSION = '1.0.3-svn' 27 28 28 29 # Template-handler class that is registered to ActionView and initialized by it. … … 86 87 end 87 88 88 # TODO: These should also be able to disable 89 def definetags *tags 90 tags.each do |tag| 91 eval %{ 92 def @view.#{tag}(*args, &block) 93 tag!('#{tag}', *args, &block) 94 end 95 } 96 end 89 def definetags *args 90 @view.malline.definetags *args 91 end 92 93 def definetags! *args 94 @view.malline.definetags! *args 97 95 end 98 96 trunk/malline/lib/malline/template.rb
r35 r42 22 22 attr_accessor :whitespace 23 23 attr_accessor :path 24 attr_accessor :helper_overrides 24 25 25 26 def initialize view, opts … … 29 30 @options = opts 30 31 @short_tag_excludes = [] 32 @helper_overrides = {} 31 33 end 32 34 … … 63 65 64 66 def helper helper, *args, &block 65 tmp = @view.send(helper, *args, &block) 67 helper = helper.to_sym 68 tmp = if h = @helper_overrides[helper] 69 h.call(*args, &block) 70 else 71 @view.send(helper, *args, &block) 72 end 66 73 @dom << ' ' if @whitespace 67 74 @dom << tmp.to_s … … 121 128 render tmp 122 129 end 130 131 # TODO: These should also be able to disable 132 def definetags! *tags 133 tags.flatten.each do |tag| 134 tag = tag.to_sym 135 @helper_overrides[tag] = @view.method(tag) if @view.respond_to?(tag) 136 define_tag! tag 137 end 138 end 139 140 def definetags *tags 141 tags.flatten.each{|tag| define_tag!(tag) unless @view.respond_to?(tag)} 142 end 143 144 def define_tag! tag 145 eval %{ 146 def @view.#{tag}(*args, &block) 147 tag!('#{tag}', *args, &block) 148 end 149 } 150 end 123 151 end 124 152 end trunk/malline/test/malline_test.rb
r35 r42 47 47 'link' 48 48 end 49 def zoo *args 50 'zoo output' 51 end 49 52 end 50 53 … … 56 59 def test_simple 57 60 Base.setopt :strict => false, :xhtml => false do 58 assert_xml_equal('<foo id="a"><bar class="a b"/> </foo>',61 assert_xml_equal('<foo id="a"><bar class="a b"/>blabla</foo>', 59 62 Base.render do 60 63 foo.a! do 61 64 bar.a.b 65 _'blabla' 62 66 end 63 67 end … … 110 114 b = Proc.new do 111 115 foo do 112 xxx:a => 'b' do116 zoo :a => 'b' do 113 117 bar 114 118 end 119 _zoo 120 xoo.bar 115 121 end 116 122 end 117 123 out = tpl.render nil, &b 118 assert_xml_equal('<foo/>', out) 119 120 tpl.definetags :xxx 124 # zoo isn't rendered, because there is helper named zoo 125 assert_xml_equal('<foo>zoo output<xoo class="bar"/></foo>', out) 126 127 tpl.definetags :zoo 121 128 out = tpl.render nil, &b 122 assert_xml_equal('<foo><xxx a="b"><bar/></xxx></foo>', out) 129 assert_xml_equal('<foo>zoo output<xoo class="bar"/></foo>', out) 130 131 tpl.definetags! :zoo 132 out = tpl.render nil, &b 133 assert_xml_equal('<foo><zoo a="b"><bar/></zoo>zoo output<xoo class="bar"/></foo>', out) 123 134 124 135 out = Base.setopt :strict => false, :xhtml => false do 125 136 Base.render &b 126 137 end 127 assert_xml_equal('<foo />', out)138 assert_xml_equal('<foo><zoo a="b"><bar/></zoo><_zoo/><xoo class="bar"/></foo>', out) 128 139 end 129 140 trunk/malline/test/malline_test_helpers.rb
r35 r42 17 17 18 18 require "rexml/document" 19 20 module Kernel21 def xxx *args22 end23 end24 19 25 20 module MallineTestHelpers
