Freeze all the things

This commit is contained in:
Florian Weingarten 2014-01-07 12:35:16 -05:00
parent 0388376925
commit 43ac8d560b
32 changed files with 166 additions and 165 deletions

View File

@ -21,9 +21,9 @@
module Liquid
FilterSeparator = /\|/
ArgumentSeparator = ','
FilterArgumentSeparator = ':'
VariableAttributeSeparator = '.'
ArgumentSeparator = ','.freeze
FilterArgumentSeparator = ':'.freeze
VariableAttributeSeparator = '.'.freeze
TagStart = /\{\%/
TagEnd = /\%\}/
VariableSignature = /\(?[\w\-\.\[\]]\)?/

View File

@ -41,14 +41,14 @@ module Liquid
unknown_tag($1, $2, tokens)
end
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
when IsVariable
new_var = create_variable(token)
@nodelist << new_var
@children << new_var
@blank = false
when ''
when ''.freeze
# pass
else
@nodelist << token
@ -79,20 +79,20 @@ module Liquid
def unknown_tag(tag, params, tokens)
case tag
when 'else'
raise SyntaxError.new(options[:locale].t("errors.syntax.unexpected_else",
when 'else'.freeze
raise SyntaxError.new(options[:locale].t("errors.syntax.unexpected_else".freeze,
:block_name => block_name))
when 'end'
raise SyntaxError.new(options[:locale].t("errors.syntax.invalid_delimiter",
:block_name => block_name,
when 'end'.freeze
raise SyntaxError.new(options[:locale].t("errors.syntax.invalid_delimiter".freeze,
:block_name => block_name,
:block_delimiter => block_delimiter))
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
def block_delimiter
"end#{block_name}"
"end#{block_name}".freeze
end
def block_name
@ -103,7 +103,7 @@ module Liquid
token.scan(ContentOfVariable) do |content|
return Variable.new(content.first, @options)
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
def render(context)
@ -113,7 +113,7 @@ module Liquid
protected
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
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)
if context.resource_limits_reached?
context.resource_limits[:reached] = true
raise MemoryError.new("Memory limits exceeded")
raise MemoryError.new("Memory limits exceeded".freeze)
end
unless token.is_a?(Block) && token.blank?
output << token_output

View File

@ -8,14 +8,14 @@ module Liquid
#
class Condition #:nodoc:
@@operators = {
'==' => lambda { |cond, left, right| cond.send(:equal_variables, left, right) },
'!=' => lambda { |cond, left, right| !cond.send(:equal_variables, left, right) },
'<>' => lambda { |cond, left, right| !cond.send(:equal_variables, left, right) },
'<' => :<,
'>' => :>,
'>=' => :>=,
'<=' => :<=,
'contains' => lambda { |cond, left, right| left && right ? left.include?(right) : false }
'=='.freeze => lambda { |cond, left, right| cond.send(:equal_variables, left, right) },
'!='.freeze => 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'.freeze => lambda { |cond, left, right| left && right ? left.include?(right) : false }
}
def self.operators
@ -61,7 +61,7 @@ module Liquid
end
def inspect
"#<Condition #{[@left, @operator, @right].compact.join(' ')}>"
"#<Condition #{[@left, @operator, @right].compact.join(' '.freeze)}>".freeze
end
private
@ -94,7 +94,7 @@ module Liquid
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)
operation.call(self, left, right)

View File

@ -45,7 +45,7 @@ module Liquid
def add_filters(filters)
filters = [filters].flatten.compact
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)
end
@ -82,9 +82,9 @@ module Liquid
case e
when SyntaxError
"Liquid syntax error: #{e.message}"
"Liquid syntax error: #{e.message}".freeze
else
"Liquid error: #{e.message}"
"Liquid error: #{e.message}".freeze
end
end
@ -95,7 +95,7 @@ module Liquid
# Push new local scope on the stack. use <tt>Context#stack</tt> instead
def push(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
# Merge a hash of variables in the current local scope
@ -143,11 +143,11 @@ module Liquid
private
LITERALS = {
nil => nil, 'nil' => nil, 'null' => nil, '' => nil,
'true' => true,
'false' => false,
'blank' => :blank?,
'empty' => :empty?
nil => nil, 'nil'.freeze => nil, 'null'.freeze => nil, ''.freeze => nil,
'true'.freeze => true,
'false'.freeze => false,
'blank'.freeze => :blank?,
'empty'.freeze => :empty?
}
# 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
# no key with the same name was found we interpret following calls
# 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

View File

@ -44,28 +44,28 @@ module Liquid
class LocalFileSystem
attr_accessor :root
def initialize(root, pattern = "_%s.liquid")
def initialize(root, pattern = "_%s.liquid".freeze)
@root = root
@pattern = pattern
end
def read_template_file(template_path, context)
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)
end
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))
else
File.join(root, @pattern % template_path)
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
end

