erb.rb 713 字节
Newer Older
J
Jeremy Kemper 已提交
1
require 'active_support/core_ext/class/attribute_accessors'
2

3 4 5
module ActionView
  module TemplateHandlers
    class ERB < TemplateHandler
6 7
      include Compilable

P
Pratik Naik 已提交
8 9
      ##
      # :singleton-method:
10 11 12 13 14
      # Specify trim mode for the ERB compiler. Defaults to '-'.
      # See ERb documentation for suitable values.
      cattr_accessor :erb_trim_mode
      self.erb_trim_mode = '-'

15 16
      self.default_format = Mime::HTML

17
      def compile(template)
18 19
        require 'erb'

20 21 22
        magic = $1 if template.source =~ /\A(<%#.*coding:\s*(\S+)\s*-?%>)/
        erb = "#{magic}<% __in_erb_template=true %>#{template.source}"
        ::ERB.new(erb, nil, erb_trim_mode, '@output_buffer').src
23 24 25 26
      end
    end
  end
end