Implement naive recusrive descent

Ragel doesn't allow us to recurse so we simply
reinvoke the parser for each step.
This commit is contained in:
Tobias Lutke
2012-10-24 21:59:14 -04:00
parent 18b83a58bd
commit cd040dabd8
8 changed files with 1275 additions and 564 deletions

View File

@@ -23,7 +23,7 @@ class ThemeRunner
theme_path = File.dirname(test) + '/theme.liquid'
[Liquid::Template.parse(File.read(test)), File.file?(theme_path) ? Liquid::Template.parse(File.read(theme_path)) : nil, test]
[File.read(test), (File.file?(theme_path) ? File.read(theme_path) : nil), test]
end.compact
end
@@ -53,17 +53,11 @@ 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|
@@ -72,17 +66,16 @@ class ThemeRunner
page_template = File.basename(template_name, File.extname(template_name))
unless @started
if profile
RubyProf.start
RubyProf.pause
end
RubyProf.start
RubyProf.pause
@started = true
end
assigns['template'] = page_template
RubyProf.resume if profile
html = render(liquid, layout, assigns)
RubyProf.pause if profile
html = nil
RubyProf.resume
html = compile_and_render(liquid, layout, assigns, page_template)
RubyProf.pause
# return the result and the MD5 of the content, this can be used to detect regressions between liquid version
@@ -92,15 +85,19 @@ class ThemeRunner
# File.open("/tmp/#{File.basename(template_name)}.html", "w+") { |fp| fp <<html}
end
RubyProf.stop if profile
RubyProf.stop
end
def render(template, layout, assigns)
content_for_layout = template.render(assigns)
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)
if layout
assigns['content_for_layout'] = content_for_layout
layout.render(assigns)
tmpl.parse(layout).render(assigns)
else
content_for_layout
end