View File

@ -11,23 +11,23 @@ module Liquid
@attributes[key] = value
end
else
raise SyntaxError.new(options[:locale].t("errors.syntax.table_row"))
raise SyntaxError.new(options[:locale].t("errors.syntax.table_row".freeze))
end
super
end
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
to = @attributes['limit'] ? from + context[@attributes['limit']].to_i : nil
from = @attributes['offset'.freeze] ? context[@attributes['offset'.freeze]].to_i : 0
to = @attributes['limit'.freeze] ? from + context[@attributes['limit'.freeze]].to_i : nil
collection = Utils.slice_collection(collection, from, to)
length = collection.length
cols = context[@attributes['cols']].to_i
cols = context[@attributes['cols'.freeze]].to_i
row = 1
col = 0
@ -37,19 +37,19 @@ module Liquid
collection.each_with_index do |item, index|
context[@variable_name] = item
context['tablerowloop'] = {
'length' => length,
'index' => index + 1,
'index0' => index,
'col' => col + 1,
'col0' => col,
'index0' => index,
'rindex' => length - index,
'rindex0' => length - index - 1,
'first' => (index == 0),
'last' => (index == length - 1),
'col_first' => (col == 0),
'col_last' => (col == cols - 1)
context['tablerowloop'.freeze] = {
'length'.freeze => length,
'index'.freeze => index + 1,
'index0'.freeze => index,
'col'.freeze => col + 1,
'col0'.freeze => col,
'index0'.freeze => index,
'rindex'.freeze => length - index,
'rindex0'.freeze => length - index - 1,
'first'.freeze => (index == 0),
'last'.freeze => (index == length - 1),
'col_first'.freeze => (col == 0),
'col_last'.freeze => (col == cols - 1)
}
@ -70,5 +70,5 @@ module Liquid
end
end
Template.register_tag('tablerow', TableRow)
Template.register_tag('tablerow'.freeze, TableRow)
end

View File

@ -6,7 +6,7 @@ module Liquid
class TranslationError < StandardError
end
attr_reader :path
def initialize(path = DEFAULT_LOCALE)
@ -31,7 +31,7 @@ module Liquid
end
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}"
end
end

View File

@ -5,7 +5,7 @@ module Liquid
attr_reader :message
def initialize(message=nil)
@message = message || "interrupt"
@message = message || "interrupt".freeze
end
end

View File

@ -2,14 +2,14 @@ require "strscan"
module Liquid
class Lexer
SPECIALS = {
'|' => :pipe,
'.' => :dot,
':' => :colon,
',' => :comma,
'[' => :open_square,
']' => :close_square,
'(' => :open_round,
')' => :close_round
'|'.freeze => :pipe,
'.'.freeze => :dot,
':'.freeze => :colon,
','.freeze => :comma,
'['.freeze => :open_square,
']'.freeze => :close_square,
'('.freeze => :open_round,
')'.freeze => :close_round
}
IDENTIFIER = /[\w\-?!]+/
SINGLE_STRING_LITERAL = /'[^\']*'/

View File

@ -43,7 +43,7 @@
class Module
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
drop_class.new(self)
end

View File

@ -56,7 +56,7 @@ module Liquid
consume(:dotdot)
last = expression
consume(:close_round)
"(#{first}..#{last})"
"(#{first}..#{last})".freeze
else
raise SyntaxError, "#{token} is not a valid expression"
end
@ -66,10 +66,11 @@ module Liquid
str = ""
# might be a keyword argument (identifier: expression)
if look(:id) && look(:colon, 1)
str << consume << consume << ' '
str << consume << consume << ' '.freeze
end
str << expression
str.freeze
end
def variable_signature

View File

