Socket
Socket
Sign inDemoInstall

fabricator-assemble

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fabricator-assemble - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

test/fixtures/materials/components/alerts/primary.html

122

index.js

@@ -13,2 +13,3 @@ // modules

var Q = require('q');
var sortObj = require('sort-object');
var yaml = require('js-yaml');

@@ -155,24 +156,56 @@

// get files
var files = globby.sync(options.materials, { nodir: true });
// get files and dirs
var files = globby.sync(options.materials, { nodir: true, nosort: true });
// get all directories
var dirs = files.map(function (file) {
return path.dirname(file).split(path.sep).pop();
});
// stub out an object for each collection and subCollection
files.forEach(function (file) {
var parent = path.dirname(file).split(path.sep).slice(-2, -1)[0];
var collection = path.dirname(file).split(path.sep).pop();
var isSubCollection = (dirs.indexOf(parent) > -1);
if (!isSubCollection) {
assembly.materials[collection] = assembly.materials[collection] || {
name: changeCase.titleCase(collection),
items: {}
};
} else {
assembly.materials[parent].items[collection] = assembly.materials[parent].items[collection] || {
name: changeCase.titleCase(collection),
items: {}
};
}
});
// iterate over each file (material)
files.forEach(function (file) {
// get info
var id = getFileName(file);
var fileMatter = matter.read(file);
var collection = path.dirname(file).split(path.sep).pop();
var parent = path.dirname(file).split(path.sep).slice(-2, -1)[0];
var isSubCollection = (dirs.indexOf(parent) > -1);
var id = (isSubCollection) ? collection + '.' + getFileName(file) : getFileName(file);
// create collection (e.g. "components", "structures") if it doesn't already exist
assembly.materials[collection] = assembly.materials[collection] || {
name: changeCase.titleCase(collection),
items: {}
};
// capture meta data for the material
assembly.materials[collection].items[id] = {
name: changeCase.titleCase(id),
notes: (fileMatter.data.notes) ? md.render(fileMatter.data.notes) : ''
};
if (!isSubCollection) {
assembly.materials[collection].items[id] = {
name: changeCase.titleCase(id),
notes: (fileMatter.data.notes) ? md.render(fileMatter.data.notes) : ''
};
} else {
assembly.materials[parent].items[collection].items[id] = {
name: changeCase.titleCase(id.split('.')[1]),
notes: (fileMatter.data.notes) ? md.render(fileMatter.data.notes) : ''
};
}

@@ -185,23 +218,9 @@ // register the partial, trim whitespace

// register the 'material' helper used for more dynamic partial includes
Handlebars.registerHelper('material', function (name, context) {
// sort materials object alphabetically
assembly.materials = sortObj(assembly.materials);
var template = Handlebars.partials[name],
fn;
for (var collection in assembly.materials) {
assembly.materials[collection].items = sortObj(assembly.materials[collection].items);
}
// check to see if template is already compiled
if (!_.isFunction(template)) {
fn = Handlebars.compile(template);
} else {
fn = template;
}
return beautifyHtml(fn(buildContext(context)).replace(/^\s+/, ''), {
indent_size: 1,
indent_char: ' ',
indent_with_tabs: true
});
});
};

@@ -319,3 +338,3 @@

name: changeCase.titleCase(id)
}
};

@@ -330,2 +349,38 @@ }

/**
* Register new Handlebars helpers
* @return {[type]} [description]
*/
var registerHelpers = function () {
/**
* `material`
* @description Like a normal partial include (`{{> partialName }}`),
* but with some additional templating logic to help with nested block iterations
* @example
* {{material name context}}
*/
Handlebars.registerHelper('material', function (name, context) {
var template = Handlebars.partials[name],
fn;
// check to see if template is already compiled
if (!_.isFunction(template)) {
fn = Handlebars.compile(template);
} else {
fn = template;
}
return beautifyHtml(fn(buildContext(context)).replace(/^\s+/, ''), {
indent_size: 1,
indent_char: ' ',
indent_with_tabs: true
});
});
};
/**
* Setup the assembly

@@ -340,2 +395,3 @@ * @param {Objet} options User options

// setup steps
registerHelpers();
parseLayouts();

@@ -342,0 +398,0 @@ parseLayoutIncludes();

{
"name": "fabricator-assemble",
"version": "0.1.1",
"version": "0.1.2",
"description": "The assembly engine behind Fabricator",

@@ -30,3 +30,4 @@ "main": "index.js",

"mkdirp": "^0.5.0",
"q": "^1.2.0"
"q": "^1.2.0",
"sort-object": "^1.0.0"
},

@@ -33,0 +34,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc