inject yaml data into liquid templates. closes #111
This commit is contained in:
parent
d79eb3fc0f
commit
6eadb0e888
8 changed files with 47 additions and 8 deletions
|
@ -3,8 +3,8 @@
|
||||||
- Support accessing variables and data objects in ERb Sprockets files (library.js.coffee.erb)
|
- 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)
|
- Make :markdown_engine support simple symbol names (:maruku instead of ::Tilt::MarkukuTemplate)
|
||||||
- Update Padrino deps to 0.10.2
|
- Update Padrino deps to 0.10.2
|
||||||
- Update EventMachine to pre for Windows users
|
|
||||||
- Include therubyracer on *nix
|
- Include therubyracer on *nix
|
||||||
|
- Enable frontmatter for Liquid templates
|
||||||
|
|
||||||
2.0.7
|
2.0.7
|
||||||
=====
|
=====
|
||||||
|
|
|
@ -5,3 +5,8 @@ Feature: Local Data API
|
||||||
Given the Server is running at "test-app"
|
Given the Server is running at "test-app"
|
||||||
When I go to "/data.html"
|
When I go to "/data.html"
|
||||||
Then I should see "One:Two"
|
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"
|
|
@ -19,6 +19,7 @@ with_layout false do
|
||||||
page "/spaces in file.html"
|
page "/spaces in file.html"
|
||||||
page "/slim.html"
|
page "/slim.html"
|
||||||
page "/data.html"
|
page "/data.html"
|
||||||
|
page "/data2.html"
|
||||||
page "/page-classes.html"
|
page "/page-classes.html"
|
||||||
page "/sub1/page-classes.html"
|
page "/sub1/page-classes.html"
|
||||||
page "/sub1/sub2/page-classes.html"
|
page "/sub1/sub2/page-classes.html"
|
||||||
|
|
1
fixtures/test-app/source/data2.html.liquid
Normal file
1
fixtures/test-app/source/data2.html.liquid
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{% for item in data.test %}{{item.title}}{% endfor %}
|
|
@ -172,7 +172,12 @@ module Middleman::Base
|
||||||
render_options = { :layout => layout }
|
render_options = { :layout => layout }
|
||||||
render_options[:layout_engine] = options[:layout_engine] if options.has_key? :layout_engine
|
render_options[:layout_engine] = options[:layout_engine] if options.has_key? :layout_engine
|
||||||
request_path = request.path_info.gsub("%20", " ")
|
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
|
settings.set :layout, old_layout
|
||||||
|
|
||||||
if result
|
if result
|
||||||
|
|
|
@ -22,7 +22,7 @@ module Middleman::CoreExtensions::Data
|
||||||
@app = app
|
@app = app
|
||||||
end
|
end
|
||||||
|
|
||||||
def method_missing(path)
|
def data_for_path(path)
|
||||||
response = nil
|
response = nil
|
||||||
|
|
||||||
@@local_sources ||= {}
|
@@local_sources ||= {}
|
||||||
|
@ -38,10 +38,36 @@ module Middleman::CoreExtensions::Data
|
||||||
response = YAML.load_file(file_path)
|
response = YAML.load_file(file_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if response
|
|
||||||
recursively_enhance(response)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def method_missing(path)
|
||||||
|
result = data_for_path(path)
|
||||||
|
|
||||||
|
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
|
end
|
||||||
|
|
||||||
def self.data_content(name, content)
|
def self.data_content(name, content)
|
||||||
|
|
|
@ -80,7 +80,7 @@ module Middleman::CoreExtensions::FrontMatter
|
||||||
|
|
||||||
module YamlAware
|
module YamlAware
|
||||||
def prepare
|
def prepare
|
||||||
options, @data = Middleman::CoreExtensions::FrontMatter.parse_front_matter(@data)
|
@frontmatter, @data = Middleman::CoreExtensions::FrontMatter.parse_front_matter(@data)
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,7 +38,7 @@ Gem::Specification.new do |s|
|
||||||
eos
|
eos
|
||||||
|
|
||||||
s.add_dependency("rack", ["~> 1.3.0"])
|
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("thin", ["~> 1.2.11"])
|
||||||
s.add_dependency("thor", ["~> 0.14.0"])
|
s.add_dependency("thor", ["~> 0.14.0"])
|
||||||
s.add_dependency("tilt", ["~> 1.3.1"])
|
s.add_dependency("tilt", ["~> 1.3.1"])
|
||||||
|
@ -74,6 +74,7 @@ eos
|
||||||
# Development and test
|
# Development and test
|
||||||
# s.add_development_dependency("jquery-rails")
|
# s.add_development_dependency("jquery-rails")
|
||||||
s.add_development_dependency("coffee-filter", ["~> 0.1.1"])
|
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("cucumber", ["~> 1.0.2"])
|
||||||
s.add_development_dependency("rake", ["0.8.7"])
|
s.add_development_dependency("rake", ["0.8.7"])
|
||||||
s.add_development_dependency("rspec", ["~> 2.6.0"])
|
s.add_development_dependency("rspec", ["~> 2.6.0"])
|
||||||
|
|
Loading…
Add table
Reference in a new issue