@ -4,12 +4,17 @@ require 'bigdecimal'
module Liquid
module StandardFilters
HTML_ESCAPE = { '&' => '&amp;', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;', "'" => '&#39;' }
HTML_ESCAPE = {
'&'.freeze => '&amp;'.freeze,
'>'.freeze => '&gt;'.freeze,
'<'.freeze => '&lt;'.freeze,
'"'.freeze => '&quot;'.freeze,
"'".freeze => '&#39;'.freeze
}
HTML_ESCAPE_ONCE_REGEXP = /["><']|&(?!([a-zA-Z]+|(#\d+));)/
# Return the size of an array or of an string
def size(input)
input.respond_to?(:size) ? input.size : 0
end
@ -39,19 +44,19 @@ module Liquid
alias_method :h, :escape
# 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
l = length.to_i - truncate_string.length
l = 0 if l < 0
input.length > length.to_i ? input[0...l] + truncate_string : input
end
def truncatewords(input, words = 15, truncate_string = "...")
def truncatewords(input, words = 15, truncate_string = "...".freeze)
if input.nil? then return end
wordlist = input.to_s.split
l = words.to_i - 1
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
# Split input string into an array of substrings separated by given pattern.
@ -64,16 +69,17 @@ module Liquid
end
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
# Remove all newlines from the string
def strip_newlines(input)
input.to_s.gsub(/\r?\n/, '')
input.to_s.gsub(/\r?\n/, ''.freeze)
end
# Join elements of the array with certain character between them
def join(input, glue = ' ')
def join(input, glue = ' '.freeze)
[input].flatten.join(glue)
end
@ -83,7 +89,7 @@ module Liquid
ary = flatten_if_necessary(input)
if property.nil?
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] }
elsif ary.first.respond_to?(property)
ary.sort {|a,b| a.send(property) <=> b.send(property) }
@ -101,7 +107,7 @@ module Liquid
flatten_if_necessary(input).map do |e|
e = e.call if e.is_a?(Proc)
if property == "to_liquid"
if property == "to_liquid".freeze
e
elsif e.respond_to?(:[])
e[property]
@ -110,23 +116,23 @@ module Liquid
end
# 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)
end
# 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)
end
# remove a substring
def remove(input, string)
input.to_s.gsub(string, '')
input.to_s.gsub(string, ''.freeze)
end
# remove the first occurrences of a substring
def remove_first(input, string)
input.to_s.sub(string, '')
input.to_s.sub(string, ''.freeze)
end
# add one string to another
@ -141,7 +147,7 @@ module Liquid
# Add <br /> tags in front of all newlines in input string
def newline_to_br(input)
input.to_s.gsub(/\n/, "<br />\n")
input.to_s.gsub(/\n/, "<br />\n".freeze)
end
# Reformat a date
@ -184,7 +190,7 @@ module Liquid
date = if input.is_a?(String)
case input.downcase
when 'now', 'today'
when 'now'.freeze, 'today'.freeze
Time.now
else
Time.parse(input)
@ -244,7 +250,7 @@ module Liquid
apply_operation(input, operand, :%)
end
def default(input, default_value = "")
def default(input, default_value = "".freeze)
is_blank = input.respond_to?(:empty?) ? input.empty? : !input
is_blank ? default_value : input
end

View File

@ -27,7 +27,7 @@ module Liquid
end
def render(context)
''
''.freeze
end
def blank?

View File

@ -16,7 +16,7 @@ module Liquid
@to = $1
@from = Variable.new($2)
else
raise SyntaxError.new options[:locale].t("errors.syntax.assign")
raise SyntaxError.new options[:locale].t("errors.syntax.assign".freeze)
end
super
@ -26,7 +26,7 @@ module Liquid
val = @from.render(context)
context.scopes.last[@to] = val
context.resource_limits[:assign_score_current] += (val.respond_to?(:length) ? val.length : 1)
''
''.freeze
end
def blank?
@ -34,5 +34,5 @@ module Liquid
end
end
Template.register_tag('assign', Assign)
Template.register_tag('assign'.freeze, Assign)
end

View File

@ -17,5 +17,5 @@ module Liquid
end
Template.register_tag('break', Break)
Template.register_tag('break'.freeze, Break)
end

View File

@ -28,7 +28,7 @@ module Liquid
output = super
context.scopes.last[@to] = output
context.resource_limits[:assign_score_current] += (output.respond_to?(:length) ? output.length : 1)
''
''.freeze
end
def blank?
@ -36,5 +36,5 @@ module Liquid
end
end
Template.register_tag('capture', Capture)
Template.register_tag('capture'.freeze, Capture)
end

View File

@ -9,7 +9,7 @@ module Liquid
if markup =~ Syntax
@left = $1
else
raise SyntaxError.new(options[:locale].t("errors.syntax.case"))
raise SyntaxError.new(options[:locale].t("errors.syntax.case".freeze))
end
super
@ -18,9 +18,9 @@ module Liquid
def unknown_tag(tag, markup, tokens)
@nodelist = []
case tag
when 'when'
when 'when'.freeze
record_when_condition(markup)
when 'else'
when 'else'.freeze
record_else_condition(markup)
else
super
@ -50,12 +50,12 @@ module Liquid
while markup
# Create a new nodelist and assign it to the new block
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
markup = $2
block = Condition.new(@left, '==', $1)
block = Condition.new(@left, '=='.freeze, $1)
block.attach(@nodelist)
@blocks.push(block)
end
@ -63,7 +63,7 @@ module Liquid
def record_else_condition(markup)
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
block = ElseCondition.new
@ -72,5 +72,5 @@ module Liquid
end
end
Template.register_tag('case', Case)
Template.register_tag('case'.freeze, Case)
end

