grunt-ejs-static
Advanced tools
Comparing version 0.3.3 to 0.3.4
105
Gruntfile.js
@@ -32,7 +32,8 @@ /* | ||
post_optimize: [ | ||
'demo/production/pages', | ||
'demo/production/pages', | ||
'demo/production/templates', | ||
'demo/production/head.ejs', | ||
'demo/production/scripts.ejs' | ||
] | ||
], | ||
test: ['tests/test*'] | ||
}, | ||
@@ -71,3 +72,3 @@ | ||
'demo/production/scripts.ejs' | ||
] | ||
] | ||
}, | ||
@@ -89,8 +90,6 @@ | ||
path_to_layouts: 'demo/dev/layouts/', | ||
global_data: 'global' | ||
// index_page: 'home', | ||
// parent_dirs: false, | ||
// underscores_to_dashes: true, | ||
// file_extension: '.html', | ||
// path_separator: '/' | ||
index_page: 'home', | ||
parent_dirs: false, | ||
underscores_to_dashes: true, | ||
file_extension: '.html' | ||
} | ||
@@ -106,6 +105,59 @@ }, | ||
underscores_to_dashes: true, | ||
file_extension: '.html', | ||
global_data: 'global', | ||
path_separator: '/' | ||
file_extension: '.html' | ||
} | ||
}, | ||
test1: { | ||
options: { | ||
dest: 'tests/test1', | ||
path_to_data: 'demo/dev/data/data.json', | ||
path_to_layouts: 'demo/dev/layouts', | ||
index_page: 'home', | ||
parent_dirs: false, | ||
underscores_to_dashes: true, | ||
file_extension: '.html' | ||
} | ||
}, | ||
test2: { | ||
options: { | ||
dest: 'tests/test2', | ||
path_to_data: 'demo/dev/data/data.json', | ||
path_to_layouts: 'demo/dev/layouts', | ||
index_page: 'home', | ||
parent_dirs: true, | ||
underscores_to_dashes: true, | ||
file_extension: '.html' | ||
} | ||
}, | ||
test3: { | ||
options: { | ||
dest: 'tests/test3', | ||
path_to_data: 'demo/dev/data/data.json', | ||
path_to_layouts: 'demo/dev/layouts', | ||
index_page: 'home', | ||
parent_dirs: false, | ||
underscores_to_dashes: true, | ||
file_extension: '.html' | ||
} | ||
}, | ||
test4: { | ||
options: { | ||
dest: 'tests/test4', | ||
path_to_data: 'demo/dev/data/data.json', | ||
path_to_layouts: 'demo/dev/layouts', | ||
index_page: 'home', | ||
parent_dirs: false, | ||
underscores_to_dashes: false, | ||
file_extension: '.html' | ||
} | ||
}, | ||
test5: { | ||
options: { | ||
dest: 'tests/test5', | ||
path_to_data: 'demo/dev/data/data.json', | ||
path_to_layouts: 'demo/dev/layouts', | ||
index_page: 'home', | ||
parent_dirs: false, | ||
underscores_to_dashes: true, | ||
file_extension: '.php' | ||
} | ||
} | ||
@@ -116,3 +168,3 @@ }, | ||
nodeunit: { | ||
tests: ['test/*_test.js'], | ||
tests: ['test/ejs_static_test.js'], | ||
}, | ||
@@ -138,6 +190,4 @@ | ||
'clean:preview', | ||
'copy:preview', | ||
'copy:preview', | ||
'ejs_static:preview' | ||
// , | ||
// 'nodeunit' | ||
]); | ||
@@ -149,13 +199,22 @@ | ||
'copy:optimize', | ||
'useminPrepare', | ||
'concat', | ||
'cssmin', | ||
'uglify', | ||
'usemin', | ||
'useminPrepare', | ||
'concat', | ||
'cssmin', | ||
'uglify', | ||
'usemin', | ||
'ejs_static:optimize', | ||
'clean:post_optimize' | ||
// , | ||
// 'nodeunit' | ||
]); | ||
// test | ||
grunt.registerTask('test', [ | ||
'clean:test', | ||
'ejs_static:test1', | ||
'ejs_static:test2', | ||
'ejs_static:test3', | ||
'ejs_static:test4', | ||
'ejs_static:test5', | ||
'nodeunit' | ||
]); | ||
}; |
@@ -28,6 +28,6 @@ | ||
grunt.fail.warn('A value for path_to_layout is required, please specify in data file for key: ' + key); | ||
} | ||
} | ||
} | ||
// end generate path to layout | ||
// end generate path to layout | ||
@@ -46,4 +46,7 @@ // search the layouts dir for a dir or file that matches key | ||
var path_to_layout = grunt.file.expand(search_pattern1, search_pattern2, search_pattern3); | ||
var search_pattern4 = path.join(options.path_to_layouts, '**', key, 'index.html'); | ||
grunt.log.debug('search pattern4 is ' + search_pattern4); | ||
var path_to_layout = grunt.file.expand(search_pattern1, search_pattern2, search_pattern3, search_pattern4); | ||
// if exactly one path to layout is returned, return that path | ||
@@ -64,4 +67,4 @@ if (path_to_layout.length === 1) { | ||
grunt.fail.warn('More than 1 path to layout file was not found for key: ' + key + | ||
'\nThe paths found were: \n' + multiple_layout_paths + | ||
grunt.fail.warn('More than 1 path to layout file was not found for key: ' + key + | ||
'\nThe paths found were: \n' + multiple_layout_paths + | ||
'\nResolve in the project dir structure and/or data file\n'); | ||
@@ -77,3 +80,3 @@ | ||
// | ||
// | ||
// END PRIVATE FUNCTIONS | ||
@@ -101,2 +104,2 @@ | ||
}; | ||
}; |
{ | ||
"name": "grunt-ejs-static", | ||
"description": "Compile static html from ejs templates", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"homepage": "https://github.com/shaekuronen/grunt-ejs-static", | ||
@@ -57,3 +57,6 @@ "author": { | ||
"embedded js" | ||
] | ||
], | ||
"scripts": { | ||
"test": "grunt test" | ||
} | ||
} |
# grunt-ejs-static | ||
Grunt EJS Static takes an MVC approach to building a static site generator using EJS and Grunt. | ||
[![Build Status](https://travis-ci.org/shaekuronen/grunt-ejs-static.png?branch=master)](https://travis-ci.org/shaekuronen/grunt-ejs-static) | ||
Models can be defined in multiple JSON files, which helps keep logic out of the templates and the data more maintainable. | ||
Grunt EJS Static takes an MVC approach to building a static site generator using EJS and Grunt. | ||
Views are defined in layout files, which are top-level templates utilizing EJS Includes to manage layout. | ||
Models can be defined in multiple JSON files, which helps keep logic out of the templates and the data more maintainable. | ||
The controller is a JSON file (such as routes.json) which defines files to render, as well as each file's layout and any additional data needed for rendering. | ||
Views are defined in layout files, which are top-level templates utilizing EJS Includes to manage layout. | ||
The controller is a JSON file (such as routes.json) which defines files to render, as well as each file's layout and any additional data needed for rendering. | ||
For examples, please see demo/ and Usage section below | ||
@@ -35,7 +37,7 @@ | ||
Conditionally required options are path_to_layouts. | ||
Conditionally required options are path_to_layouts. | ||
If layout paths are specified in data.json (recommended), options.path_to_layouts is not necessary. | ||
If layout paths are specified in data.json (recommended), options.path_to_layouts is not necessary. | ||
If layout paths are not specified, ejs_static falls back to searching the dir specified in options.path_to_layouts. | ||
If layout paths are not specified, ejs_static falls back to searching the dir specified in options.path_to_layouts. | ||
@@ -103,3 +105,3 @@ ```js | ||
``` | ||
Generates this JSON data model | ||
Generates this JSON data model | ||
```json | ||
@@ -212,3 +214,3 @@ { | ||
<div class="container"> | ||
<footer> | ||
@@ -230,3 +232,3 @@ <p>© Company 2012</p> | ||
#### options.dest | ||
#### options.dest | ||
Required | ||
@@ -247,3 +249,3 @@ Type: `String` | ||
This is the path to the layout files directory | ||
This is the path to the layout files directory | ||
@@ -254,3 +256,3 @@ #### options.index_page | ||
This sets the index page for the site | ||
This sets the index page for the site | ||
@@ -281,5 +283,5 @@ #### options.parent_dirs | ||
This defines the file extension of rendered files | ||
This defines the file extension of rendered files | ||
Defaults to .html, but could be .php, .aspx, etc | ||
Defaults to .html, but could be .php, .aspx, etc | ||
@@ -307,3 +309,3 @@ | ||
This builds static html into demo/production/ | ||
This builds static html into demo/production/ | ||
@@ -316,5 +318,5 @@ ## Contributing | ||
* Moved logic into modules. | ||
* Improved management of data files. Combine files, or parse for a specific key, prior to rendering. | ||
* Improved management of data files. Combine files, or parse for a specific key, prior to rendering. | ||
### 0.3.0 | ||
### 0.3.0 | ||
* Complete rewrite. More flexible, less opinionated. | ||
@@ -321,0 +323,0 @@ * Now data-driven. Files to be rendered are defined in JSON file, not in the file structure. |
'use strict'; | ||
var grunt = require('grunt'); | ||
var path = require('path'); | ||
@@ -27,13 +28,18 @@ /* | ||
setUp: function(done) { | ||
// setup here if necessary | ||
done(); | ||
test1: function(test) { | ||
test.expect(1); | ||
var actual = grunt.file.read('tests/test1/index.html'); | ||
var expected = grunt.file.read('test/expected/index.html'); | ||
test.equal(actual, expected, 'Test1 should output files without parent dirs'); | ||
test.done(); | ||
}, | ||
default_options: function(test) { | ||
test2: function(test) { | ||
test.expect(1); | ||
var actual = grunt.file.read('tmp/default_options'); | ||
var expected = grunt.file.read('test/expected/default_options'); | ||
test.equal(actual, expected, 'should describe what the default behavior is.'); | ||
var actual = grunt.file.read('tests/test2/about/index.html'); | ||
var expected = grunt.file.read('test/expected/about/index.html'); | ||
test.equal(actual, expected, 'Test2 should output files with parent dirs'); | ||
@@ -43,8 +49,7 @@ test.done(); | ||
custom_options: function(test) { | ||
test3: function(test) { | ||
test.expect(1); | ||
var actual = grunt.file.read('tmp/custom_options'); | ||
var expected = grunt.file.read('test/expected/custom_options'); | ||
test.equal(actual, expected, 'should describe what the custom option(s) behavior is.'); | ||
var file = grunt.file.read('tests/test3/project/project-name.html'); | ||
test.ok(file, 'Test3 should find file project/project-name.html'); | ||
@@ -54,2 +59,20 @@ test.done(); | ||
test4: function(test) { | ||
test.expect(1); | ||
var file = grunt.file.read('tests/test4/project/project_name.html'); | ||
test.ok(file, 'Test4 should find file project/project_name.html'); | ||
test.done(); | ||
}, | ||
test5: function(test) { | ||
test.expect(1); | ||
var file = grunt.file.read('tests/test5/index.php'); | ||
test.ok(file, 'Test5 should find file index.php'); | ||
test.done(); | ||
} | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
2583424
50435
321