front matter test case and further support
This commit is contained in:
parent
ca5921a72e
commit
edb60cd83a
|
@ -1,7 +1,7 @@
|
||||||
Feature: Local Data API
|
Feature: Local Data API
|
||||||
In order to abstract content from structure
|
In order to abstract content from structure
|
||||||
|
|
||||||
Scenario: Rendering html with the feature enabled
|
Scenario: Rendering html
|
||||||
Given the Server is running
|
Given the Server is running
|
||||||
When I go to "/data.html"
|
When I go to "/data.html"
|
||||||
Then I should see "One:Two"
|
Then I should see "One:Two"
|
|
@ -1,7 +0,0 @@
|
||||||
---
|
|
||||||
layout: false
|
|
||||||
title: No title
|
|
||||||
---
|
|
||||||
|
|
||||||
<%= data.page.title %>
|
|
||||||
<%= data.page.inspect %>
|
|
6
fixtures/test-app/source/front-matter.html.slim
Normal file
6
fixtures/test-app/source/front-matter.html.slim
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
layout: false
|
||||||
|
title: This is the title
|
||||||
|
---
|
||||||
|
|
||||||
|
h1= data.page.title
|
|
@ -9,18 +9,21 @@ module Middleman::CoreExtensions::FrontMatter
|
||||||
::Tilt::register RDiscountTemplate, 'markdown', 'mkd', 'md'
|
::Tilt::register RDiscountTemplate, 'markdown', 'mkd', 'md'
|
||||||
::Tilt::register RedClothTemplate, 'textile'
|
::Tilt::register RedClothTemplate, 'textile'
|
||||||
::Tilt::register ERBTemplate, 'erb', 'rhtml'
|
::Tilt::register ERBTemplate, 'erb', 'rhtml'
|
||||||
::Tilt::register ErubisTemplate, 'erb', 'rhtml', 'erubis'
|
::Tilt::register SlimTemplate, 'slim'
|
||||||
|
::Tilt::register HamlTemplate, 'haml'
|
||||||
|
|
||||||
app.before do
|
app.before do
|
||||||
result = resolve_template(request.path_info, :raise_exceptions => false)
|
result = resolve_template(request.path_info, :raise_exceptions => false)
|
||||||
if result
|
if result
|
||||||
|
extensionless_path, template_engine = result
|
||||||
full_file_path = "#{extensionless_path}.#{template_engine}"
|
full_file_path = "#{extensionless_path}.#{template_engine}"
|
||||||
system_path = File.join(settings.views, full_file_path)
|
system_path = File.join(settings.views, full_file_path)
|
||||||
data, content = app.parse_front_matter(File.read(system_path))
|
data, content = app.parse_front_matter(File.read(system_path))
|
||||||
|
|
||||||
|
request['custom_options'] = {}
|
||||||
%w(layout layout_engine).each do |opt|
|
%w(layout layout_engine).each do |opt|
|
||||||
if data.has_key?(opt)
|
if data.has_key?(opt)
|
||||||
options[opt.to_sym] = data.delete(opt)
|
request['custom_options'][opt.to_sym] = data.delete(opt)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -57,22 +60,23 @@ module Middleman::CoreExtensions::FrontMatter
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# MARKDOWN
|
|
||||||
class RDiscountTemplate < ::Tilt::RDiscountTemplate
|
class RDiscountTemplate < ::Tilt::RDiscountTemplate
|
||||||
include Middleman::CoreExtensions::FrontMatter::YamlAware
|
include Middleman::CoreExtensions::FrontMatter::YamlAware
|
||||||
end
|
end
|
||||||
|
|
||||||
# TEXTILE
|
|
||||||
class RedClothTemplate < ::Tilt::RedClothTemplate
|
class RedClothTemplate < ::Tilt::RedClothTemplate
|
||||||
include Middleman::CoreExtensions::FrontMatter::YamlAware
|
include Middleman::CoreExtensions::FrontMatter::YamlAware
|
||||||
end
|
end
|
||||||
|
|
||||||
# ERb
|
|
||||||
class ERBTemplate < ::Tilt::ERBTemplate
|
class ERBTemplate < ::Tilt::ERBTemplate
|
||||||
include Middleman::CoreExtensions::FrontMatter::YamlAware
|
include Middleman::CoreExtensions::FrontMatter::YamlAware
|
||||||
end
|
end
|
||||||
|
|
||||||
class ErubisTemplate < ::Tilt::ErubisTemplate
|
class HamlTemplate < ::Tilt::HamlTemplate
|
||||||
|
include Middleman::CoreExtensions::FrontMatter::YamlAware
|
||||||
|
end
|
||||||
|
|
||||||
|
class SlimTemplate < ::Slim::Template
|
||||||
include Middleman::CoreExtensions::FrontMatter::YamlAware
|
include Middleman::CoreExtensions::FrontMatter::YamlAware
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -43,12 +43,12 @@ module Middleman
|
||||||
# Activate Yaml Data package
|
# Activate Yaml Data package
|
||||||
register Middleman::CoreExtensions::Data
|
register Middleman::CoreExtensions::Data
|
||||||
|
|
||||||
# Parse YAML from templates
|
|
||||||
register Middleman::CoreExtensions::FrontMatter
|
|
||||||
|
|
||||||
# with_layout and page routing
|
# with_layout and page routing
|
||||||
register Middleman::CoreExtensions::Routing
|
register Middleman::CoreExtensions::Routing
|
||||||
|
|
||||||
|
# Parse YAML from templates
|
||||||
|
register Middleman::CoreExtensions::FrontMatter
|
||||||
|
|
||||||
set :default_extensions, [
|
set :default_extensions, [
|
||||||
:lorem
|
:lorem
|
||||||
]
|
]
|
||||||
|
@ -92,6 +92,8 @@ module Middleman
|
||||||
private
|
private
|
||||||
# Internal method to look for templates and evaluate them if found
|
# Internal method to look for templates and evaluate them if found
|
||||||
def process_request(options={})
|
def process_request(options={})
|
||||||
|
options.merge!(request['custom_options'] || {})
|
||||||
|
|
||||||
old_layout = settings.current_layout
|
old_layout = settings.current_layout
|
||||||
settings.layout(options[:layout]) if !options[:layout].nil?
|
settings.layout(options[:layout]) if !options[:layout].nil?
|
||||||
layout = settings.fetch_layout_path.to_sym
|
layout = settings.fetch_layout_path.to_sym
|
||||||
|
|
Loading…
Reference in a new issue