mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-15 08:50:45 -07:00
Replace regexpes with Ragel grammer
context parsing was handrolled and pretty ad-hoc this branch exists to explore parsing the context through a defined fsm as produced by Ragel
This commit is contained in:
committed by
Tobias Lutke
parent
6b64bfb53e
commit
18b83a58bd
@@ -9,11 +9,9 @@ puts 'Running profiler...'
|
||||
results = profiler.run_profile
|
||||
|
||||
puts 'Success'
|
||||
puts
|
||||
|
||||
[RubyProf::FlatPrinter, RubyProf::GraphPrinter, RubyProf::GraphHtmlPrinter, RubyProf::CallTreePrinter].each do |klass|
|
||||
filename = (ENV['TMP'] || '/tmp') + (klass.name.include?('Html') ? "/liquid.#{klass.name.downcase}.html" : "/callgrind.liquid.#{klass.name.downcase}.txt")
|
||||
filename.gsub!(/:+/, '_')
|
||||
File.open(filename, "w+") { |fp| klass.new(results).print(fp, :print_file => true) }
|
||||
$stderr.puts "wrote #{klass.name} output to #{filename}"
|
||||
filename = (ENV['TMP'] || '/tmp') + "/callgrind.liquid.txt"
|
||||
File.open(filename, "w+") do |fp|
|
||||
RubyProf::CallTreePrinter.new(results).print(fp, :print_file => true)
|
||||
end
|
||||
$stderr.puts "wrote RubyProf::CallTreePrinter output to #{filename}"
|
||||
|
||||
+19
-16
@@ -23,7 +23,7 @@ class ThemeRunner
|
||||
|
||||
theme_path = File.dirname(test) + '/theme.liquid'
|
||||
|
||||
[File.read(test), (File.file?(theme_path) ? File.read(theme_path) : nil), test]
|
||||
[Liquid::Template.parse(File.read(test)), File.file?(theme_path) ? Liquid::Template.parse(File.read(theme_path)) : nil, test]
|
||||
end.compact
|
||||
end
|
||||
|
||||
@@ -53,11 +53,17 @@ class ThemeRunner
|
||||
end
|
||||
|
||||
|
||||
<<<<<<< HEAD
|
||||
def run_profile
|
||||
RubyProf.measure_mode = RubyProf::WALL_TIME
|
||||
=======
|
||||
def run(profile = false)
|
||||
RubyProf.measure_mode = RubyProf::WALL_TIME if profile
|
||||
>>>>>>> wip
|
||||
|
||||
# Dup assigns because will make some changes to them
|
||||
assigns = Database.tables.dup
|
||||
assigns['page_title'] = 'Page title'
|
||||
|
||||
@tests.each do |liquid, layout, template_name|
|
||||
|
||||
@@ -66,16 +72,17 @@ class ThemeRunner
|
||||
page_template = File.basename(template_name, File.extname(template_name))
|
||||
|
||||
unless @started
|
||||
RubyProf.start
|
||||
RubyProf.pause
|
||||
if profile
|
||||
RubyProf.start
|
||||
RubyProf.pause
|
||||
end
|
||||
@started = true
|
||||
end
|
||||
|
||||
html = nil
|
||||
|
||||
RubyProf.resume
|
||||
html = compile_and_render(liquid, layout, assigns, page_template)
|
||||
RubyProf.pause
|
||||
assigns['template'] = page_template
|
||||
RubyProf.resume if profile
|
||||
html = render(liquid, layout, assigns)
|
||||
RubyProf.pause if profile
|
||||
|
||||
|
||||
# return the result and the MD5 of the content, this can be used to detect regressions between liquid version
|
||||
@@ -85,19 +92,15 @@ class ThemeRunner
|
||||
# File.open("/tmp/#{File.basename(template_name)}.html", "w+") { |fp| fp <<html}
|
||||
end
|
||||
|
||||
RubyProf.stop
|
||||
RubyProf.stop if profile
|
||||
end
|
||||
|
||||
def compile_and_render(template, layout, assigns, page_template)
|
||||
tmpl = Liquid::Template.new
|
||||
tmpl.assigns['page_title'] = 'Page title'
|
||||
tmpl.assigns['template'] = page_template
|
||||
|
||||
content_for_layout = tmpl.parse(template).render(assigns)
|
||||
def render(template, layout, assigns)
|
||||
content_for_layout = template.render(assigns)
|
||||
|
||||
if layout
|
||||
assigns['content_for_layout'] = content_for_layout
|
||||
tmpl.parse(layout).render(assigns)
|
||||
layout.render(assigns)
|
||||
else
|
||||
content_for_layout
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user