mirror of
https://github.com/Shopify/liquid.git
synced 2025-12-21 00:00:38 -05:00
Freeze all the things
This commit is contained in:
parent
0388376925
commit
43ac8d560b
@ -21,9 +21,9 @@
|
|||||||
|
|
||||||
module Liquid
|
module Liquid
|
||||||
FilterSeparator = /\|/
|
FilterSeparator = /\|/
|
||||||
ArgumentSeparator = ','
|
ArgumentSeparator = ','.freeze
|
||||||
FilterArgumentSeparator = ':'
|
FilterArgumentSeparator = ':'.freeze
|
||||||
VariableAttributeSeparator = '.'
|
VariableAttributeSeparator = '.'.freeze
|
||||||
TagStart = /\{\%/
|
TagStart = /\{\%/
|
||||||
TagEnd = /\%\}/
|
TagEnd = /\%\}/
|
||||||
VariableSignature = /\(?[\w\-\.\[\]]\)?/
|
VariableSignature = /\(?[\w\-\.\[\]]\)?/
|
||||||
|
|||||||
@ -41,14 +41,14 @@ module Liquid
|
|||||||
unknown_tag($1, $2, tokens)
|
unknown_tag($1, $2, tokens)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
raise SyntaxError.new(options[:locale].t("errors.syntax.tag_termination", :token => token, :tag_end => TagEnd.inspect))
|
raise SyntaxError.new(options[:locale].t("errors.syntax.tag_termination".freeze, :token => token, :tag_end => TagEnd.inspect))
|
||||||
end
|
end
|
||||||
when IsVariable
|
when IsVariable
|
||||||
new_var = create_variable(token)
|
new_var = create_variable(token)
|
||||||
@nodelist << new_var
|
@nodelist << new_var
|
||||||
@children << new_var
|
@children << new_var
|
||||||
@blank = false
|
@blank = false
|
||||||
when ''
|
when ''.freeze
|
||||||
# pass
|
# pass
|
||||||
else
|
else
|
||||||
@nodelist << token
|
@nodelist << token
|
||||||
@ -79,20 +79,20 @@ module Liquid
|
|||||||
|
|
||||||
def unknown_tag(tag, params, tokens)
|
def unknown_tag(tag, params, tokens)
|
||||||
case tag
|
case tag
|
||||||
when 'else'
|
when 'else'.freeze
|
||||||
raise SyntaxError.new(options[:locale].t("errors.syntax.unexpected_else",
|
raise SyntaxError.new(options[:locale].t("errors.syntax.unexpected_else".freeze,
|
||||||
:block_name => block_name))
|
:block_name => block_name))
|
||||||
when 'end'
|
when 'end'.freeze
|
||||||
raise SyntaxError.new(options[:locale].t("errors.syntax.invalid_delimiter",
|
raise SyntaxError.new(options[:locale].t("errors.syntax.invalid_delimiter".freeze,
|
||||||
:block_name => block_name,
|
:block_name => block_name,
|
||||||
:block_delimiter => block_delimiter))
|
:block_delimiter => block_delimiter))
|
||||||
else
|
else
|
||||||
raise SyntaxError.new(options[:locale].t("errors.syntax.unknown_tag", :tag => tag))
|
raise SyntaxError.new(options[:locale].t("errors.syntax.unknown_tag".freeze, :tag => tag))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def block_delimiter
|
def block_delimiter
|
||||||
"end#{block_name}"
|
"end#{block_name}".freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
def block_name
|
def block_name
|
||||||
@ -103,7 +103,7 @@ module Liquid
|
|||||||
token.scan(ContentOfVariable) do |content|
|
token.scan(ContentOfVariable) do |content|
|
||||||
return Variable.new(content.first, @options)
|
return Variable.new(content.first, @options)
|
||||||
end
|
end
|
||||||
raise SyntaxError.new(options[:locale].t("errors.syntax.variable_termination", :token => token, :tag_end => VariableEnd.inspect))
|
raise SyntaxError.new(options[:locale].t("errors.syntax.variable_termination".freeze, :token => token, :tag_end => VariableEnd.inspect))
|
||||||
end
|
end
|
||||||
|
|
||||||
def render(context)
|
def render(context)
|
||||||
@ -113,7 +113,7 @@ module Liquid
|
|||||||
protected
|
protected
|
||||||
|
|
||||||
def assert_missing_delimitation!
|
def assert_missing_delimitation!
|
||||||
raise SyntaxError.new(options[:locale].t("errors.syntax.tag_never_closed", :block_name => block_name))
|
raise SyntaxError.new(options[:locale].t("errors.syntax.tag_never_closed".freeze, :block_name => block_name))
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_all(list, context)
|
def render_all(list, context)
|
||||||
@ -138,7 +138,7 @@ module Liquid
|
|||||||
context.resource_limits[:render_length_current] += (token_output.respond_to?(:length) ? token_output.length : 1)
|
context.resource_limits[:render_length_current] += (token_output.respond_to?(:length) ? token_output.length : 1)
|
||||||
if context.resource_limits_reached?
|
if context.resource_limits_reached?
|
||||||
context.resource_limits[:reached] = true
|
context.resource_limits[:reached] = true
|
||||||
raise MemoryError.new("Memory limits exceeded")
|
raise MemoryError.new("Memory limits exceeded".freeze)
|
||||||
end
|
end
|
||||||
unless token.is_a?(Block) && token.blank?
|
unless token.is_a?(Block) && token.blank?
|
||||||
output << token_output
|
output << token_output
|
||||||
|
|||||||
@ -8,14 +8,14 @@ module Liquid
|
|||||||
#
|
#
|
||||||
class Condition #:nodoc:
|
class Condition #:nodoc:
|
||||||
@@operators = {
|
@@operators = {
|
||||||
'==' => lambda { |cond, left, right| cond.send(:equal_variables, left, right) },
|
'=='.freeze => lambda { |cond, left, right| cond.send(:equal_variables, left, right) },
|
||||||
'!=' => lambda { |cond, left, right| !cond.send(:equal_variables, left, right) },
|
'!='.freeze => lambda { |cond, left, right| !cond.send(:equal_variables, left, right) },
|
||||||
'<>' => lambda { |cond, left, right| !cond.send(:equal_variables, left, right) },
|
'<>'.freeze => lambda { |cond, left, right| !cond.send(:equal_variables, left, right) },
|
||||||
'<' => :<,
|
'<'.freeze => :<,
|
||||||
'>' => :>,
|
'>'.freeze => :>,
|
||||||
'>=' => :>=,
|
'>='.freeze => :>=,
|
||||||
'<=' => :<=,
|
'<='.freeze => :<=,
|
||||||
'contains' => lambda { |cond, left, right| left && right ? left.include?(right) : false }
|
'contains'.freeze => lambda { |cond, left, right| left && right ? left.include?(right) : false }
|
||||||
}
|
}
|
||||||
|
|
||||||
def self.operators
|
def self.operators
|
||||||
@ -61,7 +61,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def inspect
|
def inspect
|
||||||
"#<Condition #{[@left, @operator, @right].compact.join(' ')}>"
|
"#<Condition #{[@left, @operator, @right].compact.join(' '.freeze)}>".freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@ -94,7 +94,7 @@ module Liquid
|
|||||||
|
|
||||||
left, right = context[left], context[right]
|
left, right = context[left], context[right]
|
||||||
|
|
||||||
operation = self.class.operators[op] || raise(ArgumentError.new("Unknown operator #{op}"))
|
operation = self.class.operators[op] || raise(ArgumentError.new("Unknown operator #{op}".freeze))
|
||||||
|
|
||||||
if operation.respond_to?(:call)
|
if operation.respond_to?(:call)
|
||||||
operation.call(self, left, right)
|
operation.call(self, left, right)
|
||||||
|
|||||||
@ -45,7 +45,7 @@ module Liquid
|
|||||||
def add_filters(filters)
|
def add_filters(filters)
|
||||||
filters = [filters].flatten.compact
|
filters = [filters].flatten.compact
|
||||||
filters.each do |f|
|
filters.each do |f|
|
||||||
raise ArgumentError, "Expected module but got: #{f.class}" unless f.is_a?(Module)
|
raise ArgumentError, "Expected module but got: #{f.class}".freeze unless f.is_a?(Module)
|
||||||
Strainer.add_known_filter(f)
|
Strainer.add_known_filter(f)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -82,9 +82,9 @@ module Liquid
|
|||||||
|
|
||||||
case e
|
case e
|
||||||
when SyntaxError
|
when SyntaxError
|
||||||
"Liquid syntax error: #{e.message}"
|
"Liquid syntax error: #{e.message}".freeze
|
||||||
else
|
else
|
||||||
"Liquid error: #{e.message}"
|
"Liquid error: #{e.message}".freeze
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ module Liquid
|
|||||||
# Push new local scope on the stack. use <tt>Context#stack</tt> instead
|
# Push new local scope on the stack. use <tt>Context#stack</tt> instead
|
||||||
def push(new_scope={})
|
def push(new_scope={})
|
||||||
@scopes.unshift(new_scope)
|
@scopes.unshift(new_scope)
|
||||||
raise StackLevelError, "Nesting too deep" if @scopes.length > 100
|
raise StackLevelError, "Nesting too deep".freeze if @scopes.length > 100
|
||||||
end
|
end
|
||||||
|
|
||||||
# Merge a hash of variables in the current local scope
|
# Merge a hash of variables in the current local scope
|
||||||
@ -143,11 +143,11 @@ module Liquid
|
|||||||
|
|
||||||
private
|
private
|
||||||
LITERALS = {
|
LITERALS = {
|
||||||
nil => nil, 'nil' => nil, 'null' => nil, '' => nil,
|
nil => nil, 'nil'.freeze => nil, 'null'.freeze => nil, ''.freeze => nil,
|
||||||
'true' => true,
|
'true'.freeze => true,
|
||||||
'false' => false,
|
'false'.freeze => false,
|
||||||
'blank' => :blank?,
|
'blank'.freeze => :blank?,
|
||||||
'empty' => :empty?
|
'empty'.freeze => :empty?
|
||||||
}
|
}
|
||||||
|
|
||||||
# Look up variable, either resolve directly after considering the name. We can directly handle
|
# Look up variable, either resolve directly after considering the name. We can directly handle
|
||||||
@ -236,7 +236,7 @@ module Liquid
|
|||||||
# Some special cases. If the part wasn't in square brackets and
|
# Some special cases. If the part wasn't in square brackets and
|
||||||
# no key with the same name was found we interpret following calls
|
# no key with the same name was found we interpret following calls
|
||||||
# as commands and call them on the current object
|
# as commands and call them on the current object
|
||||||
elsif !part_resolved and object.respond_to?(part) and ['size', 'first', 'last'].include?(part)
|
elsif !part_resolved and object.respond_to?(part) and ['size'.freeze, 'first'.freeze, 'last'.freeze].include?(part)
|
||||||
|
|
||||||
object = object.send(part.intern).to_liquid
|
object = object.send(part.intern).to_liquid
|
||||||
|
|
||||||
|
|||||||
@ -44,28 +44,28 @@ module Liquid
|
|||||||
class LocalFileSystem
|
class LocalFileSystem
|
||||||
attr_accessor :root
|
attr_accessor :root
|
||||||
|
|
||||||
def initialize(root, pattern = "_%s.liquid")
|
def initialize(root, pattern = "_%s.liquid".freeze)
|
||||||
@root = root
|
@root = root
|
||||||
@pattern = pattern
|
@pattern = pattern
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_template_file(template_path, context)
|
def read_template_file(template_path, context)
|
||||||
full_path = full_path(template_path)
|
full_path = full_path(template_path)
|
||||||
raise FileSystemError, "No such template '#{template_path}'" unless File.exists?(full_path)
|
raise FileSystemError, "No such template '#{template_path}'".freeze unless File.exists?(full_path)
|
||||||
|
|
||||||
File.read(full_path)
|
File.read(full_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def full_path(template_path)
|
def full_path(template_path)
|
||||||
raise FileSystemError, "Illegal template name '#{template_path}'" unless template_path =~ /^[^.\/][a-zA-Z0-9_\/]+$/
|
raise FileSystemError, "Illegal template name '#{template_path}'".freeze unless template_path =~ /^[^.\/][a-zA-Z0-9_\/]+$/
|
||||||
|
|
||||||
full_path = if template_path.include?('/')
|
full_path = if template_path.include?('/'.freeze)
|
||||||
File.join(root, File.dirname(template_path), @pattern % File.basename(template_path))
|
File.join(root, File.dirname(template_path), @pattern % File.basename(template_path))
|
||||||
else
|
else
|
||||||
File.join(root, @pattern % template_path)
|
File.join(root, @pattern % template_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
raise FileSystemError, "Illegal template path '#{File.expand_path(full_path)}'" unless File.expand_path(full_path) =~ /^#{File.expand_path(root)}/
|
raise FileSystemError, "Illegal template path '#{File.expand_path(full_path)}'".freeze unless File.expand_path(full_path) =~ /^#{File.expand_path(root)}/
|
||||||
|
|
||||||
full_path
|
full_path
|
||||||
end
|
end
|
||||||
|
|||||||
@ -11,23 +11,23 @@ module Liquid
|
|||||||
@attributes[key] = value
|
@attributes[key] = value
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
raise SyntaxError.new(options[:locale].t("errors.syntax.table_row"))
|
raise SyntaxError.new(options[:locale].t("errors.syntax.table_row".freeze))
|
||||||
end
|
end
|
||||||
|
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
def render(context)
|
def render(context)
|
||||||
collection = context[@collection_name] or return ''
|
collection = context[@collection_name] or return ''.freeze
|
||||||
|
|
||||||
from = @attributes['offset'] ? context[@attributes['offset']].to_i : 0
|
from = @attributes['offset'.freeze] ? context[@attributes['offset'.freeze]].to_i : 0
|
||||||
to = @attributes['limit'] ? from + context[@attributes['limit']].to_i : nil
|
to = @attributes['limit'.freeze] ? from + context[@attributes['limit'.freeze]].to_i : nil
|
||||||
|
|
||||||
collection = Utils.slice_collection(collection, from, to)
|
collection = Utils.slice_collection(collection, from, to)
|
||||||
|
|
||||||
length = collection.length
|
length = collection.length
|
||||||
|
|
||||||
cols = context[@attributes['cols']].to_i
|
cols = context[@attributes['cols'.freeze]].to_i
|
||||||
|
|
||||||
row = 1
|
row = 1
|
||||||
col = 0
|
col = 0
|
||||||
@ -37,19 +37,19 @@ module Liquid
|
|||||||
|
|
||||||
collection.each_with_index do |item, index|
|
collection.each_with_index do |item, index|
|
||||||
context[@variable_name] = item
|
context[@variable_name] = item
|
||||||
context['tablerowloop'] = {
|
context['tablerowloop'.freeze] = {
|
||||||
'length' => length,
|
'length'.freeze => length,
|
||||||
'index' => index + 1,
|
'index'.freeze => index + 1,
|
||||||
'index0' => index,
|
'index0'.freeze => index,
|
||||||
'col' => col + 1,
|
'col'.freeze => col + 1,
|
||||||
'col0' => col,
|
'col0'.freeze => col,
|
||||||
'index0' => index,
|
'index0'.freeze => index,
|
||||||
'rindex' => length - index,
|
'rindex'.freeze => length - index,
|
||||||
'rindex0' => length - index - 1,
|
'rindex0'.freeze => length - index - 1,
|
||||||
'first' => (index == 0),
|
'first'.freeze => (index == 0),
|
||||||
'last' => (index == length - 1),
|
'last'.freeze => (index == length - 1),
|
||||||
'col_first' => (col == 0),
|
'col_first'.freeze => (col == 0),
|
||||||
'col_last' => (col == cols - 1)
|
'col_last'.freeze => (col == cols - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -70,5 +70,5 @@ module Liquid
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Template.register_tag('tablerow', TableRow)
|
Template.register_tag('tablerow'.freeze, TableRow)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -6,7 +6,7 @@ module Liquid
|
|||||||
|
|
||||||
class TranslationError < StandardError
|
class TranslationError < StandardError
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :path
|
attr_reader :path
|
||||||
|
|
||||||
def initialize(path = DEFAULT_LOCALE)
|
def initialize(path = DEFAULT_LOCALE)
|
||||||
@ -31,7 +31,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def deep_fetch_translation(name)
|
def deep_fetch_translation(name)
|
||||||
name.split('.').reduce(locale) do |level, cur|
|
name.split('.'.freeze).reduce(locale) do |level, cur|
|
||||||
level[cur] or raise TranslationError, "Translation for #{name} does not exist in locale #{path}"
|
level[cur] or raise TranslationError, "Translation for #{name} does not exist in locale #{path}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -5,7 +5,7 @@ module Liquid
|
|||||||
attr_reader :message
|
attr_reader :message
|
||||||
|
|
||||||
def initialize(message=nil)
|
def initialize(message=nil)
|
||||||
@message = message || "interrupt"
|
@message = message || "interrupt".freeze
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -2,14 +2,14 @@ require "strscan"
|
|||||||
module Liquid
|
module Liquid
|
||||||
class Lexer
|
class Lexer
|
||||||
SPECIALS = {
|
SPECIALS = {
|
||||||
'|' => :pipe,
|
'|'.freeze => :pipe,
|
||||||
'.' => :dot,
|
'.'.freeze => :dot,
|
||||||
':' => :colon,
|
':'.freeze => :colon,
|
||||||
',' => :comma,
|
','.freeze => :comma,
|
||||||
'[' => :open_square,
|
'['.freeze => :open_square,
|
||||||
']' => :close_square,
|
']'.freeze => :close_square,
|
||||||
'(' => :open_round,
|
'('.freeze => :open_round,
|
||||||
')' => :close_round
|
')'.freeze => :close_round
|
||||||
}
|
}
|
||||||
IDENTIFIER = /[\w\-?!]+/
|
IDENTIFIER = /[\w\-?!]+/
|
||||||
SINGLE_STRING_LITERAL = /'[^\']*'/
|
SINGLE_STRING_LITERAL = /'[^\']*'/
|
||||||
|
|||||||
@ -43,7 +43,7 @@
|
|||||||
class Module
|
class Module
|
||||||
|
|
||||||
def liquid_methods(*allowed_methods)
|
def liquid_methods(*allowed_methods)
|
||||||
drop_class = eval "class #{self.to_s}::LiquidDropClass < Liquid::Drop; self; end"
|
drop_class = eval "class #{self.to_s}::LiquidDropClass < Liquid::Drop; self; end".freeze
|
||||||
define_method :to_liquid do
|
define_method :to_liquid do
|
||||||
drop_class.new(self)
|
drop_class.new(self)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -56,7 +56,7 @@ module Liquid
|
|||||||
consume(:dotdot)
|
consume(:dotdot)
|
||||||
last = expression
|
last = expression
|
||||||
consume(:close_round)
|
consume(:close_round)
|
||||||
"(#{first}..#{last})"
|
"(#{first}..#{last})".freeze
|
||||||
else
|
else
|
||||||
raise SyntaxError, "#{token} is not a valid expression"
|
raise SyntaxError, "#{token} is not a valid expression"
|
||||||
end
|
end
|
||||||
@ -66,10 +66,11 @@ module Liquid
|
|||||||
str = ""
|
str = ""
|
||||||
# might be a keyword argument (identifier: expression)
|
# might be a keyword argument (identifier: expression)
|
||||||
if look(:id) && look(:colon, 1)
|
if look(:id) && look(:colon, 1)
|
||||||
str << consume << consume << ' '
|
str << consume << consume << ' '.freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
str << expression
|
str << expression
|
||||||
|
str.freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
def variable_signature
|
def variable_signature
|
||||||
|
|||||||
@ -4,12 +4,17 @@ require 'bigdecimal'
|
|||||||
module Liquid
|
module Liquid
|
||||||
|
|
||||||
module StandardFilters
|
module StandardFilters
|
||||||
HTML_ESCAPE = { '&' => '&', '>' => '>', '<' => '<', '"' => '"', "'" => ''' }
|
HTML_ESCAPE = {
|
||||||
|
'&'.freeze => '&'.freeze,
|
||||||
|
'>'.freeze => '>'.freeze,
|
||||||
|
'<'.freeze => '<'.freeze,
|
||||||
|
'"'.freeze => '"'.freeze,
|
||||||
|
"'".freeze => '''.freeze
|
||||||
|
}
|
||||||
HTML_ESCAPE_ONCE_REGEXP = /["><']|&(?!([a-zA-Z]+|(#\d+));)/
|
HTML_ESCAPE_ONCE_REGEXP = /["><']|&(?!([a-zA-Z]+|(#\d+));)/
|
||||||
|
|
||||||
# Return the size of an array or of an string
|
# Return the size of an array or of an string
|
||||||
def size(input)
|
def size(input)
|
||||||
|
|
||||||
input.respond_to?(:size) ? input.size : 0
|
input.respond_to?(:size) ? input.size : 0
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -39,19 +44,19 @@ module Liquid
|
|||||||
alias_method :h, :escape
|
alias_method :h, :escape
|
||||||
|
|
||||||
# Truncate a string down to x characters
|
# Truncate a string down to x characters
|
||||||
def truncate(input, length = 50, truncate_string = "...")
|
def truncate(input, length = 50, truncate_string = "...".freeze)
|
||||||
if input.nil? then return end
|
if input.nil? then return end
|
||||||
l = length.to_i - truncate_string.length
|
l = length.to_i - truncate_string.length
|
||||||
l = 0 if l < 0
|
l = 0 if l < 0
|
||||||
input.length > length.to_i ? input[0...l] + truncate_string : input
|
input.length > length.to_i ? input[0...l] + truncate_string : input
|
||||||
end
|
end
|
||||||
|
|
||||||
def truncatewords(input, words = 15, truncate_string = "...")
|
def truncatewords(input, words = 15, truncate_string = "...".freeze)
|
||||||
if input.nil? then return end
|
if input.nil? then return end
|
||||||
wordlist = input.to_s.split
|
wordlist = input.to_s.split
|
||||||
l = words.to_i - 1
|
l = words.to_i - 1
|
||||||
l = 0 if l < 0
|
l = 0 if l < 0
|
||||||
wordlist.length > l ? wordlist[0..l].join(" ") + truncate_string : input
|
wordlist.length > l ? wordlist[0..l].join(" ".freeze) + truncate_string : input
|
||||||
end
|
end
|
||||||
|
|
||||||
# Split input string into an array of substrings separated by given pattern.
|
# Split input string into an array of substrings separated by given pattern.
|
||||||
@ -64,16 +69,17 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def strip_html(input)
|
def strip_html(input)
|
||||||
input.to_s.gsub(/<script.*?<\/script>/m, '').gsub(/<!--.*?-->/m, '').gsub(/<style.*?<\/style>/m, '').gsub(/<.*?>/m, '')
|
empty = ''.freeze
|
||||||
|
input.to_s.gsub(/<script.*?<\/script>/m, empty).gsub(/<!--.*?-->/m, empty).gsub(/<style.*?<\/style>/m, empty).gsub(/<.*?>/m, empty)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Remove all newlines from the string
|
# Remove all newlines from the string
|
||||||
def strip_newlines(input)
|
def strip_newlines(input)
|
||||||
input.to_s.gsub(/\r?\n/, '')
|
input.to_s.gsub(/\r?\n/, ''.freeze)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Join elements of the array with certain character between them
|
# Join elements of the array with certain character between them
|
||||||
def join(input, glue = ' ')
|
def join(input, glue = ' '.freeze)
|
||||||
[input].flatten.join(glue)
|
[input].flatten.join(glue)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -83,7 +89,7 @@ module Liquid
|
|||||||
ary = flatten_if_necessary(input)
|
ary = flatten_if_necessary(input)
|
||||||
if property.nil?
|
if property.nil?
|
||||||
ary.sort
|
ary.sort
|
||||||
elsif ary.first.respond_to?('[]') and !ary.first[property].nil?
|
elsif ary.first.respond_to?('[]'.freeze) and !ary.first[property].nil?
|
||||||
ary.sort {|a,b| a[property] <=> b[property] }
|
ary.sort {|a,b| a[property] <=> b[property] }
|
||||||
elsif ary.first.respond_to?(property)
|
elsif ary.first.respond_to?(property)
|
||||||
ary.sort {|a,b| a.send(property) <=> b.send(property) }
|
ary.sort {|a,b| a.send(property) <=> b.send(property) }
|
||||||
@ -101,7 +107,7 @@ module Liquid
|
|||||||
flatten_if_necessary(input).map do |e|
|
flatten_if_necessary(input).map do |e|
|
||||||
e = e.call if e.is_a?(Proc)
|
e = e.call if e.is_a?(Proc)
|
||||||
|
|
||||||
if property == "to_liquid"
|
if property == "to_liquid".freeze
|
||||||
e
|
e
|
||||||
elsif e.respond_to?(:[])
|
elsif e.respond_to?(:[])
|
||||||
e[property]
|
e[property]
|
||||||
@ -110,23 +116,23 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Replace occurrences of a string with another
|
# Replace occurrences of a string with another
|
||||||
def replace(input, string, replacement = '')
|
def replace(input, string, replacement = ''.freeze)
|
||||||
input.to_s.gsub(string, replacement.to_s)
|
input.to_s.gsub(string, replacement.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Replace the first occurrences of a string with another
|
# Replace the first occurrences of a string with another
|
||||||
def replace_first(input, string, replacement = '')
|
def replace_first(input, string, replacement = ''.freeze)
|
||||||
input.to_s.sub(string, replacement.to_s)
|
input.to_s.sub(string, replacement.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
# remove a substring
|
# remove a substring
|
||||||
def remove(input, string)
|
def remove(input, string)
|
||||||
input.to_s.gsub(string, '')
|
input.to_s.gsub(string, ''.freeze)
|
||||||
end
|
end
|
||||||
|
|
||||||
# remove the first occurrences of a substring
|
# remove the first occurrences of a substring
|
||||||
def remove_first(input, string)
|
def remove_first(input, string)
|
||||||
input.to_s.sub(string, '')
|
input.to_s.sub(string, ''.freeze)
|
||||||
end
|
end
|
||||||
|
|
||||||
# add one string to another
|
# add one string to another
|
||||||
@ -141,7 +147,7 @@ module Liquid
|
|||||||
|
|
||||||
# Add <br /> tags in front of all newlines in input string
|
# Add <br /> tags in front of all newlines in input string
|
||||||
def newline_to_br(input)
|
def newline_to_br(input)
|
||||||
input.to_s.gsub(/\n/, "<br />\n")
|
input.to_s.gsub(/\n/, "<br />\n".freeze)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Reformat a date
|
# Reformat a date
|
||||||
@ -184,7 +190,7 @@ module Liquid
|
|||||||
|
|
||||||
date = if input.is_a?(String)
|
date = if input.is_a?(String)
|
||||||
case input.downcase
|
case input.downcase
|
||||||
when 'now', 'today'
|
when 'now'.freeze, 'today'.freeze
|
||||||
Time.now
|
Time.now
|
||||||
else
|
else
|
||||||
Time.parse(input)
|
Time.parse(input)
|
||||||
@ -244,7 +250,7 @@ module Liquid
|
|||||||
apply_operation(input, operand, :%)
|
apply_operation(input, operand, :%)
|
||||||
end
|
end
|
||||||
|
|
||||||
def default(input, default_value = "")
|
def default(input, default_value = "".freeze)
|
||||||
is_blank = input.respond_to?(:empty?) ? input.empty? : !input
|
is_blank = input.respond_to?(:empty?) ? input.empty? : !input
|
||||||
is_blank ? default_value : input
|
is_blank ? default_value : input
|
||||||
end
|
end
|
||||||
|
|||||||
@ -27,7 +27,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def render(context)
|
def render(context)
|
||||||
''
|
''.freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
def blank?
|
def blank?
|
||||||
|
|||||||
@ -16,7 +16,7 @@ module Liquid
|
|||||||
@to = $1
|
@to = $1
|
||||||
@from = Variable.new($2)
|
@from = Variable.new($2)
|
||||||
else
|
else
|
||||||
raise SyntaxError.new options[:locale].t("errors.syntax.assign")
|
raise SyntaxError.new options[:locale].t("errors.syntax.assign".freeze)
|
||||||
end
|
end
|
||||||
|
|
||||||
super
|
super
|
||||||
@ -26,7 +26,7 @@ module Liquid
|
|||||||
val = @from.render(context)
|
val = @from.render(context)
|
||||||
context.scopes.last[@to] = val
|
context.scopes.last[@to] = val
|
||||||
context.resource_limits[:assign_score_current] += (val.respond_to?(:length) ? val.length : 1)
|
context.resource_limits[:assign_score_current] += (val.respond_to?(:length) ? val.length : 1)
|
||||||
''
|
''.freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
def blank?
|
def blank?
|
||||||
@ -34,5 +34,5 @@ module Liquid
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Template.register_tag('assign', Assign)
|
Template.register_tag('assign'.freeze, Assign)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -17,5 +17,5 @@ module Liquid
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Template.register_tag('break', Break)
|
Template.register_tag('break'.freeze, Break)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -28,7 +28,7 @@ module Liquid
|
|||||||
output = super
|
output = super
|
||||||
context.scopes.last[@to] = output
|
context.scopes.last[@to] = output
|
||||||
context.resource_limits[:assign_score_current] += (output.respond_to?(:length) ? output.length : 1)
|
context.resource_limits[:assign_score_current] += (output.respond_to?(:length) ? output.length : 1)
|
||||||
''
|
''.freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
def blank?
|
def blank?
|
||||||
@ -36,5 +36,5 @@ module Liquid
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Template.register_tag('capture', Capture)
|
Template.register_tag('capture'.freeze, Capture)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -9,7 +9,7 @@ module Liquid
|
|||||||
if markup =~ Syntax
|
if markup =~ Syntax
|
||||||
@left = $1
|
@left = $1
|
||||||
else
|
else
|
||||||
raise SyntaxError.new(options[:locale].t("errors.syntax.case"))
|
raise SyntaxError.new(options[:locale].t("errors.syntax.case".freeze))
|
||||||
end
|
end
|
||||||
|
|
||||||
super
|
super
|
||||||
@ -18,9 +18,9 @@ module Liquid
|
|||||||
def unknown_tag(tag, markup, tokens)
|
def unknown_tag(tag, markup, tokens)
|
||||||
@nodelist = []
|
@nodelist = []
|
||||||
case tag
|
case tag
|
||||||
when 'when'
|
when 'when'.freeze
|
||||||
record_when_condition(markup)
|
record_when_condition(markup)
|
||||||
when 'else'
|
when 'else'.freeze
|
||||||
record_else_condition(markup)
|
record_else_condition(markup)
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
@ -50,12 +50,12 @@ module Liquid
|
|||||||
while markup
|
while markup
|
||||||
# Create a new nodelist and assign it to the new block
|
# Create a new nodelist and assign it to the new block
|
||||||
if not markup =~ WhenSyntax
|
if not markup =~ WhenSyntax
|
||||||
raise SyntaxError.new(options[:locale].t("errors.syntax.case_invalid_when"))
|
raise SyntaxError.new(options[:locale].t("errors.syntax.case_invalid_when".freeze))
|
||||||
end
|
end
|
||||||
|
|
||||||
markup = $2
|
markup = $2
|
||||||
|
|
||||||
block = Condition.new(@left, '==', $1)
|
block = Condition.new(@left, '=='.freeze, $1)
|
||||||
block.attach(@nodelist)
|
block.attach(@nodelist)
|
||||||
@blocks.push(block)
|
@blocks.push(block)
|
||||||
end
|
end
|
||||||
@ -63,7 +63,7 @@ module Liquid
|
|||||||
|
|
||||||
def record_else_condition(markup)
|
def record_else_condition(markup)
|
||||||
if not markup.strip.empty?
|
if not markup.strip.empty?
|
||||||
raise SyntaxError.new(options[:locale].t("errors.syntax.case_invalid_else"))
|
raise SyntaxError.new(options[:locale].t("errors.syntax.case_invalid_else".freeze))
|
||||||
end
|
end
|
||||||
|
|
||||||
block = ElseCondition.new
|
block = ElseCondition.new
|
||||||
@ -72,5 +72,5 @@ module Liquid
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Template.register_tag('case', Case)
|
Template.register_tag('case'.freeze, Case)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
module Liquid
|
module Liquid
|
||||||
class Comment < Block
|
class Comment < Block
|
||||||
def render(context)
|
def render(context)
|
||||||
''
|
''.freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
def unknown_tag(tag, markup, tokens)
|
def unknown_tag(tag, markup, tokens)
|
||||||
@ -12,5 +12,5 @@ module Liquid
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Template.register_tag('comment', Comment)
|
Template.register_tag('comment'.freeze, Comment)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
module Liquid
|
module Liquid
|
||||||
|
|
||||||
# Continue tag to be used to break out of a for loop.
|
# Continue tag to be used to break out of a for loop.
|
||||||
#
|
#
|
||||||
# == Basic Usage:
|
# == Basic Usage:
|
||||||
@ -10,12 +9,10 @@ module Liquid
|
|||||||
# {% endfor %}
|
# {% endfor %}
|
||||||
#
|
#
|
||||||
class Continue < Tag
|
class Continue < Tag
|
||||||
|
|
||||||
def interrupt
|
def interrupt
|
||||||
ContinueInterrupt.new
|
ContinueInterrupt.new
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Template.register_tag('continue', Continue)
|
Template.register_tag('continue'.freeze, Continue)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -24,7 +24,7 @@ module Liquid
|
|||||||
@variables = variables_from_string(markup)
|
@variables = variables_from_string(markup)
|
||||||
@name = "'#{@variables.to_s}'"
|
@name = "'#{@variables.to_s}'"
|
||||||
else
|
else
|
||||||
raise SyntaxError.new(options[:locale].t("errors.syntax.cycle"))
|
raise SyntaxError.new(options[:locale].t("errors.syntax.cycle".freeze))
|
||||||
end
|
end
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|||||||
@ -21,7 +21,6 @@ module Liquid
|
|||||||
class Decrement < Tag
|
class Decrement < Tag
|
||||||
def initialize(tag_name, markup, tokens)
|
def initialize(tag_name, markup, tokens)
|
||||||
@variable = markup.strip
|
@variable = markup.strip
|
||||||
|
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -35,5 +34,5 @@ module Liquid
|
|||||||
private
|
private
|
||||||
end
|
end
|
||||||
|
|
||||||
Template.register_tag('decrement', Decrement)
|
Template.register_tag('decrement'.freeze, Decrement)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -53,7 +53,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def unknown_tag(tag, markup, tokens)
|
def unknown_tag(tag, markup, tokens)
|
||||||
return super unless tag == 'else'
|
return super unless tag == 'else'.freeze
|
||||||
@nodelist = @else_block = []
|
@nodelist = @else_block = []
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -66,13 +66,13 @@ module Liquid
|
|||||||
# Maintains Ruby 1.8.7 String#each behaviour on 1.9
|
# Maintains Ruby 1.8.7 String#each behaviour on 1.9
|
||||||
return render_else(context) unless iterable?(collection)
|
return render_else(context) unless iterable?(collection)
|
||||||
|
|
||||||
from = if @attributes['offset'] == 'continue'
|
from = if @attributes['offset'.freeze] == 'continue'.freeze
|
||||||
context.registers[:for][@name].to_i
|
context.registers[:for][@name].to_i
|
||||||
else
|
else
|
||||||
context[@attributes['offset']].to_i
|
context[@attributes['offset'.freeze]].to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
limit = context[@attributes['limit']]
|
limit = context[@attributes['limit'.freeze]]
|
||||||
to = limit ? limit.to_i + from : nil
|
to = limit ? limit.to_i + from : nil
|
||||||
|
|
||||||
segment = Utils.slice_collection(collection, from, to)
|
segment = Utils.slice_collection(collection, from, to)
|
||||||
@ -91,15 +91,16 @@ module Liquid
|
|||||||
context.stack do
|
context.stack do
|
||||||
segment.each_with_index do |item, index|
|
segment.each_with_index do |item, index|
|
||||||
context[@variable_name] = item
|
context[@variable_name] = item
|
||||||
context['forloop'] = {
|
context['forloop'.freeze] = {
|
||||||
'name' => @name,
|
'name'.freeze => @name,
|
||||||
'length' => length,
|
'length'.freeze => length,
|
||||||
'index' => index + 1,
|
'index'.freeze => index + 1,
|
||||||
'index0' => index,
|
'index0'.freeze => index,
|
||||||
'rindex' => length - index,
|
'rindex'.freeze => length - index,
|
||||||
'rindex0' => length - index - 1,
|
'rindex0'.freeze => length - index - 1,
|
||||||
'first' => (index == 0),
|
'first'.freeze => (index == 0),
|
||||||
'last' => (index == length - 1) }
|
'last'.freeze => (index == length - 1)
|
||||||
|
}
|
||||||
|
|
||||||
result << render_all(@for_block, context)
|
result << render_all(@for_block, context)
|
||||||
|
|
||||||
@ -127,22 +128,22 @@ module Liquid
|
|||||||
@attributes[key] = value
|
@attributes[key] = value
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
raise SyntaxError.new(options[:locale].t("errors.syntax.for"))
|
raise SyntaxError.new(options[:locale].t("errors.syntax.for".freeze))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def strict_parse(markup)
|
def strict_parse(markup)
|
||||||
p = Parser.new(markup)
|
p = Parser.new(markup)
|
||||||
@variable_name = p.consume(:id)
|
@variable_name = p.consume(:id)
|
||||||
raise SyntaxError.new(options[:locale].t("errors.syntax.for_invalid_in")) unless p.id?('in')
|
raise SyntaxError.new(options[:locale].t("errors.syntax.for_invalid_in".freeze)) unless p.id?('in'.freeze)
|
||||||
@collection_name = p.expression
|
@collection_name = p.expression
|
||||||
@name = "#{@variable_name}-#{@collection_name}"
|
@name = "#{@variable_name}-#{@collection_name}"
|
||||||
@reversed = p.id?('reversed')
|
@reversed = p.id?('reversed'.freeze)
|
||||||
|
|
||||||
@attributes = {}
|
@attributes = {}
|
||||||
while p.look(:id) && p.look(:colon, 1)
|
while p.look(:id) && p.look(:colon, 1)
|
||||||
unless attribute = p.id?('limit') || p.id?('offset')
|
unless attribute = p.id?('limit'.freeze) || p.id?('offset'.freeze)
|
||||||
raise SyntaxError.new(options[:locale].t("errors.syntax.for_invalid_attribute"))
|
raise SyntaxError.new(options[:locale].t("errors.syntax.for_invalid_attribute".freeze))
|
||||||
end
|
end
|
||||||
p.consume
|
p.consume
|
||||||
val = p.expression
|
val = p.expression
|
||||||
@ -153,14 +154,14 @@ module Liquid
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def render_else(context)
|
def render_else(context)
|
||||||
return @else_block ? [render_all(@else_block, context)] : ''
|
return @else_block ? [render_all(@else_block, context)] : ''.freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
def iterable?(collection)
|
def iterable?(collection)
|
||||||
collection.respond_to?(:each) || Utils.non_blank_string?(collection)
|
collection.respond_to?(:each) || Utils.non_blank_string?(collection)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Template.register_tag('for', For)
|
Template.register_tag('for'.freeze, For)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -16,12 +16,12 @@ module Liquid
|
|||||||
|
|
||||||
def initialize(tag_name, markup, tokens)
|
def initialize(tag_name, markup, tokens)
|
||||||
@blocks = []
|
@blocks = []
|
||||||
push_block('if', markup)
|
push_block('if'.freeze, markup)
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
def unknown_tag(tag, markup, tokens)
|
def unknown_tag(tag, markup, tokens)
|
||||||
if ['elsif', 'else'].include?(tag)
|
if ['elsif'.freeze, 'else'.freeze].include?(tag)
|
||||||
push_block(tag, markup)
|
push_block(tag, markup)
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
@ -35,14 +35,14 @@ module Liquid
|
|||||||
return render_all(block.attachment, context)
|
return render_all(block.attachment, context)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
''
|
''.freeze
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def push_block(tag, markup)
|
def push_block(tag, markup)
|
||||||
block = if tag == 'else'
|
block = if tag == 'else'.freeze
|
||||||
ElseCondition.new
|
ElseCondition.new
|
||||||
else
|
else
|
||||||
parse_with_selected_parser(markup)
|
parse_with_selected_parser(markup)
|
||||||
@ -54,17 +54,17 @@ module Liquid
|
|||||||
|
|
||||||
def lax_parse(markup)
|
def lax_parse(markup)
|
||||||
expressions = markup.scan(ExpressionsAndOperators).reverse
|
expressions = markup.scan(ExpressionsAndOperators).reverse
|
||||||
raise(SyntaxError.new(options[:locale].t("errors.syntax.if"))) unless expressions.shift =~ Syntax
|
raise(SyntaxError.new(options[:locale].t("errors.syntax.if".freeze))) unless expressions.shift =~ Syntax
|
||||||
|
|
||||||
condition = Condition.new($1, $2, $3)
|
condition = Condition.new($1, $2, $3)
|
||||||
|
|
||||||
while not expressions.empty?
|
while not expressions.empty?
|
||||||
operator = (expressions.shift).to_s.strip
|
operator = (expressions.shift).to_s.strip
|
||||||
|
|
||||||
raise(SyntaxError.new(options[:locale].t("errors.syntax.if"))) unless expressions.shift.to_s =~ Syntax
|
raise(SyntaxError.new(options[:locale].t("errors.syntax.if".freeze))) unless expressions.shift.to_s =~ Syntax
|
||||||
|
|
||||||
new_condition = Condition.new($1, $2, $3)
|
new_condition = Condition.new($1, $2, $3)
|
||||||
raise(SyntaxError.new(options[:locale].t("errors.syntax.if"))) unless BOOLEAN_OPERATORS.include?(operator)
|
raise(SyntaxError.new(options[:locale].t("errors.syntax.if".freeze))) unless BOOLEAN_OPERATORS.include?(operator)
|
||||||
new_condition.send(operator, condition)
|
new_condition.send(operator, condition)
|
||||||
condition = new_condition
|
condition = new_condition
|
||||||
end
|
end
|
||||||
@ -77,7 +77,7 @@ module Liquid
|
|||||||
|
|
||||||
condition = parse_comparison(p)
|
condition = parse_comparison(p)
|
||||||
|
|
||||||
while op = (p.id?('and') || p.id?('or'))
|
while op = (p.id?('and'.freeze) || p.id?('or'.freeze))
|
||||||
new_cond = parse_comparison(p)
|
new_cond = parse_comparison(p)
|
||||||
new_cond.send(op, condition)
|
new_cond.send(op, condition)
|
||||||
condition = new_cond
|
condition = new_cond
|
||||||
@ -98,5 +98,5 @@ module Liquid
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Template.register_tag('if', If)
|
Template.register_tag('if'.freeze, If)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -10,11 +10,11 @@ module Liquid
|
|||||||
context.registers[:ifchanged] = output
|
context.registers[:ifchanged] = output
|
||||||
output
|
output
|
||||||
else
|
else
|
||||||
''
|
''.freeze
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Template.register_tag('ifchanged', Ifchanged)
|
Template.register_tag('ifchanged'.freeze, Ifchanged)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -29,7 +29,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
raise SyntaxError.new(options[:locale].t("errors.syntax.include"))
|
raise SyntaxError.new(options[:locale].t("errors.syntax.include".freeze))
|
||||||
end
|
end
|
||||||
|
|
||||||
super
|
super
|
||||||
@ -51,7 +51,7 @@ module Liquid
|
|||||||
context[key] = context[value]
|
context[key] = context[value]
|
||||||
end
|
end
|
||||||
|
|
||||||
context_variable_name = @template_name[1..-2].split('/').last
|
context_variable_name = @template_name[1..-2].split('/'.freeze).last
|
||||||
if variable.is_a?(Array)
|
if variable.is_a?(Array)
|
||||||
variable.collect do |var|
|
variable.collect do |var|
|
||||||
context[context_variable_name] = var
|
context[context_variable_name] = var
|
||||||
@ -94,5 +94,5 @@ module Liquid
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Template.register_tag('include', Include)
|
Template.register_tag('include'.freeze, Include)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -31,5 +31,5 @@ module Liquid
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Template.register_tag('increment', Increment)
|
Template.register_tag('increment'.freeze, Increment)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -7,7 +7,7 @@ module Liquid
|
|||||||
@nodelist.clear
|
@nodelist.clear
|
||||||
while token = tokens.shift
|
while token = tokens.shift
|
||||||
if token =~ FullTokenPossiblyInvalid
|
if token =~ FullTokenPossiblyInvalid
|
||||||
@nodelist << $1 if $1 != ""
|
@nodelist << $1 if $1 != "".freeze
|
||||||
if block_delimiter == $2
|
if block_delimiter == $2
|
||||||
end_tag
|
end_tag
|
||||||
return
|
return
|
||||||
@ -18,5 +18,5 @@ module Liquid
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Template.register_tag('raw', Raw)
|
Template.register_tag('raw'.freeze, Raw)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
require File.dirname(__FILE__) + '/if'
|
require File.dirname(__FILE__) + '/if'
|
||||||
|
|
||||||
module Liquid
|
module Liquid
|
||||||
|
|
||||||
# Unless is a conditional just like 'if' but works on the inverse logic.
|
# Unless is a conditional just like 'if' but works on the inverse logic.
|
||||||
#
|
#
|
||||||
# {% unless x < 0 %} x is greater than zero {% end %}
|
# {% unless x < 0 %} x is greater than zero {% end %}
|
||||||
@ -23,11 +22,10 @@ module Liquid
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
''
|
''.freeze
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Template.register_tag('unless'.freeze, Unless)
|
||||||
Template.register_tag('unless', Unless)
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -110,7 +110,7 @@ module Liquid
|
|||||||
# filters and tags and might be useful to integrate liquid more with its host application
|
# filters and tags and might be useful to integrate liquid more with its host application
|
||||||
#
|
#
|
||||||
def render(*args)
|
def render(*args)
|
||||||
return '' if @root.nil?
|
return ''.freeze if @root.nil?
|
||||||
|
|
||||||
context = case args.first
|
context = case args.first
|
||||||
when Liquid::Context
|
when Liquid::Context
|
||||||
|
|||||||
@ -10,7 +10,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.non_blank_string?(collection)
|
def self.non_blank_string?(collection)
|
||||||
collection.is_a?(String) && collection != ''
|
collection.is_a?(String) && collection != ''.freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.slice_collection_using_each(collection, from, to)
|
def self.slice_collection_using_each(collection, from, to)
|
||||||
|
|||||||
@ -19,7 +19,6 @@ module Liquid
|
|||||||
@markup = markup
|
@markup = markup
|
||||||
@name = nil
|
@name = nil
|
||||||
@options = options || {}
|
@options = options || {}
|
||||||
|
|
||||||
|
|
||||||
case @options[:error_mode] || Template.error_mode
|
case @options[:error_mode] || Template.error_mode
|
||||||
when :strict then strict_parse(markup)
|
when :strict then strict_parse(markup)
|
||||||
@ -63,7 +62,7 @@ module Liquid
|
|||||||
@filters = []
|
@filters = []
|
||||||
p = Parser.new(markup)
|
p = Parser.new(markup)
|
||||||
# Could be just filters with no input
|
# Could be just filters with no input
|
||||||
@name = p.look(:pipe) ? '' : p.expression
|
@name = p.look(:pipe) ? ''.freeze : p.expression
|
||||||
while p.consume?(:pipe)
|
while p.consume?(:pipe)
|
||||||
filtername = p.consume(:id)
|
filtername = p.consume(:id)
|
||||||
filterargs = p.consume?(:colon) ? parse_filterargs(p) : []
|
filterargs = p.consume?(:colon) ? parse_filterargs(p) : []
|
||||||
@ -86,7 +85,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def render(context)
|
def render(context)
|
||||||
return '' if @name.nil?
|
return ''.freeze if @name.nil?
|
||||||
@filters.inject(context[@name]) do |output, filter|
|
@filters.inject(context[@name]) do |output, filter|
|
||||||
filterargs = []
|
filterargs = []
|
||||||
keyword_args = {}
|
keyword_args = {}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
module Liquid
|
module Liquid
|
||||||
VERSION = "3.0.0"
|
VERSION = "3.0.0".freeze
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user