Changeset 991

Show
Ignore:
Timestamp:
11/13/07 14:11:32 (1 year ago)
Author:
wyca..@gmail.com
Message:

Reloading stuff as well as fixes to faster partials

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/app_generators/merb/templates/app/views/exceptions/internal_server_error.html.erb

    r833 r991  
    105105                                        font-weight:bold; 
    106106                                        color:#00BF10; 
     107                                } 
     108                                table.trace tr td.code a { 
     109                                  width: 20px; 
     110                                  float: left; 
    107111                                } 
    108112                                table.trace tr td.code .more { 
     
    165169                                                </td> 
    166170                                                <td class="path"> 
    167                                                         <%= (line.match(/^([^:]+)/)[1] rescue 'unknown').sub(/\/((opt|usr)\/local\/lib\/(ruby\/)?(gems\/)?(1.8\/)?(gems\/)?|.+\/app\/)/, '') %> in "<strong><%= line.match(/:in `(.+)'$/)[1] rescue '?' %></strong>" 
     171                                                        <%= (line.match(/^([^:]+)/)[1] rescue 'unknown').sub(/\/((opt|usr)\/local\/lib\/(ruby\/)?(gems\/)?(1.8\/)?(gems\/)?|.+\/app\/)/, '') %> 
     172                                                        <% unless line.match(/\.erb:/) %> 
     173                in "<strong><%= line.match(/:in `(.+)'$/)[1] rescue '?' %></strong>" 
     174              <% else %> 
     175                (<strong>ERB Template</strong>) 
     176              <% end %> 
    168177                                                </td> 
    169178                                                <td class="line"> 
    170                                                         <a href="txmt://open?url=file://<%=file = (line.match(/^([^:]+)/)[1] rescue 'unknown')%>&amp;line=<%= lineno = line.match(/:([0-9]+):/)[1] rescue '?' %>"><%=lineno%></a> 
     179                                                        <a href="txmt://open?url=file://<%=file = (line.match(/^([^:]+)/)[1] rescue 'unknown')%>&amp;line=<%= lineno = line.match(/:([0-9]+):/)[1] rescue '?' %>"><%=lineno%></a>&nbsp; 
    171180                                                </td>  
    172181                                        </tr> 
     
    175184                                                </td> 
    176185                                                <td class="code" colspan="2"><% (__caller_lines__(file, lineno, 5) rescue []).each do |llineno, lcode, lcurrent| %> 
    177 <a href="txmt://open?url=file://<%=file%>&amp;line=<%=llineno%>"><%= llineno %></a><%='<em>' if llineno==lineno.to_i %><%= lcode.size > 90 ? lcode[0..90]+'<span class="more">......</span>' : lcode %><%='</em>' if llineno==lineno.to_i %> 
     186<a href="txmt://open?url=file://<%=file%>&amp;line=<%=llineno%>"><%= llineno %></a><%='<em>' if llineno==lineno.to_i %><%= lcode.size > 90 ? CGI.escapeHTML(lcode[0..90])+'<span class="more">......</span>' : CGI.escapeHTML(lcode) %><%='</em>' if llineno==lineno.to_i %> 
    178187<% end %> 
    179188 
  • trunk/lib/merb/server.rb

    r988 r991  
    275275      end 
    276276       
    277       def load_controller_template_path_cache 
    278          
    279         # This gets all templates set in the controllers template roots 
     277      def template_paths(type = "*") 
     278        # This gets all templates set in the controllers template roots         
    280279        template_paths = Merb::AbstractController._abstract_subclasses.map do |klass|  
    281280          Object.full_const_get(klass)._template_root 
    282281        end.uniq.map do |path|  
    283           Dir["#{path}/**/*"]  
     282          Dir["#{path}/**/#{type}"]  
    284283        end 
    285284         
    286285        # This gets the templates that might be created outside controllers 
    287286        # template roots.  eg app/views/shared/* 
    288         template_paths << Dir["#{MERB_ROOT}/app/views/**/*"] 
    289          
    290         template_paths = template_paths.flatten.compact.uniq 
    291          
     287        template_paths << Dir["#{MERB_ROOT}/app/views/**/*"] if type == "*" 
     288         
     289        template_paths.flatten.compact.uniq || [] 
     290      end 
     291       
     292      def load_controller_template_path_cache 
    292293        Merb::AbstractController.reset_template_path_cache! 
    293294 
     
    298299       
    299300      def load_erubis_inline_helpers 
    300         partials = Merb::AbstractController._abstract_subclasses.map {|x|  
    301           Dir.glob("#{Object.full_const_get(x)._template_root}/**/_*.erb") }.flatten 
     301        partials = template_paths("_*.erb") 
    302302 
    303303        partials.each do |partial| 
     
    329329      def reload 
    330330        return if !@@merb_opts[:reloader] || !Object.const_defined?(:MERB_PATHS) 
     331         
    331332        # First we collect all files in the project (this will also grab newly added files) 
    332333        project_files = MERB_PATHS.map { |path| Dir[@@merb_opts[:merb_root] + path] }.flatten.uniq 
    333         project_mtime = max_mtime project_files # Latest changed time of all project files 
     334        erb_partials = template_paths("_*.erb").map { |path| Dir[path] }.flatten.uniq 
     335        project_mtime = max_mtime(project_files + erb_partials) # Latest changed time of all project files 
    334336 
    335337        return if @mtime.nil? || @mtime >= project_mtime   # Only continue if a file has changed 
     
    358360              loaded_classes = Merb::Controller._subclasses - old_subclasses 
    359361              load_action_arguments(loaded_classes) 
    360               load_controller_template_path_cache 
    361               load_erubis_inline_helpers               
    362362            rescue Exception => e 
    363363              puts "Error reloading file #{file}: #{e}" 
     
    370370          end 
    371371        end         
    372          
     372 
     373        # Rebuild the glob cache and erubis inline helpers 
     374        load_controller_template_path_cache 
     375        load_erubis_inline_helpers 
     376 
    373377        @mtime = project_mtime # As the last action, update the current @mtime 
    374378      end 
  • trunk/lib/merb/template/erubis.rb

    r988 r991  
    1616        template_method = template.gsub(/[\/:]/, "__").gsub(/\./, "_") 
    1717 
     18        unless self.respond_to?(template_method) 
     19          raise Merb::ControllerExceptions::TemplateNotFound, "No template matched at #{template}"           
     20        end 
     21 
    1822        if with = opts.delete(:with) 
    1923          as = opts.delete(:as) || template.match(/(.*\/_)([^\.]*)/)[2] 
     
    2125          sent_template = [with].flatten.map do |temp| 
    2226            @_merb_partial_locals[as.to_sym] = temp 
    23             send(template_method) rescue raise Merb::ControllerExceptions::TemplateNotFound,  
    24               "No template matched at #{template}" 
     27            send(template_method) 
    2528          end.join 
    2629        else 
    2730          @_merb_partial_locals = opts         
    28           sent_template = send(template_method) rescue nil 
     31          sent_template = send(template_method) 
    2932        end 
    3033 
    3134        return sent_template if sent_template 
    3235 
    33         raise Merb::ControllerExceptions::TemplateNotFound, "No template matched at #{template}" 
    3436      end 
    3537 
    3638      def method_missing(sym, *args, &blk) 
    37         @_merb_partial_locals[sym] || @web_controller.send(sym, *args, &blk) rescue super 
     39        @_merb_partial_locals[sym] || @web_controller.send(sym, *args, &blk) 
    3840      end 
    3941       
  • trunk/lib/merb/view_context.rb

    r986 r991  
    6969    # and delegate them back to the controller. 
    7070    def method_missing(sym, *args, &blk) 
    71       @_merb_partial_locals[sym] || @web_controller.send(sym, *args, &blk) rescue super 
     71      @_merb_partial_locals[sym] || @web_controller.send(sym, *args, &blk) 
    7272    end 
    7373