Sha256: 7db24157911813b3b584306e18acdf0749107d469af0ec4220c74adc6bb0c9c0

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

class CommentForm < Liquor::Block                                             
  Syntax = /(#{Liquor::VariableSignature}+)/   

  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

  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          
    
  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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
liquor-0.1.1 performance/shopify/comment_form.rb
liquor-0.1.0 performance/shopify/comment_form.rb