Skip to content
Browse files

Initial commit; added testing framework and first block-level handleb…

…ars helper
  • Loading branch information...
0 parents commit f3c3f1abd9f076d7796319e32cf6330d575f52bf @badsyntax committed
Showing with 129 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +56 −0 GruntFile.js
  3. +7 −0 bower.json
  4. +2 −0 dist/handlebars_helpers.js
  5. +10 −0 package.json
  6. +16 −0 spec/Helpers.Spec.js
  7. +26 −0 spec/reporter.js
  8. +10 −0 src/Helpers.js
2 .gitignore
@@ -0,0 +1,2 @@
+components
+node_modules
56 GruntFile.js
@@ -0,0 +1,56 @@
+module.exports = function(grunt) {
+
+ // Project configuration.
+ grunt.initConfig({
+ pkg: grunt.file.readJSON('package.json'),
+ uglify: {
+ options: {
+ banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
+ },
+ build: {
+ src: [
+ 'src/**/*.js'
+ ],
+ dest: 'dist/handlebars_helpers.js'
+ }
+ },
+ jshint: {
+ files: [
+ '*.js',
+ 'src/**/*.js',
+ 'spec/**/*.js'
+ ],
+ options: {
+ globals: {
+ console: true,
+ document: true
+ }
+ }
+ },
+ jasmine: {
+ helpers: {
+ src: [
+ 'components/handlebars.js/handlebars.js',
+ 'src/Helpers.js'
+ ],
+ options: {
+ specs: 'spec/**/*.Spec.js'
+ }
+ }
+ }
+ });
+
+ // Load the task plugins
+ grunt.loadNpmTasks('grunt-contrib-uglify');
+ grunt.loadNpmTasks('grunt-contrib-jshint');
+ grunt.loadNpmTasks('grunt-contrib-jasmine');
+
+ // Custom tasks
+ grunt.registerTask('test', ['jshint', 'jasmine']);
+
+ // Default tasks
+ grunt.registerTask('default', [
+ 'test',
+ 'uglify'
+ ]);
+};
7 bower.json
@@ -0,0 +1,7 @@
+{
+ "name": "handlebars-form-helpers",
+ "version": "0.0.0",
+ "dependencies": {
+ "handlebars.js": "~1.0.0-rc.3"
+ }
+}
2 dist/handlebars_helpers.js
@@ -0,0 +1,2 @@
+/*! handlebars-form-helpers 2013-05-12 */
+(function(r){r.registerHelper("form",function(r){return"<form>"+r.fn(this)+"</form>"})})(Handlebars);
10 package.json
@@ -0,0 +1,10 @@
+{
+ "name": "handlebars-form-helpers",
+ "version": "0.1.0",
+ "devDependencies": {
+ "grunt": "~0.4.1",
+ "grunt-contrib-uglify": "~0.1.2rc7",
+ "grunt-contrib-jshint": "~0.1.1",
+ "grunt-contrib-jasmine": "~0.3.3"
+ }
+}
16 spec/Helpers.Spec.js
@@ -0,0 +1,16 @@
+describe('Handlebars form helpers', function() {
+
+ function strip(html) {
+ return html.toLowerCase().replace(/[\r\n]/g,'');
+ }
+
+ it('Provides a form block level helper', function() {
+
+ var data = {};
+ var source = '{{#form}}{{/form}}';
+ var template = Handlebars.compile(source);
+ var html = template(data);
+
+ expect(strip(html)).toBe('<form></form>');
+ });
+});
26 spec/reporter.js
@@ -0,0 +1,26 @@
+(function() {
+
+ var jasmineEnv = jasmine.getEnv();
+ jasmineEnv.updateInterval = 1000;
+
+ var trivialReporter = new jasmine.TrivialReporter();
+
+ jasmineEnv.addReporter(trivialReporter);
+
+ jasmineEnv.specFilter = function(spec) {
+ return trivialReporter.specFilter(spec);
+ };
+
+ var currentWindowOnload = window.onload;
+
+ window.onload = function() {
+ if (currentWindowOnload) {
+ currentWindowOnload();
+ }
+ execJasmine();
+ };
+
+ function execJasmine() {
+ jasmineEnv.execute();
+ }
+})();
10 src/Helpers.js
@@ -0,0 +1,10 @@
+// Helpers.js
+// handlebars.js form helpers
+
+(function(Handlebars) {
+
+ Handlebars.registerHelper('form', function(options) {
+ return '<form>' + options.fn(this) + '</form>';
+ });
+
+}(Handlebars));

0 comments on commit f3c3f1a

Please sign in to comment.
Something went wrong with that request. Please try again.