frontmatter extensions. closes #191
This commit is contained in:
parent
6f4c1b816a
commit
433275d71f
5 changed files with 21 additions and 11 deletions
|
@ -6,6 +6,10 @@ Feature: YAML Front Matter
|
|||
When I go to "/front-matter.html"
|
||||
Then I should see "<h1>This is the title</h1>"
|
||||
Then I should not see "---"
|
||||
When I go to "/front-matter-2.php"
|
||||
Then I should see "<h1>This is the title</h1>"
|
||||
Then I should see "<?php"
|
||||
Then I should not see "---"
|
||||
|
||||
Scenario: A template changes frontmatter during preview
|
||||
Given the Server is running at "test-app"
|
||||
|
|
7
fixtures/test-app/source/front-matter-2.php.erb
Normal file
7
fixtures/test-app/source/front-matter-2.php.erb
Normal file
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
layout: false
|
||||
title: This is the title
|
||||
---
|
||||
|
||||
<h1><%= data.page.title %></h1>
|
||||
<?php echo "sup"; ?>
|
|
@ -1,7 +1,7 @@
|
|||
h1 Welcome
|
||||
|
||||
= image_tag "Chrome_Logo.svg"
|
||||
= image_tag "cfb_tomb-perennial-energy.svgz"
|
||||
== image_tag "Chrome_Logo.svg"
|
||||
== image_tag "cfb_tomb-perennial-energy.svgz"
|
||||
|
||||
markdown:
|
||||
## H2
|
||||
|
|
|
@ -4,6 +4,7 @@ require "tilt"
|
|||
module Middleman::CoreExtensions::FrontMatter
|
||||
class << self
|
||||
def registered(app)
|
||||
app.set :frontmatter_extensions, %w(.htm .html .php)
|
||||
app.extend ClassMethods
|
||||
app.send :include, InstanceMethods
|
||||
end
|
||||
|
@ -22,15 +23,18 @@ module Middleman::CoreExtensions::FrontMatter
|
|||
def initialize
|
||||
super
|
||||
|
||||
file_changed FrontMatter.matcher do |file|
|
||||
exts = frontmatter_extensions.join("|").gsub(".", "\.")
|
||||
matcher = %r{source/.*(#{exts})}
|
||||
|
||||
file_changed matcher do |file|
|
||||
frontmatter.touch_file(file)
|
||||
end
|
||||
|
||||
file_deleted FrontMatter.matcher do |file|
|
||||
file_deleted matcher do |file|
|
||||
frontmatter.remove_file(file)
|
||||
end
|
||||
|
||||
provides_metadata FrontMatter.matcher do |path|
|
||||
provides_metadata matcher do |path|
|
||||
relative_path = path.sub(source_dir, "")
|
||||
|
||||
data = if frontmatter.has_data?(relative_path)
|
||||
|
@ -70,12 +74,6 @@ module Middleman::CoreExtensions::FrontMatter
|
|||
end
|
||||
|
||||
class FrontMatter
|
||||
class << self
|
||||
def matcher
|
||||
%r{source/.*\.html}
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(app)
|
||||
@app = app
|
||||
@source = File.expand_path(@app.source, @app.root)
|
||||
|
|
|
@ -28,6 +28,7 @@ Given /^the Server is running at "([^\"]*)"$/ do |app_path|
|
|||
initialize_commands.unshift lambda {
|
||||
set :root, File.join(PROJECT_ROOT_PATH, "fixtures", app_path)
|
||||
set :environment, @current_env || :development
|
||||
set :show_exceptions, false
|
||||
}
|
||||
|
||||
@server_inst = Middleman.server.inst do
|
||||
|
|
Loading…
Reference in a new issue