class Erubi::CaptureEndEngine
An engine class that supports capturing blocks via the <%|= and <%|== tags, explicitly ending the captures using <%| end %> blocks.
Public Class Methods
new(input, properties={})
click to toggle source
Initializes the engine. Accepts the same arguments as ::Erubi::Engine
, and these additional options:
- :escape_capture
-
Whether to make <%|= escape by default, and <%|== not escape by default, defaults to the same value as :escape.
Calls superclass method
Erubi::Engine::new
# File lib/erubi/capture_end.rb 13 def initialize(input, properties={}) 14 properties = Hash[properties] 15 escape = properties.fetch(:escape){properties.fetch(:escape_html, false)} 16 @escape_capture = properties.fetch(:escape_capture, escape) 17 @bufval = properties[:bufval] ||= 'String.new' 18 @bufstack = '__erubi_stack' 19 properties[:regexp] ||= /<%(\|?={1,2}|-|\#|%|\|)?(.*?)([-=])?%>([ \t]*\r?\n)?/m 20 super 21 end
Private Instance Methods
handle(indicator, code, tailch, rspace, lspace)
click to toggle source
Handle the <%|= and <%|== tags
Calls superclass method
Erubi::Engine#handle
# File lib/erubi/capture_end.rb 26 def handle(indicator, code, tailch, rspace, lspace) 27 case indicator 28 when '|=', '|==' 29 rspace = nil if tailch && !tailch.empty? 30 add_text(lspace) if lspace 31 escape_capture = !((indicator == '|=') ^ @escape_capture) 32 src << "begin; (#{@bufstack} ||= []) << #{@bufvar}; #{@bufvar} = #{@bufval}; #{@bufstack}.last << #{@escapefunc if escape_capture}((" << code 33 add_text(rspace) if rspace 34 when '|' 35 rspace = nil if tailch && !tailch.empty? 36 add_text(lspace) if lspace 37 src << code << ")).to_s; ensure; #{@bufvar} = #{@bufstack}.pop; end;" 38 add_text(rspace) if rspace 39 else 40 super 41 end 42 end