View File

@ -1,7 +1,7 @@
module Liquid
class Comment < Block
def render(context)
''
''.freeze
end
def unknown_tag(tag, markup, tokens)
@ -12,5 +12,5 @@ module Liquid
end
end
Template.register_tag('comment', Comment)
Template.register_tag('comment'.freeze, Comment)
end

View File

@ -1,5 +1,4 @@
module Liquid
# Continue tag to be used to break out of a for loop.
#
# == Basic Usage:
@ -10,12 +9,10 @@ module Liquid
# {% endfor %}
#
class Continue < Tag
def interrupt
ContinueInterrupt.new
end
end
Template.register_tag('continue', Continue)
Template.register_tag('continue'.freeze, Continue)
end

View File

@ -24,7 +24,7 @@ module Liquid
@variables = variables_from_string(markup)
@name = "'#{@variables.to_s}'"
else
raise SyntaxError.new(options[:locale].t("errors.syntax.cycle"))
raise SyntaxError.new(options[:locale].t("errors.syntax.cycle".freeze))
end
super
end

View File

@ -21,7 +21,6 @@ module Liquid
class Decrement < Tag
def initialize(tag_name, markup, tokens)
@variable = markup.strip
super
end
@ -35,5 +34,5 @@ module Liquid
private
end
Template.register_tag('decrement', Decrement)
Template.register_tag('decrement'.freeze, Decrement)
end

View File

@ -53,7 +53,7 @@ module Liquid
end
def unknown_tag(tag, markup, tokens)
return super unless tag == 'else'
return super unless tag == 'else'.freeze
@nodelist = @else_block = []
end
@ -66,13 +66,13 @@ module Liquid
# Maintains Ruby 1.8.7 String#each behaviour on 1.9
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
else
context[@attributes['offset']].to_i
context[@attributes['offset'.freeze]].to_i
end
limit = context[@attributes['limit']]
limit = context[@attributes['limit'.freeze]]
to = limit ? limit.to_i + from : nil
segment = Utils.slice_collection(collection, from, to)
@ -91,15 +91,16 @@ module Liquid
context.stack do
segment.each_with_index do |item, index|
context[@variable_name] = item
context['forloop'] = {
'name' => @name,
'length' => length,
'index' => index + 1,
'index0' => index,
'rindex' => length - index,
'rindex0' => length - index - 1,
'first' => (index == 0),
'last' => (index == length - 1) }
context['forloop'.freeze] = {
'name'.freeze => @name,
'length'.freeze => length,
'index'.freeze => index + 1,
'index0'.freeze => index,
'rindex'.freeze => length - index,
'rindex0'.freeze => length - index - 1,
'first'.freeze => (index == 0),
'last'.freeze => (index == length - 1)
}
result << render_all(@for_block, context)
@ -127,22 +128,22 @@ module Liquid
@attributes[key] = value
end
else
raise SyntaxError.new(options[:locale].t("errors.syntax.for"))
raise SyntaxError.new(options[:locale].t("errors.syntax.for".freeze))
end
end
def strict_parse(markup)
p = Parser.new(markup)
@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
@name = "#{@variable_name}-#{@collection_name}"
@reversed = p.id?('reversed')
@reversed = p.id?('reversed'.freeze)
@attributes = {}
while p.look(:id) && p.look(:colon, 1)
unless attribute = p.id?('limit') || p.id?('offset')
raise SyntaxError.new(options[:locale].t("errors.syntax.for_invalid_attribute"))
unless attribute = p.id?('limit'.freeze) || p.id?('offset'.freeze)
raise SyntaxError.new(options[:locale].t("errors.syntax.for_invalid_attribute".freeze))
end
p.consume
val = p.expression
@ -153,14 +154,14 @@ module Liquid
private
def render_else(context)
return @else_block ? [render_all(@else_block, context)] : ''
end
def render_else(context)
return @else_block ? [render_all(@else_block, context)] : ''.freeze
end
def iterable?(collection)
collection.respond_to?(:each) || Utils.non_blank_string?(collection)
end
def iterable?(collection)
collection.respond_to?(:each) || Utils.non_blank_string?(collection)
end
end
Template.register_tag('for', For)
Template.register_tag('for'.freeze, For)
end

