* mix in metadata
This commit is contained in:
Ian Storm Taylor 2014-02-05 11:44:18 -08:00
parent 53b63f440a
commit 07ca571862
11 changed files with 74 additions and 4 deletions

View file

@ -1,4 +1,8 @@
0.0.2 - February 5, 2013
------------------------
* mix in metadata
0.0.1 - February 4, 2013
------------------------
:sparkles:

View file

@ -1,5 +1,6 @@
var consolidate = require('consolidate');
var defaults = require('defaults');
var each = require('async').each;
/**
@ -21,10 +22,12 @@ function plugin(opts){
if (!opts.engine) throw new Error('"engine" option required');
return function(files, metalsmith, done){
var metadata = metalsmith.metadata();
each(Object.keys(files), convert, done);
function convert(file, done){
var data = files[file];
var data = defaults(files[file], metadata);
var template = data.template;
if (!template) return done();
var tmpl = metalsmith.join(opts.dir, template);

View file

@ -2,16 +2,17 @@
"name": "metalsmith-templates",
"description": "A metalsmith plugin to render files with templates.",
"repository": "git://github.com/segmentio/metalsmith-templates.git",
"version": "0.0.1",
"version": "0.0.2",
"license": "MIT",
"main": "lib/index.js",
"dependencies": {
"consolidate": "~0.10.0",
"async": "~0.2.10"
"async": "~0.2.10",
"defaults": "~1.0.0"
},
"devDependencies": {
"mocha": "1.x",
"metalsmith": "0.0.0",
"metalsmith": "0.0.2",
"swig": "~1.3.2",
"assert-dir-equal": "0.0.1"
}

8
test/fixtures/metadata/build/one.html vendored Normal file
View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Local Title</title>
</head>
<body>
one
</body>
</html>

8
test/fixtures/metadata/build/two.html vendored Normal file
View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Global Title</title>
</head>
<body>
two
</body>
</html>

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Local Title</title>
</head>
<body>
one
</body>
</html>

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Global Title</title>
</head>
<body>
two
</body>
</html>

6
test/fixtures/metadata/src/one.html vendored Normal file
View file

@ -0,0 +1,6 @@
---
title: Local Title
template: layout.html
---
one

5
test/fixtures/metadata/src/two.html vendored Normal file
View file

@ -0,0 +1,5 @@
---
template: layout.html
---
two

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>{{title}}</title>
</head>
<body>
{{body}}
</body>
</html>

View file

@ -24,4 +24,15 @@ describe('metalsmith-templates', function(){
done();
});
});
it('should mix in global metadata', function(done){
Metalsmith('test/fixtures/metadata')
.metadata({ title: 'Global Title' })
.use(templates({ engine: 'swig' }))
.build(function(err){
if (err) return done(err);
equal('test/fixtures/metadata/expected', 'test/fixtures/metadata/build');
done();
});
});
});