diff --git a/index.js b/index.js index 556972d..c72b35c 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ /** - * Handlebars Helper: {{rawinclude}} + * Handlebars Helper: {{{rawinclude}}} * Copyright © 2014-2016 Ain Tohvri * Licensed under GPL-3.0 */ @@ -7,12 +7,12 @@ 'use strict'; /** - * {{rawinclude}} + * {{{rawinclude}}} * Like {{ include }} but without context. * * @param {String} path Path of the file to include. * @return {String} Returns raw content of the file at path. - * @example: {{rawinclude '/path/to/compund.svg'}} + * @example: {{{rawinclude '/path/to/compund.svg'}}} * @todo support for Array input, minimatch. */ exports.rawinclude = function (path, options) { @@ -24,9 +24,7 @@ exports.rawinclude = function (path, options) { options = options || {}; options.hash = options.hash || {}; - var Handlebars = require('handlebars'); - var matter = require('gray-matter'); + var fs = require('fs') - var result = matter.read(path); - return new Handlebars.SafeString(result.content); + return fs.readFileSync(path, 'utf8'); }; diff --git a/package.json b/package.json index a50e38d..e0f2ebd 100644 --- a/package.json +++ b/package.json @@ -25,9 +25,6 @@ "scripts": { "test": "mocha" }, - "dependencies": { - "gray-matter": "~2.0.2" - }, "peerDependencies": { "handlebars": "~4.0.5" }, diff --git a/test.js b/test.js index 7ecbf5f..fc4aa71 100644 --- a/test.js +++ b/test.js @@ -1,37 +1,37 @@ var should = require('should'); var Handlebars = require('handlebars'); var helpers = require('./index'); -var matter = require('gray-matter'); +var fs = require('fs'); Handlebars.registerHelper("rawinclude", helpers.rawinclude); describe('parsing', function () { it('should parse fixtures/GPLv3_Logo.svg into template', function () { - var template = Handlebars.compile('{{rawinclude "fixtures/GPLv3_Logo.svg"}}'); - var context = matter.read('fixtures/GPLv3_Logo.svg'); - template({}).should.eql(context.content); + var template = Handlebars.compile('{{{rawinclude "fixtures/GPLv3_Logo.svg"}}}'); + var content = fs.readFileSync('fixtures/GPLv3_Logo.svg', 'utf8'); + template({}).should.eql(content); }); it('should parse fixtures/circle.svg into template', function () { - var template = Handlebars.compile('{{rawinclude "fixtures/circle.svg"}}'); - var context = matter.read('fixtures/circle.svg'); - template({}).should.eql(context.content); + var template = Handlebars.compile('{{{rawinclude "fixtures/circle.svg"}}}'); + var content = fs.readFileSync('fixtures/circle.svg', 'utf8'); + template({}).should.eql(content); }); it('should parse fixtures/simple.json into template', function () { - var template = Handlebars.compile('{{rawinclude "fixtures/simple.json"}}'); - var context = matter.read('fixtures/simple.json'); - template({}).should.eql(context.content); + var template = Handlebars.compile('{{{rawinclude "fixtures/simple.json"}}}'); + var content = fs.readFileSync('fixtures/simple.json', 'utf8'); + template({}).should.eql(content); }); it('should parse fixtures/circle.svg with correctly using gray-matter', function () { - var template = Handlebars.compile('{{rawinclude "fixtures/circle.svg"}}'); + var template = Handlebars.compile('{{{rawinclude "fixtures/circle.svg"}}}'); template({}).should.eql('\n\n\n \n \n \n \n \n \n \n\n'); }); }); describe('errorhandling', function () { it('should throw TypeError on non-string key', function () { - Handlebars.compile('{{rawinclude foo}}').should.throw(TypeError); + Handlebars.compile('{{{rawinclude foo}}}').should.throw(TypeError); }); });