metalsmith-jstransformer
Advanced tools
Comparing version 0.0.1 to 0.0.2
41
index.js
var minimatch = require('minimatch'); | ||
var jstransformer = require('jstransformer'); | ||
var path = require('path'); | ||
var merge = require('merge'); | ||
function plugin (opts) { | ||
module.exports = function (opts) { | ||
var transformers = {}; | ||
var mix = function(obj1, obj2) { | ||
var newObj = {}; | ||
var key; | ||
for (key in obj1) { | ||
if (obj1.hasOwnProperty(key)) { | ||
newObj[key] = obj1[key]; | ||
} | ||
} | ||
for (key in obj2) { | ||
if (obj2.hasOwnProperty(key)) { | ||
newObj[key] = obj2[key]; | ||
} | ||
} | ||
return newObj; | ||
}; | ||
// Load all the required JSTransformers. | ||
@@ -32,15 +17,9 @@ for (var i in opts || {}) { | ||
for (var transform in transformers) { | ||
// Find all files that can be handled by the given transform. | ||
// TODO: Use .inputFormats(). | ||
var process = Object.keys(files).filter( | ||
minimatch.filter('*.' + transform, { | ||
matchBase: true | ||
}) | ||
); | ||
// Loop through each transformable file. | ||
for (var file in process) { | ||
var filename = process[file]; | ||
// Find all files that match the given transformer. | ||
var transformFiles = minimatch.match(Object.keys(files), "*." + transform); | ||
for (var i in transformFiles) { | ||
var filename = transformFiles[i]; | ||
var data = files[filename]; | ||
var locals = mix(data, metalsmith.metadata()); | ||
var locals = merge(data, metalsmith.metadata()); | ||
@@ -56,3 +35,3 @@ // Construct the new file name. | ||
// Process the file contents using the transformer. | ||
var result = transformers[transform].render(data.contents, locals); | ||
var result = transformers[transform].render(data.contents.toString('utf-8'), locals); | ||
data.contents = new Buffer(result.body); | ||
@@ -68,4 +47,2 @@ | ||
} | ||
} | ||
module.exports = plugin; | ||
}; |
{ | ||
"name": "metalsmith-jstransformer", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Metalsmith JSTransformer Plugin", | ||
@@ -26,11 +26,13 @@ "main": "index.js", | ||
"dependencies": { | ||
"jstransformer": "~0.0.2", | ||
"jstransformer": "^0.0.2", | ||
"merge": "^1.2.0", | ||
"minimatch": "^2.0.4" | ||
}, | ||
"devDependencies": { | ||
"jstransformer-jade": "~0.0.3", | ||
"assert-dir-equal": "*", | ||
"metalsmith": "^1.5.0", | ||
"jstransformer-jade": "*", | ||
"jstransformer-styl": "^0.1.0", | ||
"metalsmith": "^1.7.0", | ||
"mocha": "*" | ||
} | ||
} |
@@ -18,2 +18,6 @@ # Metalsmith JSTransformer Plugin | ||
First, create a file that you would like to act on with JSTransformers, with | ||
the file name of "example.html.<pluginname>". In the following Jade example, it | ||
would be `example.html.jade`. | ||
### CLI | ||
@@ -43,3 +47,3 @@ | ||
metalsmith.use(jstransformer([ | ||
'jade' | ||
"jade" | ||
])); | ||
@@ -53,3 +57,3 @@ ``` | ||
```javascript | ||
['jade', 'scss'] | ||
["jade", "scss"] | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57
5104
3
5
36
+ Addedmerge@^1.2.0
+ Addedasap@1.0.0(transitive)
+ Addedjstransformer@0.0.2(transitive)
+ Addedmerge@1.2.1(transitive)
+ Addedpromise@6.1.0(transitive)
- Removedasap@2.0.6(transitive)
- Removedjstransformer@0.0.4(transitive)
- Removedpromise@7.3.1(transitive)
Updatedjstransformer@^0.0.2