diff --git a/CHANGELOG b/CHANGELOG index 7e79638a..67bfda1a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,8 +3,8 @@ - Support accessing variables and data objects in ERb Sprockets files (library.js.coffee.erb) - Make :markdown_engine support simple symbol names (:maruku instead of ::Tilt::MarkukuTemplate) - Update Padrino deps to 0.10.2 -- Update EventMachine to pre for Windows users - Include therubyracer on *nix +- Enable frontmatter for Liquid templates 2.0.7 ===== diff --git a/features/data.feature b/features/data.feature index e803a603..d296e1ba 100644 --- a/features/data.feature +++ b/features/data.feature @@ -4,4 +4,9 @@ Feature: Local Data API Scenario: Rendering html Given the Server is running at "test-app" When I go to "/data.html" - Then I should see "One:Two" \ No newline at end of file + Then I should see "One:Two" + + Scenario: Rendering liquid + Given the Server is running at "test-app" + When I go to "/data2.html" + Then I should see "OneTwo" \ No newline at end of file diff --git a/fixtures/test-app/config.rb b/fixtures/test-app/config.rb index f3e08569..55ee8fcb 100644 --- a/fixtures/test-app/config.rb +++ b/fixtures/test-app/config.rb @@ -19,6 +19,7 @@ with_layout false do page "/spaces in file.html" page "/slim.html" page "/data.html" + page "/data2.html" page "/page-classes.html" page "/sub1/page-classes.html" page "/sub1/sub2/page-classes.html" diff --git a/fixtures/test-app/source/data2.html.liquid b/fixtures/test-app/source/data2.html.liquid new file mode 100644 index 00000000..95416380 --- /dev/null +++ b/fixtures/test-app/source/data2.html.liquid @@ -0,0 +1 @@ +{% for item in data.test %}{{item.title}}{% endfor %} \ No newline at end of file diff --git a/lib/middleman/base.rb b/lib/middleman/base.rb index bca4a547..148b82bd 100644 --- a/lib/middleman/base.rb +++ b/lib/middleman/base.rb @@ -172,7 +172,12 @@ module Middleman::Base render_options = { :layout => layout } render_options[:layout_engine] = options[:layout_engine] if options.has_key? :layout_engine request_path = request.path_info.gsub("%20", " ") - result = render(request_path, render_options) + path, engine = resolve_template(request_path) + + locals = {} + locals[:data] = data.to_h if engine == :liquid + + result = render(engine, path, render_options, locals) settings.set :layout, old_layout if result diff --git a/lib/middleman/core_extensions/data.rb b/lib/middleman/core_extensions/data.rb index ce00f9b9..c2602e5a 100755 --- a/lib/middleman/core_extensions/data.rb +++ b/lib/middleman/core_extensions/data.rb @@ -22,7 +22,7 @@ module Middleman::CoreExtensions::Data @app = app end - def method_missing(path) + def data_for_path(path) response = nil @@local_sources ||= {} @@ -38,11 +38,37 @@ module Middleman::CoreExtensions::Data response = YAML.load_file(file_path) end end + end + + def method_missing(path) + result = data_for_path(path) - if response - recursively_enhance(response) + if result + recursively_enhance(result) + else + super end end + + def to_h + data = {} + + (@@local_sources || {}).each do |k, v| + data[k] = data_for_path(k) + end + + (@@callback_sources || {}).each do |k, v| + data[k] = data_for_path(k) + end + + yaml_path = File.join(@app.root, @app.data_dir, "*.yml") + Dir[yaml_path].each do |f| + p = f.split("/").last.gsub(".yml", "") + data[p] = data_for_path(p) + end + + data + end def self.data_content(name, content) @@local_sources ||= {} diff --git a/lib/middleman/core_extensions/front_matter.rb b/lib/middleman/core_extensions/front_matter.rb index ebb37385..aab49186 100644 --- a/lib/middleman/core_extensions/front_matter.rb +++ b/lib/middleman/core_extensions/front_matter.rb @@ -80,7 +80,7 @@ module Middleman::CoreExtensions::FrontMatter module YamlAware def prepare - options, @data = Middleman::CoreExtensions::FrontMatter.parse_front_matter(@data) + @frontmatter, @data = Middleman::CoreExtensions::FrontMatter.parse_front_matter(@data) super end end diff --git a/middleman.gemspec b/middleman.gemspec index 3482e0e6..32e72f76 100644 --- a/middleman.gemspec +++ b/middleman.gemspec @@ -38,7 +38,7 @@ Gem::Specification.new do |s| eos s.add_dependency("rack", ["~> 1.3.0"]) - s.add_dependency("eventmachine", ["1.0.0.beta.3"]) + # s.add_dependency("eventmachine", ["1.0.0.beta.3"]) s.add_dependency("thin", ["~> 1.2.11"]) s.add_dependency("thor", ["~> 0.14.0"]) s.add_dependency("tilt", ["~> 1.3.1"]) @@ -74,6 +74,7 @@ eos # Development and test # s.add_development_dependency("jquery-rails") s.add_development_dependency("coffee-filter", ["~> 0.1.1"]) + s.add_development_dependency("liquid", ["~> 2.2.0"]) s.add_development_dependency("cucumber", ["~> 1.0.2"]) s.add_development_dependency("rake", ["0.8.7"]) s.add_development_dependency("rspec", ["~> 2.6.0"])