diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5e1b9b5f..c9b0e0ac 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,7 @@
master
===
+* Allow frontmatter to be side-loaded from a neighboring file with a .frontmatter extension: #855
* Allow frontmatter "renderer_options" key to overwrite renderer options on a per-file basis. #859
* Added a "t" helper that delegates to I18n.t, just like Rails. #853.
* I18n will fall back to the default locale if a translation in the current locale is not found. You can disable this behavior by passing `:no_fallbacks => true` when activating `:i18n`. More settings documented at https://github.com/svenfuchs/i18n/wiki/Fallbacks . #853
diff --git a/Gemfile b/Gemfile
index 14159730..bbfabbe5 100644
--- a/Gemfile
+++ b/Gemfile
@@ -21,6 +21,9 @@ gem "liquid", :require => false
gem "less", :require => false
gem "stylus", :require => false
+gem "pry"
+gem "pry-debugger"
+
platforms :ruby do
gem "therubyracer"
gem "redcarpet"
diff --git a/middleman-core/features/front-matter-neighbor.feature b/middleman-core/features/front-matter-neighbor.feature
new file mode 100644
index 00000000..04724248
--- /dev/null
+++ b/middleman-core/features/front-matter-neighbor.feature
@@ -0,0 +1,151 @@
+Feature: Neighboring YAML Front Matter
+
+ Scenario: Rendering html (yaml)
+ Given the Server is running at "frontmatter-neighbor-app"
+ When I go to "/front-matter-auto.html"
+ Then I should see "
This is the title
"
+ Then I should not see "---"
+ When I go to "/front-matter-auto.erb.frontmatter"
+ Then I should see "File Not Found"
+ When I go to "/front-matter-2.php"
+ Then I should see "This is the title
"
+ Then I should see "<%= data.page.title %>"
+ Then I should not see "---"
+ When I go to "/raw-front-matter.html.frontmatter"
+ Then I should see "File Not Found"
+ When I go to "/raw-front-matter.php"
+ Then I should see ''
+ Then I should see "This is the title"
+ Then I should not see "---"
+ When I go to "/front-matter-encoding.html.erb.frontmatter"
+ Then I should see "File Not Found"
+
+ Scenario: Rendering html (json)
+ Given the Server is running at "frontmatter-neighbor-app"
+ When I go to "/json-front-matter-auto.html"
+ Then I should see "This is the title
"
+ Then I should not see ";;;"
+ When I go to "/json-front-matter-auto.erb.frontmatter"
+ Then I should see "File Not Found"
+ When I go to "/json-front-matter.html"
+ Then I should see "This is the title
"
+ Then I should not see ";;;"
+ When I go to "/json-front-matter.html.erb.frontmatter"
+ Then I should see "File Not Found"
+ When I go to "/json-front-matter-2.php"
+ Then I should see "This is the title
"
+ Then I should see "
+ """
+ And the file "source/front-matter-change.html.erb.frontmatter" has the contents
+ """
+ ---
+ title: Hello World
+ layout: false
+ ---
+ """
+ When I go to "/front-matter-change.html"
+ Then I should see "Hello World"
+ And the file "source/front-matter-change.html.erb.frontmatter" has the contents
+ """
+ ---
+ title: Hola Mundo
+ layout: false
+ ---
+ """
+ When I go to "/front-matter-change.html"
+ Then I should see "Hola Mundo"
+ When I go to "/front-matter-change.html.erb.frontmatter"
+ Then I should see "File Not Found"
+
+ Scenario: A template should handle an empty YAML feed
+ Given the Server is running at "frontmatter-neighbor-app"
+ And the file "source/front-matter-change.html.erb.frontmatter" has the contents
+ """
+ ---
+ ---
+ """
+ When I go to "/front-matter-change.html"
+ Then I should not see "Hello World"
+ Then I should not see "Hola Mundo"
+ When I go to "/front-matter-change.html.erb.frontmatter"
+ Then I should see "File Not Found"
+
+ Scenario: Setting layout, ignoring, and disabling directory indexes through frontmatter (build)
+ Given a successfully built app at "frontmatter-settings-neighbor-app"
+ Then the following files should exist:
+ | build/proxied.html |
+ And the file "build/alternate_layout.html" should contain "Alternate layout"
+ And the following files should not exist:
+ | build/ignored.html |
+ | build/alternate_layout.html.erb.frontmatter |
+ | build/ignored.html.erb.frontmatter |
+ | build/override_layout.html.erb.frontmatter |
+ | build/page_mentioned.html.erb.frontmatter |
+
+ Scenario: Setting layout, ignoring, and disabling directory indexes through frontmatter (preview)
+ Given the Server is running at "frontmatter-settings-neighbor-app"
+ When I go to "/alternate_layout.html"
+ Then I should not see "File Not Found"
+ And I should see "Alternate layout"
+ When I go to "/alternate_layout.html.erb.frontmatter"
+ Then I should see "File Not Found"
+ When I go to "/ignored.html"
+ Then I should see "File Not Found"
+ When I go to "/ignored.html.erb.frontmatter"
+ Then I should see "File Not Found"
+ When I go to "/ignored/index.html"
+ Then I should see "File Not Found"
+
+ Scenario: Changing frontmatter in preview server
+ Given the Server is running at "frontmatter-settings-neighbor-app"
+ When I go to "/ignored.html"
+ Then I should see "File Not Found"
+ And the file "source/ignored.html.erb.frontmatter" has the contents
+ """
+ ---
+ ignored: false
+ ---
+ """
+ When I go to "/ignored.html"
+ Then I should see "This file ignores itself! But it can still be proxied."
+ When I go to "/ignored.html.erb.frontmatter"
+ Then I should see "File Not Found"
+
+ Scenario: Overriding layout through frontmatter
+ Given the Server is running at "frontmatter-settings-neighbor-app"
+ When I go to "/override_layout.html"
+ Then I should see "Layout in use: Override"
+ When I go to "/override_layout.html.erb.frontmatter"
+ Then I should see "File Not Found"
+
+ Scenario: Setting layout through frontmatter even if page is mentioned in config
+ Given the Server is running at "frontmatter-settings-neighbor-app"
+ When I go to "/page_mentioned.html"
+ Then I should see "Layout in use: Override"
+ When I go to "/page_mentioned.html.erb.frontmatter"
+ Then I should see "File Not Found"
diff --git a/middleman-core/fixtures/frontmatter-neighbor-app/config.rb b/middleman-core/fixtures/frontmatter-neighbor-app/config.rb
new file mode 100644
index 00000000..e69de29b
diff --git a/middleman-core/fixtures/frontmatter-neighbor-app/source/front-matter-2.php.erb b/middleman-core/fixtures/frontmatter-neighbor-app/source/front-matter-2.php.erb
new file mode 100644
index 00000000..d74e5a71
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-neighbor-app/source/front-matter-2.php.erb
@@ -0,0 +1,2 @@
+<%= data.page.title %>
+
\ No newline at end of file
diff --git a/middleman-core/fixtures/frontmatter-neighbor-app/source/front-matter-2.php.erb.frontmatter b/middleman-core/fixtures/frontmatter-neighbor-app/source/front-matter-2.php.erb.frontmatter
new file mode 100644
index 00000000..1a0f82c3
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-neighbor-app/source/front-matter-2.php.erb.frontmatter
@@ -0,0 +1,4 @@
+---
+layout: false
+title: This is the title
+---
\ No newline at end of file
diff --git a/middleman-core/fixtures/frontmatter-neighbor-app/source/front-matter-auto.erb b/middleman-core/fixtures/frontmatter-neighbor-app/source/front-matter-auto.erb
new file mode 100644
index 00000000..c9c30179
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-neighbor-app/source/front-matter-auto.erb
@@ -0,0 +1 @@
+<%= data.page.title %>
\ No newline at end of file
diff --git a/middleman-core/fixtures/frontmatter-neighbor-app/source/front-matter-auto.erb.frontmatter b/middleman-core/fixtures/frontmatter-neighbor-app/source/front-matter-auto.erb.frontmatter
new file mode 100644
index 00000000..6227e9ef
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-neighbor-app/source/front-matter-auto.erb.frontmatter
@@ -0,0 +1,4 @@
+---
+layout: false
+title: This is the title
+---
diff --git a/middleman-core/fixtures/frontmatter-neighbor-app/source/front-matter-change.html.erb b/middleman-core/fixtures/frontmatter-neighbor-app/source/front-matter-change.html.erb
new file mode 100644
index 00000000..d0ec71cc
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-neighbor-app/source/front-matter-change.html.erb
@@ -0,0 +1 @@
+<%= data.page.title %>
\ No newline at end of file
diff --git a/middleman-core/fixtures/frontmatter-neighbor-app/source/front-matter-change.html.erb.frontmatter b/middleman-core/fixtures/frontmatter-neighbor-app/source/front-matter-change.html.erb.frontmatter
new file mode 100644
index 00000000..8c81c9ab
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-neighbor-app/source/front-matter-change.html.erb.frontmatter
@@ -0,0 +1,4 @@
+---
+title: Hola Mundo
+layout: false
+---
diff --git a/middleman-core/fixtures/frontmatter-neighbor-app/source/front-matter-encoding.html.erb b/middleman-core/fixtures/frontmatter-neighbor-app/source/front-matter-encoding.html.erb
new file mode 100644
index 00000000..c9c30179
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-neighbor-app/source/front-matter-encoding.html.erb
@@ -0,0 +1 @@
+<%= data.page.title %>
\ No newline at end of file
diff --git a/middleman-core/fixtures/frontmatter-neighbor-app/source/front-matter-encoding.html.erb.frontmatter b/middleman-core/fixtures/frontmatter-neighbor-app/source/front-matter-encoding.html.erb.frontmatter
new file mode 100644
index 00000000..daa98990
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-neighbor-app/source/front-matter-encoding.html.erb.frontmatter
@@ -0,0 +1,5 @@
+# encoding: UTF-8
+---
+layout: false
+title: This is the title
+---
\ No newline at end of file
diff --git a/middleman-core/fixtures/frontmatter-neighbor-app/source/json-front-matter-2.php.erb b/middleman-core/fixtures/frontmatter-neighbor-app/source/json-front-matter-2.php.erb
new file mode 100644
index 00000000..d74e5a71
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-neighbor-app/source/json-front-matter-2.php.erb
@@ -0,0 +1,2 @@
+<%= data.page.title %>
+
\ No newline at end of file
diff --git a/middleman-core/fixtures/frontmatter-neighbor-app/source/json-front-matter-2.php.erb.frontmatter b/middleman-core/fixtures/frontmatter-neighbor-app/source/json-front-matter-2.php.erb.frontmatter
new file mode 100644
index 00000000..415cefbc
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-neighbor-app/source/json-front-matter-2.php.erb.frontmatter
@@ -0,0 +1,4 @@
+;;;
+ "layout": false,
+ "title": "This is the title"
+;;;
\ No newline at end of file
diff --git a/middleman-core/fixtures/frontmatter-neighbor-app/source/json-front-matter-auto.erb b/middleman-core/fixtures/frontmatter-neighbor-app/source/json-front-matter-auto.erb
new file mode 100644
index 00000000..c9c30179
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-neighbor-app/source/json-front-matter-auto.erb
@@ -0,0 +1 @@
+<%= data.page.title %>
\ No newline at end of file
diff --git a/middleman-core/fixtures/frontmatter-neighbor-app/source/json-front-matter-auto.erb.frontmatter b/middleman-core/fixtures/frontmatter-neighbor-app/source/json-front-matter-auto.erb.frontmatter
new file mode 100644
index 00000000..415cefbc
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-neighbor-app/source/json-front-matter-auto.erb.frontmatter
@@ -0,0 +1,4 @@
+;;;
+ "layout": false,
+ "title": "This is the title"
+;;;
\ No newline at end of file
diff --git a/middleman-core/fixtures/frontmatter-neighbor-app/source/json-front-matter.html.erb b/middleman-core/fixtures/frontmatter-neighbor-app/source/json-front-matter.html.erb
new file mode 100644
index 00000000..c9c30179
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-neighbor-app/source/json-front-matter.html.erb
@@ -0,0 +1 @@
+<%= data.page.title %>
\ No newline at end of file
diff --git a/middleman-core/fixtures/frontmatter-neighbor-app/source/json-front-matter.html.erb.frontmatter b/middleman-core/fixtures/frontmatter-neighbor-app/source/json-front-matter.html.erb.frontmatter
new file mode 100644
index 00000000..415cefbc
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-neighbor-app/source/json-front-matter.html.erb.frontmatter
@@ -0,0 +1,4 @@
+;;;
+ "layout": false,
+ "title": "This is the title"
+;;;
\ No newline at end of file
diff --git a/middleman-core/fixtures/frontmatter-neighbor-app/source/raw-front-matter.html b/middleman-core/fixtures/frontmatter-neighbor-app/source/raw-front-matter.html
new file mode 100644
index 00000000..c9c30179
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-neighbor-app/source/raw-front-matter.html
@@ -0,0 +1 @@
+<%= data.page.title %>
\ No newline at end of file
diff --git a/middleman-core/fixtures/frontmatter-neighbor-app/source/raw-front-matter.html.frontmatter b/middleman-core/fixtures/frontmatter-neighbor-app/source/raw-front-matter.html.frontmatter
new file mode 100644
index 00000000..1a0f82c3
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-neighbor-app/source/raw-front-matter.html.frontmatter
@@ -0,0 +1,4 @@
+---
+layout: false
+title: This is the title
+---
\ No newline at end of file
diff --git a/middleman-core/fixtures/frontmatter-neighbor-app/source/raw-front-matter.php b/middleman-core/fixtures/frontmatter-neighbor-app/source/raw-front-matter.php
new file mode 100644
index 00000000..f850da7e
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-neighbor-app/source/raw-front-matter.php
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/middleman-core/fixtures/frontmatter-neighbor-app/source/raw-front-matter.php.frontmatter b/middleman-core/fixtures/frontmatter-neighbor-app/source/raw-front-matter.php.frontmatter
new file mode 100644
index 00000000..1a0f82c3
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-neighbor-app/source/raw-front-matter.php.frontmatter
@@ -0,0 +1,4 @@
+---
+layout: false
+title: This is the title
+---
\ No newline at end of file
diff --git a/middleman-core/fixtures/frontmatter-settings-neighbor-app/config.rb b/middleman-core/fixtures/frontmatter-settings-neighbor-app/config.rb
new file mode 100644
index 00000000..74cda623
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-settings-neighbor-app/config.rb
@@ -0,0 +1,4 @@
+# Proxy ignored.html, which should ignore itself through a frontmatter
+page 'proxied.html', :proxy => 'ignored.html'
+page 'override_layout.html', :layout => :alternate
+page 'page_mentioned.html'
diff --git a/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/alternate_layout.html.erb b/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/alternate_layout.html.erb
new file mode 100644
index 00000000..5d22db71
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/alternate_layout.html.erb
@@ -0,0 +1 @@
+This uses an alternate layout
diff --git a/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/alternate_layout.html.erb.frontmatter b/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/alternate_layout.html.erb.frontmatter
new file mode 100644
index 00000000..f55325f9
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/alternate_layout.html.erb.frontmatter
@@ -0,0 +1,3 @@
+---
+layout: alternate
+---
\ No newline at end of file
diff --git a/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/ignored.html.erb b/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/ignored.html.erb
new file mode 100644
index 00000000..65e59f62
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/ignored.html.erb
@@ -0,0 +1 @@
+This file ignores itself! But it can still be proxied.
diff --git a/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/ignored.html.erb.frontmatter b/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/ignored.html.erb.frontmatter
new file mode 100644
index 00000000..9277c121
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/ignored.html.erb.frontmatter
@@ -0,0 +1,3 @@
+---
+ignored: true
+---
\ No newline at end of file
diff --git a/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/layouts/alternate.erb b/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/layouts/alternate.erb
new file mode 100644
index 00000000..a38f2d07
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/layouts/alternate.erb
@@ -0,0 +1,3 @@
+Alternate layout!
+
+<%= yield %>
\ No newline at end of file
diff --git a/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/layouts/override.erb b/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/layouts/override.erb
new file mode 100644
index 00000000..fcf39dc0
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/layouts/override.erb
@@ -0,0 +1,2 @@
+<%= yield %>
+ Override.
\ No newline at end of file
diff --git a/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/override_layout.html.erb b/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/override_layout.html.erb
new file mode 100644
index 00000000..b6e2f70e
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/override_layout.html.erb
@@ -0,0 +1 @@
+Layout in use:
\ No newline at end of file
diff --git a/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/override_layout.html.erb.frontmatter b/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/override_layout.html.erb.frontmatter
new file mode 100644
index 00000000..288e7e3d
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/override_layout.html.erb.frontmatter
@@ -0,0 +1,3 @@
+---
+layout: override
+---
\ No newline at end of file
diff --git a/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/page_mentioned.html.erb b/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/page_mentioned.html.erb
new file mode 100644
index 00000000..b6e2f70e
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/page_mentioned.html.erb
@@ -0,0 +1 @@
+Layout in use:
\ No newline at end of file
diff --git a/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/page_mentioned.html.erb.frontmatter b/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/page_mentioned.html.erb.frontmatter
new file mode 100644
index 00000000..288e7e3d
--- /dev/null
+++ b/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/page_mentioned.html.erb.frontmatter
@@ -0,0 +1,3 @@
+---
+layout: override
+---
\ No newline at end of file
diff --git a/middleman-core/lib/middleman-core/core_extensions/front_matter.rb b/middleman-core/lib/middleman-core/core_extensions/front_matter.rb
index 7bafbf70..501c899a 100644
--- a/middleman-core/lib/middleman-core/core_extensions/front_matter.rb
+++ b/middleman-core/lib/middleman-core/core_extensions/front_matter.rb
@@ -28,6 +28,8 @@ module Middleman::CoreExtensions
app.after_configuration do
::Middleman::Sitemap::Resource.send :include, ResourceInstanceMethods
+ ignore %r{\.frontmatter$}
+
sitemap.provides_metadata do |path|
fmdata = frontmatter_manager.data(path).first || {}
@@ -54,7 +56,18 @@ module Middleman::CoreExtensions
def data(path)
p = normalize_path(path)
- @cache[p] ||= frontmatter_and_content(p)
+ @cache[p] ||= begin
+ in_file = frontmatter_and_content(p)
+
+ external_file = frontmatter_and_content("#{p}.frontmatter")
+
+ return in_file if external_file.nil?
+
+ [
+ external_file[0].deep_merge(in_file[0]),
+ in_file[1]
+ ]
+ end
end
def clear_data(file)
@@ -63,7 +76,7 @@ module Middleman::CoreExtensions
file = File.join(@app.root, file)
prefix = @app.source_dir.sub(/\/$/, "") + "/"
return unless file.include?(prefix)
- path = file.sub(prefix, "")
+ path = file.sub(prefix, "").sub(/\.frontmatter$/, "")
@cache.delete(path)
end
@@ -130,6 +143,8 @@ module Middleman::CoreExtensions
else
path
end
+
+ return nil unless File.exists?(full_path)
data = {}
content = nil