Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge data from data files and src file #55

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions tasks/assemble.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ module.exports = function(grunt) {
var pages = options.pages;
var collections = options.collections;
var context = {};
var datas = {};

grunt.verbose.writeln('Variables loaded');

Expand All @@ -486,7 +487,9 @@ module.exports = function(grunt) {
options.pages = undefined;
options.layout = undefined;
options.collections = undefined;
context = _.extend({}, context, assemble.util.filterProperties(options), data, pageContext);

datas = _.merge({}, data, pageContext);
context = _.extend({}, context, assemble.util.filterProperties(options), datas);
options.data = data;
options.pages = pages;
options.collections = collections;
Expand Down Expand Up @@ -523,7 +526,9 @@ module.exports = function(grunt) {
options.pages = undefined;
options.layout = undefined;
options.collections = undefined;
context = _.extend({}, context, assemble.util.filterProperties(options), layout.data, data, pageContext);
datas = _.merge({}, data, pageContext);
context = _.extend({}, context, assemble.util.filterProperties(options), layout.data, datas);

options.data = data;
options.pages = pages;
options.collections = collections;
Expand Down Expand Up @@ -651,6 +656,19 @@ module.exports = function(grunt) {

layout = grunt.file.read(layout);
layout = layout.replace(/\{{>\s*body\s*}}/, function() { return defaultLayout; });

// As we have documentation include into the pattern we need to extract the pattern content.
// Sometimes we have documenation for AMO doc and for HTML doc.
var part = /([^]*)---(?:[^]*)---(?:[^]*)---(?:[^]*)/g.exec(layout)
if (part !== null) {
layout = part[1]
} else {
// But sometimes there is only documenation for the AMO.
part = /([^]*)---(?:[^]*)---(?:[^]*)/g.exec(layout)
if (part !== null) {
layout = part[1]
}
}
}

var parsedLayout = matter(layout, assemble.options.matter);
Expand Down