Sha256: 5c2511fd5b31b2968660d1b4c85a0f23a3c378b1188635a4333f346f2d0e803b

Contents?: true

Size: 1008 Bytes

Versions: 1

Compression:

Stored size: 1008 Bytes

Contents

###
### $Rev: 102 $
### $Release: 2.6.4 $
### copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
###

require 'cgi'


module Erubis


  ##
  ## for preprocessing
  ##
  class PreprocessingEruby < Erubis::Eruby

    def initialize(input, params={})
      params = params.dup
      params[:pattern] ||= '\[% %\]'    # use '[%= %]' instead of '<%= %>'
      #params[:escape] = true            # transport '[%= %]' and '[%== %]'
      super
    end

    def add_expr_escaped(src, code)
      add_expr_literal(src, "_decode((#{code}))")
    end

  end


  ##
  ## helper methods for preprocessing
  ##
  module PreprocessingHelper

    module_function

    def _p(arg)
      return "<%=#{arg}%>"
    end

    def _P(arg)
      return "<%=h(#{arg})%>"
    end

    alias _? _p

    def _decode(arg)
      arg = arg.to_s
      arg.gsub!(/%3C%25(?:=|%3D)(.*?)%25%3E/) { "<%=#{CGI.unescape($1)}%>" }
      arg.gsub!(/&lt;%=(.*?)%&gt;/) { "<%=#{CGI.unescapeHTML($1)}%>" }
      return arg
    end

  end


end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
erubis-2.6.4 lib/erubis/preprocessing.rb