Changeset 195
- Timestamp:
- 02/25/07 14:34:10 (2 years ago)
- Files:
-
- trunk/Rakefile (modified) (1 diff)
- trunk/lib/merb/mixins/controller_mixin.rb (modified) (1 diff)
- trunk/lib/merb/mixins/form_control_mixin.rb (modified) (1 diff)
- trunk/lib/merb/mixins/render_mixin.rb (modified) (6 diffs)
- trunk/lib/merb/mixins/responder_mixin.rb (modified) (1 diff)
- trunk/lib/merb/template.rb (modified) (1 diff)
- trunk/lib/merb/template/haml.rb (modified) (2 diffs)
- trunk/lib/merb/template/markaby.rb (modified) (1 diff)
- trunk/tools/annotation_extract.rb (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Rakefile
r193 r195 11 11 12 12 require __DIR__+'/tools/rakehelp' 13 require __DIR__+'/tools/annotation_extract' 13 14 include FileUtils 14 15 trunk/lib/merb/mixins/controller_mixin.rb
r193 r195 67 67 # http://wiki.codemongers.com/NginxXSendfile 68 68 def nginx_send_file(file) 69 headers['X-Accel-Redirect'] = file69 headers['X-Accel-Redirect'] = File.expand_path(file) 70 70 return 71 71 end trunk/lib/merb/mixins/form_control_mixin.rb
r142 r195 20 20 # <%= control_for @post, :published_at, :date %> 21 21 # 22 # TODO : is this useful enough? Needs some love 22 23 def control_for(obj, meth, type, opts={}) 23 24 instance = obj trunk/lib/merb/mixins/render_mixin.rb
r194 r195 50 50 def render(opts={}, &blk) 51 51 action = opts[:action] || params[:action] 52 opts[:layout] ||= ancestral_trait[:layout] 52 53 53 54 case … … 82 83 } 83 84 content = engine.transform(options) 84 return engine.exempt_from_layout? ? content : wrap_layout(content, opts) 85 if engine.exempt_from_layout? || opts[:layout] == :none 86 content 87 else 88 wrap_layout(content, opts) 89 end 85 90 end 86 91 … … 107 112 return " " 108 113 end 109 110 # renders the action without wrapping it in a layout. 111 # call it without arguments if your template matches 112 # the name of the running action. Otherwise you can 113 # explicitely set the template name excluding the file 114 # extension 114 115 115 def render_no_layout(opts={}) 116 116 render opts.update({:layout => :none}) … … 118 118 119 119 # This is merb's partial render method. You name your 120 # partials _partialname. herb, and then call it like120 # partials _partialname.* , and then call it like 121 121 # partial(:partialname). If there is no '/' character 122 122 # in the argument passed in it will look for the partial … … 133 133 134 134 def wrap_layout(content, opts={}) 135 return content if ((opts[:layout] == :none) || (ancestral_trait[:layout] == :none)) 136 137 if ancestral_trait[:layout] != :application 138 layout_choice = find_template(:layout => ancestral_trait[:layout]) 135 if opts[:layout] != :application 136 layout_choice = find_template(:layout => opts[:layout]) 139 137 else 140 138 if name = find_template(:layout => self.class.name.snake_case) … … 155 153 end 156 154 157 155 # OPTIMIZE : combine find_template and find_partial ? 158 156 def find_template(opts={}) 159 157 if action = opts[:action] trunk/lib/merb/mixins/responder_mixin.rb
r193 r195 10 10 # end 11 11 12 # TODO : revisit this whole patern. Can we improve on this? 12 13 module ResponderMixin 13 14 def respond_to trunk/lib/merb/template.rb
r194 r195 1 1 module Merb 2 2 module Template 3 # TODO : pull up common methods from template engines. 3 4 end 4 5 end trunk/lib/merb/template/haml.rb
r194 r195 7 7 end 8 8 module ActionView 9 10 9 # stub, in case the requires for that active_* stuff of Haml doesn't fail 11 10 # but we are not running Rails ;) 12 13 11 class Base 14 15 12 # stub 16 17 13 def concat 18 14 end 19 20 15 # stub 21 22 16 def form_tag 23 17 end … … 39 33 40 34 class << self 35 @@hamls ||= {} 36 @@mtimes ||= {} 41 37 def exempt_from_layout? 42 38 false 43 39 end 44 40 41 # OPTIMIZE : add haml template caching 45 42 def transform(options = {}) 46 43 opts, file, view_context = options.values_at(:opts, :file, :view_context) 47 haml = ::Haml::Engine.new(IO.read(file), ancestral_trait[:haml_options].update(opts)) 44 opts = ancestral_trait[:haml_options].merge(opts) 45 if precompiled = get_precompiled(file) 46 opts[:precompiled] ||= precompiled 47 haml = ::Haml::Engine.new("", opts) 48 else 49 haml = ::Haml::Engine.new(IO.read(file), opts) 50 set_precompiled(file, haml.precompiled) 51 end 48 52 haml.to_html(view_context) 49 53 end 54 55 private 56 57 def get_precompiled(path, opts={}) 58 if @@hamls[path] && !cache_template?(path) 59 return @@hamls[path] 60 end 61 end 62 63 def set_precompiled(path, precompiled) 64 @@hamls[path], @@mtimes[path] = precompiled, Time.now 65 end 66 67 def cache_template?(path) 68 return false unless ::Merb::Server.config[:cache_templates] 69 return true unless @@hamls[path] 70 @@mtimes[path] < File.mtime(path) || 71 (File.symlink?(path) && (@@mtimes[path] < File.lstat(path).mtime)) 72 end 73 50 74 end 51 75 trunk/lib/merb/template/markaby.rb
r193 r195 30 30 end 31 31 32 # OPTIMIZE : add mab template caching. what does this mean for mab? 33 # mab is just ruby, there's no two phase compile and run 32 34 def transform(options = {}) 33 35 opts, file, view_context = options.values_at(:opts, :file, :view_context)
