Class: Liquid::Capture

Inherits:
Block show all
Includes:
ParserSwitching
Defined in:
lib/liquid/tags/capture.rb

Constant Summary collapse

Syntax =
/(#{VariableSignature}+)/o

Constants inherited from Block

Block::MAX_DEPTH

Instance Attribute Summary collapse

Attributes inherited from Tag

#line_number, #nodelist, #parse_context, #tag_name

Instance Method Summary collapse

Methods included from ParserSwitching

#parse_with_selected_parser, #strict2_mode?, #strict_parse_with_error_mode_fallback

Methods inherited from Block

#block_delimiter, #block_name, #nodelist, #parse, #raise_tag_never_closed, raise_unknown_tag, #render, #unknown_tag

Methods inherited from Tag

disable_tags, #name, parse, #parse, #raw, #render

Constructor Details

#initialize(tag_name, markup, options) ⇒ Capture

Returns a new instance of Capture.



29
30
31
32
# File 'lib/liquid/tags/capture.rb', line 29

def initialize(tag_name, markup, options)
  super
  parse_with_selected_parser(markup)
end

Instance Attribute Details

#toObject (readonly)

Returns the value of attribute to.



27
28
29
# File 'lib/liquid/tags/capture.rb', line 27

def to
  @to
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/liquid/tags/capture.rb', line 60

def blank?
  true
end

#lax_parse(markup) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/liquid/tags/capture.rb', line 34

def lax_parse(markup)
  if markup =~ Syntax
    @to = Regexp.last_match(1)
  else
    raise SyntaxError, options[:locale].t("errors.syntax.capture")
  end
end

#render_to_output_buffer(context, output) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/liquid/tags/capture.rb', line 52

def render_to_output_buffer(context, output)
  context.resource_limits.with_capture do
    capture_output = render(context)
    context.scopes.last[@to] = capture_output
  end
  output
end

#strict2_parse(markup) ⇒ Object



46
47
48
49
50
# File 'lib/liquid/tags/capture.rb', line 46

def strict2_parse(markup)
  p = @parse_context.new_parser(markup.strip)
  @to = p.consume(:id)
  p.consume(:end_of_string)
end

#strict_parse(markup) ⇒ Object



42
43
44
# File 'lib/liquid/tags/capture.rb', line 42

def strict_parse(markup)
  lax_parse(markup)
end