View File

@ -16,12 +16,12 @@ module Liquid
def initialize(tag_name, markup, tokens)
@blocks = []
push_block('if', markup)
push_block('if'.freeze, markup)
super
end
def unknown_tag(tag, markup, tokens)
if ['elsif', 'else'].include?(tag)
if ['elsif'.freeze, 'else'.freeze].include?(tag)
push_block(tag, markup)
else
super
@ -35,14 +35,14 @@ module Liquid
return render_all(block.attachment, context)
end
end
''
''.freeze
end
end
private
def push_block(tag, markup)
block = if tag == 'else'
block = if tag == 'else'.freeze
ElseCondition.new
else
parse_with_selected_parser(markup)
@ -54,17 +54,17 @@ module Liquid
def lax_parse(markup)
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)
while not expressions.empty?
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)
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)
condition = new_condition
end
@ -77,7 +77,7 @@ module Liquid
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.send(op, condition)
condition = new_cond
@ -98,5 +98,5 @@ module Liquid
end
end
Template.register_tag('if', If)
Template.register_tag('if'.freeze, If)
end

View File

@ -10,11 +10,11 @@ module Liquid
context.registers[:ifchanged] = output
output
else
''
''.freeze
end
end
end
end
Template.register_tag('ifchanged', Ifchanged)
Template.register_tag('ifchanged'.freeze, Ifchanged)
end

View File

@ -29,7 +29,7 @@ module Liquid
end
else
raise SyntaxError.new(options[:locale].t("errors.syntax.include"))
raise SyntaxError.new(options[:locale].t("errors.syntax.include".freeze))
end
super
@ -51,7 +51,7 @@ module Liquid
context[key] = context[value]
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)
variable.collect do |var|
context[context_variable_name] = var
@ -94,5 +94,5 @@ module Liquid
end
end
Template.register_tag('include', Include)
Template.register_tag('include'.freeze, Include)
end

View File

@ -31,5 +31,5 @@ module Liquid
end
end
Template.register_tag('increment', Increment)
Template.register_tag('increment'.freeze, Increment)
end

View File

@ -7,7 +7,7 @@ module Liquid
@nodelist.clear
while token = tokens.shift
if token =~ FullTokenPossiblyInvalid
@nodelist << $1 if $1 != ""
@nodelist << $1 if $1 != "".freeze
if block_delimiter == $2
end_tag
return
@ -18,5 +18,5 @@ module Liquid
end
end
Template.register_tag('raw', Raw)
Template.register_tag('raw'.freeze, Raw)
end

View File

@ -1,7 +1,6 @@
require File.dirname(__FILE__) + '/if'
module Liquid
# Unless is a conditional just like 'if' but works on the inverse logic.
#
# {% unless x < 0 %} x is greater than zero {% end %}
@ -23,11 +22,10 @@ module Liquid
end
end
''
''.freeze
end
end
end
Template.register_tag('unless', Unless)
Template.register_tag('unless'.freeze, Unless)
end

View File

@ -110,7 +110,7 @@ module Liquid
# filters and tags and might be useful to integrate liquid more with its host application
#
def render(*args)
return '' if @root.nil?
return ''.freeze if @root.nil?
context = case args.first
when Liquid::Context

View File

@ -10,7 +10,7 @@ module Liquid
end
def self.non_blank_string?(collection)
collection.is_a?(String) && collection != ''
collection.is_a?(String) && collection != ''.freeze
end
def self.slice_collection_using_each(collection, from, to)

View File

@ -19,7 +19,6 @@ module Liquid
@markup = markup
@name = nil
@options = options || {}
case @options[:error_mode] || Template.error_mode
when :strict then strict_parse(markup)
@ -63,7 +62,7 @@ module Liquid
@filters = []
p = Parser.new(markup)
# Could be just filters with no input
@name = p.look(:pipe) ? '' : p.expression
@name = p.look(:pipe) ? ''.freeze : p.expression
while p.consume?(:pipe)
filtername = p.consume(:id)
filterargs = p.consume?(:colon) ? parse_filterargs(p) : []
@ -86,7 +85,7 @@ module Liquid
end
def render(context)
return '' if @name.nil?
return ''.freeze if @name.nil?
@filters.inject(context[@name]) do |output, filter|
filterargs = []
keyword_args = {}

View File

@ -1,4 +1,4 @@
# encoding: utf-8
module Liquid
VERSION = "3.0.0"
VERSION = "3.0.0".freeze
end