Refactor to create tags with a parse class method instead of new.

By moving parse out of the initializer, we can call super at the start of
the initializers for subclasses, and avoid the nasty allocate hack.
This commit is contained in:
Dylan Thacker-Smith
2014-03-20 16:10:10 -04:00
parent e190bbba9e
commit d4ecaff8b8
18 changed files with 44 additions and 49 deletions
+3 -3
View File
@@ -1,15 +1,15 @@
class CommentForm < Liquid::Block
Syntax = /(#{Liquid::VariableSignature}+)/
def initialize(tag_name, markup, tokens)
def initialize(tag_name, markup, options)
super
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)
+3 -3
View File
@@ -1,7 +1,9 @@
class Paginate < Liquid::Block
Syntax = /(#{Liquid::QuotedFragment})\s*(by\s*(\d+))?/
def initialize(tag_name, markup, tokens)
def initialize(tag_name, markup, options)
super
@nodelist = []
if markup =~ Syntax
@@ -19,8 +21,6 @@ class Paginate < Liquid::Block
else
raise SyntaxError.new("Syntax Error in tag 'paginate' - Valid syntax: paginate [collection] by number")
end
super
end
def render(context)