Changeset 34
- Timestamp:
- 02/15/08 21:56:21 (7 months ago)
- Files:
-
- trunk/malline/lib/malline.rb (modified) (2 diffs)
- trunk/malline/lib/malline/rails.rb (modified) (2 diffs)
- trunk/malline/lib/malline/view_wrapper.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/malline/lib/malline.rb
r28 r34 77 77 def render tpl = nil, local_assigns = {}, n = nil, &block 78 78 add_local_assigns local_assigns 79 tmp = @view.malline.run tpl, &block80 tmp79 @view.malline_is_active = true 80 @view.malline.run tpl, &block 81 81 end 82 82 … … 85 85 end 86 86 87 # TODO: These should also be able to disable 87 88 def definetags *tags 88 89 tags.each do |tag| trunk/malline/lib/malline/rails.rb
r33 r34 26 26 alias_method :orig_delegate_render, :delegate_render 27 27 def delegate_render(handler, template, local_assigns) 28 if handler == Malline::Base29 @malline_is_active = true28 old = @malline_is_active 29 tmp = if handler == Malline::Base 30 30 h = handler.new(self) 31 31 h.set_path(@current_tpl_path) if @current_tpl_path … … 35 35 orig_delegate_render(handler, template, local_assigns) 36 36 end 37 @malline_is_active = old 38 tmp 37 39 end 38 40 end if const_defined?('Base') trunk/malline/lib/malline/view_wrapper.rb
r28 r34 18 18 module Malline 19 19 module ViewWrapper 20 attr_accessor :malline_is_active 21 22 # List of all methods that may override some custom view methods 23 # If is_malline?, then their _malline_ -prefix versions are called 24 @@malline_methods = %w{_erbout cache capture _ tag! << txt!} 25 26 def init_malline_methods 27 @malline_methods_inited = true 28 @@malline_methods.each do |m| 29 mf = m.gsub('<', 'lt') 30 eval %{def #{m}(*x, &b) is_malline? ? _malline_#{mf}(*x, &b) : super; end} 31 end 32 end 33 20 34 def malline opts = nil 21 35 if @malline … … 24 38 @malline = Template.new(self, opts) 25 39 end 40 init_malline_methods unless @malline_methods_inited 26 41 @malline 27 42 end 28 43 29 def _ erbout44 def _malline__erbout 30 45 @_erbout ||= ErbOut.new(self) 31 @_erbout32 46 end 33 47 34 def cache name = {}, options = {}, &block48 def _malline_cache name = {}, options = {}, &block 35 49 return block.call unless @controller.perform_caching 36 50 cache = @controller.read_fragment(name, options) 37 51 38 52 unless cache 39 cache = capture { block.call }53 cache = _malline_capture { block.call } 40 54 @controller.write_fragment(name, cache, options) 41 55 end … … 43 57 end 44 58 45 def capture &block59 def _malline_capture &block 46 60 @malline.run &block 47 61 end 48 62 49 def _ *args63 def _malline__ *args 50 64 @malline.add_text(*args) 51 65 end 52 alias_method : txt!, :_66 alias_method :_malline_txt!, :_malline__ 53 67 54 def <<*args68 def _malline_ltlt *args 55 69 @malline.add_unescaped_text *args 56 70 end 57 71 58 72 def method_missing s, *args, &block 73 return super unless is_malline? 59 74 helper = (s.to_s[0].chr == '_') ? s.to_s[1..255].to_sym : s.to_sym 60 75 if respond_to?(helper) … … 62 77 else 63 78 return super if @malline.options[:strict] 64 tag! s, *args, &block79 _malline_tag! s, *args, &block 65 80 end 66 81 end 67 82 68 def tag! *args, &block83 def _malline_tag! *args, &block 69 84 @malline.tag *args, &block 70 85 end
