Class: CommentForm

Inherits:
Liquid::Block show all
Defined in:
lib/generators/liquid_cms/templates/vendor/plugins/liquid/performance/shopify/comment_form.rb

Constant Summary collapse

Syntax =
/(#{Liquid::VariableSignature}+)/

Constants inherited from Liquid::Block

Liquid::Block::ContentOfVariable, Liquid::Block::FullToken, Liquid::Block::IsTag, Liquid::Block::IsVariable

Instance Attribute Summary

Attributes inherited from Liquid::Tag

#nodelist

Instance Method Summary collapse

Methods inherited from Liquid::Block

#block_delimiter, #block_name, #create_variable, #end_tag, #parse, #unknown_tag

Methods inherited from Liquid::Tag

#name, #parse

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ CommentForm

Returns a new instance of CommentForm.



4
5
6
7
8
9
10
11
12
13
# File 'lib/generators/liquid_cms/templates/vendor/plugins/liquid/performance/shopify/comment_form.rb', line 4

def initialize(tag_name, markup, tokens)
  if markup =~ Syntax
    @variable_name = $1
    @attributes = {}
  else
    raise SyntaxError.new("Syntax Error in 'comment_form' - Valid syntax: comment_form [article]")
  end
  
  super
end

Instance Method Details

#render(context) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/generators/liquid_cms/templates/vendor/plugins/liquid/performance/shopify/comment_form.rb', line 15

def render(context)          
  article = context[@variable_name]
            
  context.stack do       
    context['form'] = {
      'posted_successfully?' => context.registers[:posted_successfully],
      'errors' => context['comment.errors'],
      'author' => context['comment.author'],
      'email'  => context['comment.email'],
      'body'   => context['comment.body']
    }
    wrap_in_form(article, render_all(@nodelist, context))
  end
end

#wrap_in_form(article, input) ⇒ Object



30
31
32
# File 'lib/generators/liquid_cms/templates/vendor/plugins/liquid/performance/shopify/comment_form.rb', line 30

def wrap_in_form(article, input)    
  %Q{<form id="article-#{article.id}-comment-form" class="comment-form" method="post" action="">\n#{input}\n</form>}    
end