Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for serialization #1380

Merged
merged 2 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/liquid/tags/case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def initialize(tag_name, markup, options)
def parse(tokens)
body = case_body = new_body
body = @blocks.last.attachment while parse_body(body, tokens)
@blocks.each do |condition|
@blocks.reverse_each do |condition|
body = condition.attachment
unless body.frozen?
body.remove_blank_strings if blank?
Expand Down
4 changes: 2 additions & 2 deletions lib/liquid/tags/for.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ def parse(tokens)
parse_body(@else_block, tokens)
end
if blank?
@for_block.remove_blank_strings
@else_block&.remove_blank_strings
@for_block.remove_blank_strings
end
@for_block.freeze
@else_block&.freeze
@for_block.freeze
end

def nodelist
Expand Down
2 changes: 1 addition & 1 deletion lib/liquid/tags/if.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def nodelist
def parse(tokens)
while parse_body(@blocks.last.attachment, tokens)
end
@blocks.each do |block|
@blocks.reverse_each do |block|
block.attachment.remove_blank_strings if blank?
block.attachment.freeze
end
Expand Down
23 changes: 14 additions & 9 deletions lib/liquid/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,8 @@ def initialize
# Parse source code.
# Returns self for easy chaining
def parse(source, options = {})
if (profiling = options[:profile])
raise "Profiler not loaded, require 'liquid/profiler' first" unless defined?(Liquid::Profiler)
end

@options = options
@profiling = profiling
@line_numbers = options[:line_numbers] || profiling
parse_context = options.is_a?(ParseContext) ? options : ParseContext.new(options)
parse_context = configure_options(options)
@root = Document.parse(tokenize(source), parse_context)
@warnings = parse_context.warnings
self
end

Expand Down Expand Up @@ -218,6 +210,19 @@ def render_to_output_buffer(context, output)

private

def configure_options(options)
if (profiling = options[:profile])
raise "Profiler not loaded, require 'liquid/profiler' first" unless defined?(Liquid::Profiler)
end

@options = options
@profiling = profiling
@line_numbers = options[:line_numbers] || @profiling
parse_context = options.is_a?(ParseContext) ? options : ParseContext.new(options)
@warnings = parse_context.warnings
parse_context
end

def tokenize(source)
Tokenizer.new(source, @line_numbers)
end
Expand Down