Skip to content
This repository has been archived by the owner on May 5, 2021. It is now read-only.

Declare material ID in partial front-matter #13

Open
wants to merge 1 commit 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
15 changes: 13 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,17 +315,23 @@ var parseMaterials = function () {
// trim whitespace from material content
var content = fileMatter.content.replace(/^(\s*(\r?\n|\r))+|(\s*(\r?\n|\r))+$/g, '');

// get a material ID to register the partial with if declared
var materialId = fileMatter.data.materialId && fileMatter.data.materialId.length;
var partialId = '' + (materialId) ? fileMatter.data.materialId : id;
var name = (materialId) ? partialId + ' - ' + toTitleCase(id) : toTitleCase(id);


// capture meta data for the material
if (!isSubCollection) {
assembly.materials[collection].items[key] = {
name: toTitleCase(id),
name: name,
notes: (fileMatter.data.notes) ? md.render(fileMatter.data.notes) : '',
data: localData
};
} else {
name = (materialId) ? partialId + ' - ' + toTitleCase(id.split('.')[1]) : toTitleCase(id.split('.')[1]);
assembly.materials[parent].items[collection].items[key] = {
name: toTitleCase(id.split('.')[1]),
name: name,
notes: (fileMatter.data.notes) ? md.render(fileMatter.data.notes) : '',
data: localData
};
Expand All @@ -352,6 +358,11 @@ var parseMaterials = function () {
// register the partial
Handlebars.registerPartial(id, content);

// register the partial with partial ID if present
if (materialId) {
Handlebars.registerPartial(partialId, content);
}

});


Expand Down