grunt-textfile
Advanced tools
Comparing version 0.1.6 to 0.1.7
@@ -36,2 +36,3 @@ /* | ||
dest: 'tmp', | ||
openFile: true | ||
}, | ||
@@ -38,0 +39,0 @@ linkpost: { |
{ | ||
"name": "grunt-textfile", | ||
"description": "A grunt task to quickly create text files for text file based blogging.", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"homepage": "https://github.com/kahlil/grunt-textfile", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -30,2 +30,3 @@ # grunt-textfile | ||
dest: 'content/blog', | ||
openFile: true | ||
}, | ||
@@ -103,2 +104,12 @@ linkpost: { | ||
#### options.openFile | ||
Specify if you want the generated file to opened in an editor. | ||
Type: `Boolean` | ||
Default Value: `false` | ||
#### options.openWith | ||
Specify which editor you want the generated file to be opened with. | ||
Type: `String` | ||
Default Value: `subl` | ||
### Usage Examples | ||
@@ -113,3 +124,4 @@ | ||
options: { | ||
dest: 'content/blog' | ||
dest: 'content/blog', | ||
openFile: true | ||
}, | ||
@@ -152,3 +164,4 @@ linkpost: { | ||
options: { | ||
dest: '_posts' | ||
dest: '_posts', | ||
openFile: true | ||
}, | ||
@@ -188,3 +201,4 @@ article: { | ||
``` | ||
v0.1.0: initial release | ||
v0.1.7: add 'openFile' and 'openFile' options to open the generated file in an editor. | ||
v0.1.0: initial release. | ||
``` |
@@ -16,3 +16,3 @@ /* | ||
grunt.registerMultiTask('textfile', 'Create a new post for your text file based blogging software.', function() { | ||
var options, template, filename; | ||
var options, template, filename, filePath, result, fullPath; | ||
// Merge task-specific and/or target-specific options with these defaults. | ||
@@ -30,2 +30,6 @@ options = this.options({ | ||
urlFormat: 'PREFIX-SLUG/article.link.txt', | ||
// Set to true if you want the file to be opened in your editor | ||
openFile: false, | ||
// Set your fav editor by providing the cli command for you fav editor | ||
openWith: 'subl' | ||
}); | ||
@@ -39,3 +43,3 @@ | ||
// Check if the file exists. | ||
var filePath = './' + options.templateDir + '/' + options.template; | ||
filePath = './' + options.templateDir + '/' + options.template; | ||
if (!grunt.file.exists(filePath)) { | ||
@@ -47,10 +51,18 @@ grunt.log.warn('Template file "' + filePath + '" not found.'); | ||
} | ||
// Process the template file. | ||
var result = grunt.util.normalizelf(grunt.template.process(template)); | ||
var fullPath = options.dest + '/' + filename; | ||
result = grunt.util.normalizelf(grunt.template.process(template)); | ||
// Put together the full path to the file. | ||
fullPath = options.dest + '/' + filename; | ||
// Write the file to specified path. | ||
grunt.file.write(fullPath, result); | ||
// Log success! | ||
grunt.log.writeln('File "' + fullPath + '" created.'); | ||
// Open file in editor if desired. | ||
if(options.openFile) { | ||
grunt.util.spawn({ | ||
cmd: options.openWith, | ||
args: [fullPath] | ||
}, function(error, result, code) { grunt.log.error(error); }); | ||
} | ||
}); | ||
}; |
@@ -1,4 +0,4 @@ | ||
Title: "This is the title" | ||
Title: This is the title | ||
---- | ||
Link: "http://thisisthelink.com" | ||
Link: http://thisisthelink.com | ||
---- | ||
@@ -5,0 +5,0 @@ Date: 2013-06-06 |
@@ -6,22 +6,2 @@ 'use strict'; | ||
/* | ||
======== A Handy Little Nodeunit Reference ======== | ||
https://github.com/caolan/nodeunit | ||
Test methods: | ||
test.expect(numAssertions) | ||
test.done() | ||
Test assertions: | ||
test.ok(value, [message]) | ||
test.equal(actual, expected, [message]) | ||
test.notEqual(actual, expected, [message]) | ||
test.deepEqual(actual, expected, [message]) | ||
test.notDeepEqual(actual, expected, [message]) | ||
test.strictEqual(actual, expected, [message]) | ||
test.notStrictEqual(actual, expected, [message]) | ||
test.throws(block, [error], [message]) | ||
test.doesNotThrow(block, [error], [message]) | ||
test.ifError(value) | ||
*/ | ||
exports.textfile = { | ||
@@ -58,3 +38,3 @@ setUp: function(done) { | ||
}, | ||
default_options: function(test) { | ||
generateLinkpost: function(test) { | ||
var actual, expected; | ||
@@ -65,3 +45,3 @@ test.expect(1); | ||
grunt: true, | ||
args: ['textfile:linkpost', '--link="http://thisisthelink.com"', '--title="This is the title"'] | ||
args: ['textfile:linkpost', '--link=http://thisisthelink.com', '--title=This is the title'] | ||
}, function() { | ||
@@ -68,0 +48,0 @@ actual = grunt.file.read('tmp/1-this-is-the-title/article.link.txt'); |
Sorry, the diff of this file is not supported yet
13638
199
191