Class: ThemeCheck::Tags::Form

Inherits:
Liquid::Block
  • Object
show all
Defined in:
lib/theme_check/tags.rb

Defined Under Namespace

Classes: ParseTreeVisitor

Constant Summary collapse

TAG_ATTRIBUTES =
/([\w\-]+)\s*:\s*(#{Liquid::QuotedFragment})/o
FORM_FORMAT =

Matches forms with arguments:

'type', object
'type', object, key: value, ...
'type', key: value, ...

old format: form product new format: form “product”, product, id: “newID”, class: “custom-class”, data-example: “100”

%r{
  (?<type>#{Liquid::QuotedFragment})
  (?:\s*,\s*(?<variable_name>#{Liquid::VariableSignature}+)(?!:))?
  (?<attributes>(?:\s*,\s*(?:#{TAG_ATTRIBUTES}))*)\s*\Z
}xo

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, options) ⇒ Form

Returns a new instance of Form.

Raises:

  • (Liquid::SyntaxError)


42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/theme_check/tags.rb', line 42

def initialize(tag_name, markup, options)
  super
  @match = FORM_FORMAT.match(markup)
  raise Liquid::SyntaxError, "in 'form' - Valid syntax: form 'type'[, object]" unless @match
  @type_expr = parse_expression(@match[:type])
  @variable_name_expr = parse_expression(@match[:variable_name])
  tag_attributes = @match[:attributes].scan(TAG_ATTRIBUTES)
  tag_attributes.each do |kv_pair|
    kv_pair[1] = parse_expression(kv_pair[1])
  end
  @tag_attributes = tag_attributes
end

Instance Attribute Details

#tag_attributesObject (readonly)

Returns the value of attribute tag_attributes.



40
41
42
# File 'lib/theme_check/tags.rb', line 40

def tag_attributes
  @tag_attributes
end

#type_exprObject (readonly)

Returns the value of attribute type_expr.



40
41
42
# File 'lib/theme_check/tags.rb', line 40

def type_expr
  @type_expr
end

#variable_name_exprObject (readonly)

Returns the value of attribute variable_name_expr.



40
41
42
# File 'lib/theme_check/tags.rb', line 40

def variable_name_expr
  @variable_name_expr
end