Skip to content

Commit

Permalink
Merge pull request #46 from bcardiff/fix/initialize
Browse files Browse the repository at this point in the history
Fix initialize methods for 1.0.0

Thanks @bcardiff
  • Loading branch information
docelic authored Nov 16, 2020
2 parents 04debf5 + 4eb2d7d commit c42c77b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/liquid/blocks/assign.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module Liquid::Block
def initialize(@varname, @value)
end

def initialize(str : String)
if match = str.strip.match ASSIGN
def initialize(content : String)
if match = content.strip.match ASSIGN
@varname = match["varname"]
@value = Expression.new match["value"]
else
Expand Down
2 changes: 1 addition & 1 deletion src/liquid/blocks/block.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Liquid::Block
@children : Array(Node)
@children = Array(Node).new

abstract def initialize(content)
abstract def initialize(content : String)

def accept(visitor : Visitor)
visitor.visit self
Expand Down
2 changes: 1 addition & 1 deletion src/liquid/blocks/else.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Liquid::Block
def initialize
end

def initialize(str : String)
def initialize(content : String)
end
end
end
20 changes: 10 additions & 10 deletions src/liquid/blocks/expression.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ module Liquid::Block
@first : Expression
@filters : Array(Tuple(Filters::Filter, Array(Expression)?))

def initialize(str)
@raw = str
if match = str.match GFILTERED
def initialize(content : String)
@raw = content
if match = content.match GFILTERED
@first = Expression.new match["first"]
@filters = Array(Tuple(Filters::Filter, Array(Expression)?)).new
else
raise InvalidExpression.new "Invalid filter use :#{str}"
raise InvalidExpression.new "Invalid filter use :#{content}"
end
end
end
Expand All @@ -28,11 +28,11 @@ module Liquid::Block
getter inner
@inner : Bool

def initialize(str)
if match(str)
@inner = str == "true"
def initialize(content : String)
if match(content)
@inner = content == "true"
else
raise Exception.new "Invalid Boolean expression : #{str}"
raise Exception.new "Invalid Boolean expression : #{content}"
end
end

Expand All @@ -45,8 +45,8 @@ module Liquid::Block
getter var
@var : String

def initialize(var)
@var = var.strip
def initialize(content : String)
@var = content.strip
pre_cache
end

Expand Down
8 changes: 5 additions & 3 deletions src/liquid/blocks/include.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ module Liquid::Block
def initialize(@template_name, @template_vars)
end

def initialize(str : String)
if match = str.strip.match INCLUDE
def initialize(content : String)
content = content.strip

if match = content.match INCLUDE
@template_vars = {} of String => Expression
@template_name = match["template_name"].delete("\"")
@template_name += ".liquid" if File.extname(@template_name).empty?

if match["value"]?
varname = File.basename(@template_name, File.extname(@template_name))
@template_vars[varname] = Expression.new match["value"]
elsif groups = str.strip.scan INCLUDE_VARS
elsif groups = content.scan INCLUDE_VARS
groups.each do |group|
next if groups.empty?

Expand Down
4 changes: 2 additions & 2 deletions src/liquid/expressions.cr
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ module Liquid
left.not_nil!
end

def initialize(str : String)
@inner = case str
def initialize(content : String)
@inner = case content
when "and" then AND
when "or" then OR
else
Expand Down

0 comments on commit c42c77b

Please sign in to comment.