Skip to content

Commit

Permalink
Merge pull request #8 from superwolff/update-tests
Browse files Browse the repository at this point in the history
Update tests
  • Loading branch information
Ismay committed Jul 19, 2015
2 parents fc5e6d8 + afdf946 commit 2c1f118
Show file tree
Hide file tree
Showing 39 changed files with 90 additions and 169 deletions.
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# For more information about the properties used in
# this file, please see the EditorConfig documentation:
# http://editorconfig.org/

root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[Makefile]
indent_style = tab
17 changes: 17 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Automatically normalize line endings for all text-based files
# http://git-scm.com/docs/gitattributes#_end_of_line_conversion
* text=auto

# For the following file types, normalize line endings to LF on
# checkin and prevent conversion to CRLF when they are checked out
# (this is required in order to prevent newline related issues like,
# for example, after the build script is run)
.* text eol=lf
*.css text eol=lf
*.html text eol=lf
*.js text eol=lf
*.json text eol=lf
*.md text eol=lf
*.sh text eol=lf
*.txt text eol=lf
*.xml text eol=lf
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sudo: false
language: node_js
node_js:
- "0.12"
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@

mocha=node_modules/.bin/mocha --reporter spec

node_modules: package.json
@npm install

test: node_modules
@./node_modules/.bin/mocha --reporter spec
@$(mocha)

test-debug: node_modules
@$(mocha) debug

.PHONY: test
.PHONY: test
.PHONY: test-debug
2 changes: 2 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# metalsmith-in-place

[![Build Status](https://travis-ci.org/superwolff/metalsmith-in-place.svg)](https://travis-ci.org/superwolff/metalsmith-in-place) [![Dependency Status](https://david-dm.org/superwolff/metalsmith-in-place.svg)](https://david-dm.org/superwolff/metalsmith-in-place) [![devDependency Status](https://david-dm.org/superwolff/metalsmith-in-place/dev-status.svg)](https://david-dm.org/superwolff/metalsmith-in-place#info=devDependencies)

> A metalsmith plugin for in-place templating
This plugin renders templating syntax in your source files. You can use any templating engine supported by [consolidate.js](https://github.com/tj/consolidate.js). Pass options to it with the [Javascript API](https://github.com/segmentio/metalsmith#api) or [CLI](https://github.com/segmentio/metalsmith#cli). The options are:
Expand Down
12 changes: 8 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

var consolidate = require('consolidate');
var debug = require('debug')('metalsmith-in-place');
var each = require('async').each;
var extend = require('extend');
var match = require('multimatch');
var omit = require('lodash.omit');
var utf8 = require('is-utf8');

/**
* Expose `plugin`.
Expand Down Expand Up @@ -38,8 +38,11 @@ function plugin(opts){

return function(files, metalsmith, done){
var metadata = metalsmith.metadata();
var matches = {};

function check(file){
var data = files[file];
if (!utf8(data.contents)) return false;
if (pattern && !match(file, pattern)[0]) return false;
return true;
}
Expand All @@ -49,15 +52,16 @@ function plugin(opts){
debug('stringifying file: %s', file);
var data = files[file];
data.contents = data.contents.toString();
matches[file] = data;
});

each(Object.keys(files), convert, done);
each(Object.keys(matches), convert, done);

function convert(file, done){
if (!check(file)) return done();
debug('converting file: %s', file);
var data = files[file];
var clone = extend({}, params, metadata, data);
var clonedParams = extend(true, {}, params);
var clone = extend({}, clonedParams, metadata, data);
var str = clone.contents;
var render = consolidate[engine].render;

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"devDependencies": {
"assert-dir-equal": "0.0.1",
"is-utf8": "^0.2.0",
"metalsmith": "^1.0.1",
"mocha": "1.x",
"swig": "~1.3.2"
Expand Down
8 changes: 2 additions & 6 deletions test/fixtures/basic/build/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
<html>
<body>

body
</body>
</html>

value
8 changes: 2 additions & 6 deletions test/fixtures/basic/expected/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
<html>
<body>

body
</body>
</html>

value
4 changes: 2 additions & 2 deletions test/fixtures/basic/src/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
template: layout.html
variable: value
---

body
{{variable}}
5 changes: 0 additions & 5 deletions test/fixtures/basic/templates/layout.html

This file was deleted.

3 changes: 0 additions & 3 deletions test/fixtures/default/build/default.md

This file was deleted.

2 changes: 0 additions & 2 deletions test/fixtures/default/build/other.md

This file was deleted.

3 changes: 0 additions & 3 deletions test/fixtures/default/expected/default.md

This file was deleted.

2 changes: 0 additions & 2 deletions test/fixtures/default/expected/other.md

This file was deleted.

5 changes: 0 additions & 5 deletions test/fixtures/default/src/default.md

This file was deleted.

6 changes: 0 additions & 6 deletions test/fixtures/default/src/other.md

This file was deleted.

2 changes: 0 additions & 2 deletions test/fixtures/default/templates/default.html

This file was deleted.

1 change: 0 additions & 1 deletion test/fixtures/default/templates/other.html

This file was deleted.

6 changes: 0 additions & 6 deletions test/fixtures/directory/build/index.html

This file was deleted.

6 changes: 0 additions & 6 deletions test/fixtures/directory/expected/index.html

This file was deleted.

5 changes: 0 additions & 5 deletions test/fixtures/directory/layouts/layout.html

This file was deleted.

5 changes: 0 additions & 5 deletions test/fixtures/directory/src/index.html

This file was deleted.

2 changes: 0 additions & 2 deletions test/fixtures/in-place/build/index.html

This file was deleted.

2 changes: 0 additions & 2 deletions test/fixtures/in-place/expected/index.html

This file was deleted.

5 changes: 0 additions & 5 deletions test/fixtures/in-place/src/index.html

This file was deleted.

12 changes: 3 additions & 9 deletions test/fixtures/metadata/build/one.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
<html>
<head>
<title>Local Title</title>
</head>
<body>

one
</body>
</html>
Local Title

one
12 changes: 3 additions & 9 deletions test/fixtures/metadata/build/two.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
<html>
<head>
<title>Global Title</title>
</head>
<body>

two
</body>
</html>
Global Title

two
12 changes: 3 additions & 9 deletions test/fixtures/metadata/expected/one.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
<html>
<head>
<title>Local Title</title>
</head>
<body>

one
</body>
</html>
Local Title

one
12 changes: 3 additions & 9 deletions test/fixtures/metadata/expected/two.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
<html>
<head>
<title>Global Title</title>
</head>
<body>

two
</body>
</html>
Global Title

two
2 changes: 1 addition & 1 deletion test/fixtures/metadata/src/one.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Local Title
template: layout.html
---
{{title}}

one
4 changes: 1 addition & 3 deletions test/fixtures/metadata/src/two.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
---
template: layout.html
---
{{title}}

two
8 changes: 0 additions & 8 deletions test/fixtures/metadata/templates/layout.html

This file was deleted.

1 change: 1 addition & 0 deletions test/fixtures/pattern/build/index.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
{{title}}

Not matched body
1 change: 1 addition & 0 deletions test/fixtures/pattern/expected/index.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
{{title}}

Not matched body
2 changes: 1 addition & 1 deletion test/fixtures/pattern/src/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Not matched
template: layout.html
---
{{title}}

Not matched body
2 changes: 1 addition & 1 deletion test/fixtures/pattern/src/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Matched
template: layout.html
---
{{title}}

Matched body
2 changes: 0 additions & 2 deletions test/fixtures/pattern/templates/layout.html

This file was deleted.

Loading

0 comments on commit 2c1f118

Please sign in to comment.