# File lib/liquid/block.rb, line 8 def blank? @blank end
# File lib/liquid/block.rb, line 95 def block_delimiter @block_delimiter ||= "end#{block_name}" end
# File lib/liquid/block.rb, line 91 def block_name @tag_name end
# File lib/liquid/block.rb, line 99 def create_variable(token) token.scan(ContentOfVariable) do |content| markup = token.is_a?(Token) ? token.child(content.first) : content.first return Variable.new(markup, @options) end raise SyntaxError.new(options[:locale].t("errors.syntax.variable_termination".freeze, :token => token, :tag_end => VariableEnd.inspect)) end
# File lib/liquid/block.rb, line 12 def parse(tokens) @blank = true @nodelist ||= [] @nodelist.clear while token = tokens.shift begin unless token.empty? case when token.start_with?(TAGSTART) if token =~ FullToken # if we found the proper block delimiter just end parsing here and let the outer block # proceed return if block_delimiter == $1 # fetch the tag from registered blocks if tag = Template.tags[$1] markup = token.is_a?(Token) ? token.child($2) : $2 new_tag = tag.parse($1, markup, tokens, @options) new_tag.line_number = token.line_number if token.is_a?(Token) @blank &&= new_tag.blank? @nodelist << new_tag else # this tag is not registered with the system # pass it to the current block for special handling or error reporting unknown_tag($1, $2, tokens) end else raise SyntaxError.new(options[:locale].t("errors.syntax.tag_termination".freeze, :token => token, :tag_end => TagEnd.inspect)) end when token.start_with?(VARSTART) new_var = create_variable(token) new_var.line_number = token.line_number if token.is_a?(Token) @nodelist << new_var @blank = false else @nodelist << token @blank &&= (token =~ /\A\s*\z/) end end rescue SyntaxError => e e.set_line_number_from_token(token) raise end end # Make sure that it's ok to end parsing in the current block. # Effectively this method will throw an exception unless the current block is # of type Document assert_missing_delimitation! end
# File lib/liquid/block.rb, line 107 def render(context) render_all(@nodelist, context) end
# File lib/liquid/profiler/hooks.rb, line 3 def render_token_with_profiling(token, context) Profiler.profile_token_render(token) do render_token_without_profiling(token, context) end end
# File lib/liquid/block.rb, line 77 def unknown_tag(tag, params, tokens) case tag when 'else'.freeze raise SyntaxError.new(options[:locale].t("errors.syntax.unexpected_else".freeze, :block_name => block_name)) when 'end'.freeze raise SyntaxError.new(options[:locale].t("errors.syntax.invalid_delimiter".freeze, :block_name => block_name, :block_delimiter => block_delimiter)) else raise SyntaxError.new(options[:locale].t("errors.syntax.unknown_tag".freeze, :tag => tag)) end end
warnings of this block and all sub-tags
# File lib/liquid/block.rb, line 66 def warnings all_warnings = [] all_warnings.concat(@warnings) if @warnings (nodelist || []).each do |node| all_warnings.concat(node.warnings || []) if node.respond_to?(:warnings) end all_warnings end
# File lib/liquid/block.rb, line 113 def assert_missing_delimitation! raise SyntaxError.new(options[:locale].t("errors.syntax.tag_never_closed".freeze, :block_name => block_name)) end
# File lib/liquid/block.rb, line 117 def render_all(list, context) output = [] context.resource_limits[:render_length_current] = 0 context.resource_limits[:render_score_current] += list.length list.each do |token| # Break out if we have any unhanded interrupts. break if context.has_interrupt? begin # If we get an Interrupt that means the block must stop processing. An # Interrupt is any command that stops block execution such as {% break %} # or {% continue %} if token.is_a? Continue or token.is_a? Break context.push_interrupt(token.interrupt) break end token_output = render_token(token, context) unless token.is_a?(Block) && token.blank? output << token_output end rescue MemoryError => e raise e rescue ::StandardError => e output << (context.handle_error(e, token)) end end output.join end
# File lib/liquid/block.rb, line 150 def render_token(token, context) token_output = (token.respond_to?(:render) ? token.render(context) : token) context.increment_used_resources(:render_length_current, token_output) if context.resource_limits_reached? context.resource_limits[:reached] = true raise MemoryError.new("Memory limits exceeded".freeze) end token_output end