2010-12-06 9 views
0

Je veux passer outre comment rails crée une vue * .html.erbRAILS PRÉPONDÉRANTS VUES renderization

Dans le paquet ActionView je l'ai déjà essayé de le faire. Le faire

class ERB 
    class Compiler # :nodoc: 
.. 
class Buffer # :nodoc: 
    def compile(s) 
    ... 
    #It stores in a buffer each ruby chunk in the views inside of a Buffer. 
    end 
end 
    end 
... 
# Here it is where is called compile method. 
# The thing is that if my view is made up of several *.html.erb files such as partials this method will be invoked each time.   
     #INVOKED PER EACH html.erb file 

def initialize(str, safe_level=nil, trim_mode=nil, eoutvar='_erbout') 
    puts ">>> initialize"  
    @safe_level = safe_level 
    # ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update(:default => "%d %b %Y") 
    compiler = ERB::Compiler.new(trim_mode) 
    # raise "need a block" 
    # ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update(:default => nil) 
    set_eoutvar(compiler, eoutvar) 
    @src = compiler.compile(str) 
    @filename = nil 
    end 
end 
end 

Je voudrais savoir quand le processus sur le fond commence. Je veux dire quelle classe, fichier, etc. je dois remplacer pour voir où Rails commence à invoquer tout html.erb pour une vue spécifique.

Je pense que je devrais être ici:

require 'delegate' 
require 'optparse' 
require 'fileutils' 
require 'tempfile' 
require 'erb' 

module Rails 
    module Generator 
    module Commands 

     class Create 

       # Generate a file for a Rails application using an ERuby template. 
       # Looks up and evaluates a template by name and writes the result. 
       # 
       # The ERB template uses explicit trim mode to best control the 
       # proliferation of whitespace in generated code. <%- trims leading 
       # whitespace; -%> trims trailing whitespace including one newline. 
       # 
       # A hash of template options may be passed as the last argument. 
       # The options accepted by the file are accepted as well as :assigns, 
       # a hash of variable bindings. Example: 
       # template 'foo', 'bar', :assigns => { :action => 'view' } 
       # 
       # Template is implemented in terms of file. It calls file with a 
       # block which takes a file handle and returns its rendered contents. 
       def template(relative_source, relative_destination, template_options = {}) 
       puts "EEEEEEEEEEEEEEEEEEEEEe" 
       file(relative_source, relative_destination, template_options) do |file| 
        # Evaluate any assignments in a temporary, throwaway binding. 
        vars = template_options[:assigns] || {} 
        b = template_options[:binding] || binding 
        vars.each { |k,v| eval "#{k} = vars[:#{k}] || vars['#{k}']", b } 

        # Render the source file with the temporary binding. 
        ERB.new(file.read, nil, '-').result(b) 
       end 
      end 

     end 

    end 
    end 
end 

Mais je ne trouve aucune trace de la méthode met.

Tous changement de nom sont placés dans un fichier appelé /lib/*_extensions.erb et /config/initializers/extensions.rb je la prochaine:

Dir[File.dirname(__FILE__) + "/../../lib/*_extensions.rb"].each do |fn| 
    require fn 
end 

Je ne veux pas révéler pourquoi je fais cela.

Merci

Répondre

0

Je voulais utiliser un before_render il n'existe pas au moins dans Rails 2.3.4.

Donc, si vous voulez le faire, je l'ai comme prochain:

class ApplicationController < ActionController::Base 
     helper :all # include all helpers, all the time 
     protect_from_forgery # See ActionController::RequestForgeryProtection for details 

     # Scrub sensitive parameters from your log 
     # filter_parameter_logging :password 

     protected 
     def render(options = nil, extra_options = {}, &block) #:doc: 
     puts "BEFORE render" 
     puts "Setting %H:%M:%S" 
     ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(:default => "%H:%M:%S") 
     # call the ActionController::Base render to show the page 
     super 
     puts "AFTER render" 
     puts "Resetting" 
     ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(:default => nil) 
     end 

end 
Questions connexes