Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3c2a5a1
Showing
7 changed files
with
254 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
node_modules/ | ||
.idea/ | ||
index.html | ||
.DS_Store | ||
.anvil/ | ||
plugins/anvil.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
node_modules/ | ||
.idea/ | ||
index.html | ||
.DS_Store | ||
.anvil/ | ||
plugins/anvil.* |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/*global require, console, module */ | ||
|
||
// Require Mustache. This task depends on mustache. If you don't have it, run "npm install mustache" in your terminal. | ||
var mustache = require("mustache"); | ||
|
||
var pluginFactory = function( _, anvil ) { | ||
|
||
'use strict'; | ||
|
||
return anvil.plugin( { | ||
|
||
name: "anvil.mustache", | ||
|
||
// Activity list: "identify", "pull", "combine", "pre-process","compile", "post-process", "push", "test" | ||
activity: "post-process", | ||
|
||
// The config data is used to pass into each of the mustache templates | ||
config: { | ||
data: {}, | ||
formats: ["md", "html", "handelbars", "hb", "mustache"] | ||
}, | ||
|
||
// Tests to see if the file should be mustached | ||
isMustache: function (file) { | ||
|
||
var self = this, | ||
isMustache = false; | ||
|
||
// Loop over all of the formats. If the file is one of the mustache formats, return true | ||
_.each(self.config.formats, function (format) { | ||
if (file.name.indexOf('.' + format) !== -1) { | ||
isMustache = true; | ||
} | ||
}); | ||
|
||
return isMustache; | ||
|
||
}, | ||
|
||
// Compiles individual files | ||
compileFile: function (file) { | ||
|
||
var self = this; | ||
|
||
// If the file is a html, handelbars or mustache file, process it | ||
if (self.isMustache(file)) { | ||
|
||
// This is the temp file | ||
file.workingFile = file.workingPath + "/" + file.name; | ||
|
||
// Read the temp file | ||
anvil.fs.read(file.workingFile, function (html) { | ||
|
||
// Markdown screws up some mustache partial include tags... this should fix it | ||
html = html.replace(/\{\{>/g, '{{>'); | ||
|
||
// Render the template with mustache | ||
file.template = mustache.render(html, self.config.data, self.config.data.partials); | ||
|
||
// Re-write the temp file | ||
anvil.fs.write(file.workingFile, file.template, function () { | ||
|
||
// Report the compilation to the command line | ||
console.log(" mustached " + (file.relativePath + '/' + file.name).replace('//', '/')); | ||
|
||
}); | ||
|
||
}); | ||
|
||
} | ||
|
||
}, | ||
|
||
// Compiles individual partials | ||
compilePartial: function (partial, index) { | ||
|
||
var self = this; | ||
|
||
// Read the partial | ||
anvil.fs.read(anvil.config.working + '/' + partial, function (html) { | ||
self.config.data.partials[index] = html; | ||
}); | ||
|
||
}, | ||
|
||
// Run all the things... | ||
run: function( done ) { | ||
|
||
var self = this; | ||
|
||
// Default the partials | ||
this.config.data.partials = _.extend({}, this.config.data.partials); | ||
|
||
// Loop over the partials and add them as HTML | ||
_.each(this.config.data.partials, self.compilePartial); | ||
|
||
// Loop over all of the files | ||
_.each(anvil.project.files, self.compileFile); | ||
|
||
done(); | ||
|
||
} | ||
|
||
} ); | ||
}; | ||
|
||
module.exports = pluginFactory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"author": { | ||
"name": "Tyson Cadenhead", | ||
"email": "tcadenhead@appendto.com", | ||
"url": "http://appendto.com" | ||
}, | ||
"name": "anvil.mustache", | ||
"description": "Mustache plugin for anvil.js", | ||
"version": "0.0.1", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/tysoncadenhead/anvil.mustache.git" | ||
}, | ||
"engines": { | ||
"node": "~0.8.3" | ||
}, | ||
"main": "./lib/plugin.js", | ||
"dependencies": { | ||
"mustache": ">=0.7.0" | ||
}, | ||
"devDependencies": { | ||
"anvil.js": ">=0.8.4" | ||
}, | ||
"optionalDependencies": {}, | ||
"readme": "## Anvil Mustache Plugin\n\nThis plugin requires anvil.js version 0.8.* or greater.\n\n## Installation\n\n\tanvil install anvil.mustache", | ||
"_id": "anvil.mustache@0.0.1", | ||
"_from": "anvil.mustache" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/*global require, console, module */ | ||
|
||
// Require Mustache. This task depends on mustache. If you don't have it, run "npm install mustache" in your terminal. | ||
var mustache = require("mustache"); | ||
|
||
var pluginFactory = function( _, anvil ) { | ||
|
||
'use strict'; | ||
|
||
return anvil.plugin( { | ||
|
||
name: "anvil.mustache", | ||
|
||
// Activity list: "identify", "pull", "combine", "pre-process","compile", "post-process", "push", "test" | ||
activity: "post-process", | ||
|
||
// The config data is used to pass into each of the mustache templates | ||
config: { | ||
data: {}, | ||
formats: ["md", "html", "handelbars", "hb", "mustache"] | ||
}, | ||
|
||
// Tests to see if the file should be mustached | ||
isMustache: function (file) { | ||
|
||
var self = this, | ||
isMustache = false; | ||
|
||
// Loop over all of the formats. If the file is one of the mustache formats, return true | ||
_.each(self.config.formats, function (format) { | ||
if (file.name.indexOf('.' + format) !== -1) { | ||
isMustache = true; | ||
} | ||
}); | ||
|
||
return isMustache; | ||
|
||
}, | ||
|
||
// Compiles individual files | ||
compileFile: function (file) { | ||
|
||
var self = this; | ||
|
||
// If the file is a html, handelbars or mustache file, process it | ||
if (self.isMustache(file)) { | ||
|
||
// This is the temp file | ||
file.workingFile = file.workingPath + "/" + file.name; | ||
|
||
// Read the temp file | ||
anvil.fs.read(file.workingFile, function (html) { | ||
|
||
// Markdown screws up some mustache partial include tags... this should fix it | ||
html = html.replace(/\{\{>/g, '{{>'); | ||
|
||
// Render the template with mustache | ||
file.template = mustache.render(html, self.config.data, self.config.data.partials); | ||
|
||
// Re-write the temp file | ||
anvil.fs.write(file.workingFile, file.template, function () { | ||
|
||
// Report the compilation to the command line | ||
console.log(" mustached " + (file.relativePath + '/' + file.name).replace('//', '/')); | ||
|
||
}); | ||
|
||
}); | ||
|
||
} | ||
|
||
}, | ||
|
||
// Compiles individual partials | ||
compilePartial: function (partial, index) { | ||
|
||
var self = this; | ||
|
||
// Read the partial | ||
anvil.fs.read(anvil.config.working + '/' + partial, function (html) { | ||
self.config.data.partials[index] = html; | ||
}); | ||
|
||
}, | ||
|
||
// Run all the things... | ||
run: function( done ) { | ||
|
||
var self = this; | ||
|
||
// Default the partials | ||
this.config.data.partials = _.extend({}, this.config.data.partials); | ||
|
||
// Loop over the partials and add them as HTML | ||
_.each(this.config.data.partials, self.compilePartial); | ||
|
||
// Loop over all of the files | ||
_.each(anvil.project.files, self.compileFile); | ||
|
||
done(); | ||
|
||
} | ||
|
||
} ); | ||
}; | ||
|
||
module.exports = pluginFactory; |