From 6efd4ff8a767936858422064b115a3e4845a3b33 Mon Sep 17 00:00:00 2001 From: lmarkus Date: Sat, 23 Nov 2013 01:01:22 -0800 Subject: [PATCH] Plain vanilla kraken app --- .editorconfig | 13 +++ .gitignore | 5 + .jshintignore | 3 + .jshintrc | 155 +++++++++++++++++++++++++++ .nodemonignore | 5 + Gruntfile.js | 91 ++++++++++++++++ README.md | 3 + bower.json | 5 + config/app.json | 47 ++++++++ config/middleware.json | 8 ++ controllers/index.js | 13 +++ index.js | 33 ++++++ locales/US/en/index.properties | 1 + models/index.js | 0 package.json | 32 ++++++ public/css/app.less | 0 public/js/.jshintignore | 1 + public/js/.jshintrc | 72 +++++++++++++ public/js/app.js | 14 +++ public/js/config.js | 6 ++ public/templates/index.dust | 5 + public/templates/layouts/master.dust | 14 +++ 22 files changed, 526 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 .jshintignore create mode 100644 .jshintrc create mode 100644 .nodemonignore create mode 100644 Gruntfile.js create mode 100644 README.md create mode 100644 bower.json create mode 100644 config/app.json create mode 100644 config/middleware.json create mode 100644 controllers/index.js create mode 100644 index.js create mode 100644 locales/US/en/index.properties create mode 100644 models/index.js create mode 100644 package.json create mode 100644 public/css/app.less create mode 100644 public/js/.jshintignore create mode 100644 public/js/.jshintrc create mode 100644 public/js/app.js create mode 100644 public/js/config.js create mode 100644 public/templates/index.dust create mode 100644 public/templates/layouts/master.dust diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c308ed0 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +# http://editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..69a12c7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.DS_Store +.idea/ +.build/ +node_modules/ +*.iml diff --git a/.jshintignore b/.jshintignore new file mode 100644 index 0000000..5d8b3f9 --- /dev/null +++ b/.jshintignore @@ -0,0 +1,3 @@ +.build +node_modules +public/js diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..e9a3c1e --- /dev/null +++ b/.jshintrc @@ -0,0 +1,155 @@ +{ + // Whether the scan should stop on first error. + "passfail": false, + // Maximum errors before stopping. + "maxerr": 100, + + + // Predefined globals + + // Whether the standard browser globals should be predefined. + "browser": false, + // Whether the Node.js environment globals should be predefined. + "node": true, + // Whether the Rhino environment globals should be predefined. + "rhino": false, + // Whether CouchDB globals should be predefined. + "couch": false, + // Whether the Windows Scripting Host environment globals should be predefined. + "wsh": false, + + // Whether jQuery globals should be predefined. + "jquery": false, + // Whether Prototype and Scriptaculous globals should be predefined. + "prototypejs": false, + // Whether MooTools globals should be predefined. + "mootools": false, + // Whether Dojo Toolkit globals should be predefined. + "dojo": false, + + // Custom predefined globals. + "predef": [], + + // Development + + // Whether debugger statements should be allowed. + "debug": false, + // Whether logging globals should be predefined (console, alert, etc.). + "devel": false, + + + // ECMAScript 5 + + // Whether the "use strict"; pragma should be required. + "strict": true, + // Whether global "use strict"; should be allowed (also enables strict). + "globalstrict": true, + + + // The Good Parts + + // Whether automatic semicolon insertion should be allowed. + "asi": false, + // Whether line breaks should not be checked, e.g. `return [\n] x`. + "laxbreak": false, + // Whether bitwise operators (&, |, ^, etc.) should be forbidden. + "bitwise": false, + // Whether assignments inside `if`, `for` and `while` should be allowed. Usually + // conditions and loops are for comparison, not assignments. + "boss": true, + // Whether curly braces around all blocks should be required. + "curly": true, + // Whether `===` and `!==` should be required (instead of `==` and `!=`). + "eqeqeq": true, + // Whether `== null` comparisons should be allowed, even if `eqeqeq` is `true`. + "eqnull": false, + // Whether `eval` should be allowed. + "evil": false, + // Whether ExpressionStatement should be allowed as Programs. + "expr": true, + // Whether `for in` loops must filter with `hasOwnPrototype`. + "forin": false, + // Whether immediate invocations must be wrapped in parens, e.g. + // `( function(){}() );`. + "immed": true, + // Whether use before define should be forbidden. + "latedef": false, + // Whether functions should be allowed to be defined within loops. + "loopfunc": false, + // Whether arguments.caller and arguments.callee should be forbidden. + "noarg": false, + // Whether `.` should be forbidden in regexp literals. + "regexp": false, + // Whether unescaped first/last dash (-) inside brackets in regexps should be allowed. + "regexdash": false, + // Whether script-targeted URLs should be allowed. + "scripturl": false, + // Whether variable shadowing should be allowed. + "shadow": false, + // Whether `new function () { ... };` and `new Object;` should be allowed. + "supernew": false, + // Whether variables must be declared before used. + "undef": true, + // Whether `this` inside a non-constructor function should be allowed. + "validthis": false, + // Whether smarttabs should be allowed + // (http://www.emacswiki.org/emacs/SmartTabs). + "smarttabs": true, + // Whether the `__proto__` property should be allowed. + "proto": false, + // Whether one-case switch statements should be allowed. + "onecase": false, + // Whether non-standard (but widely adopted) globals should be predefined. + "nonstandard": false, + // Allow multiline strings. + "multistr": false, + // Whether line breaks should not be checked around commas. + "laxcomma": false, + // Whether semicolons may be ommitted for the trailing statements inside of a + // one-line blocks. + "lastsemic": false, + // Whether the `__iterator__` property should be allowed. + "iterator": false, + // Whether only function scope should be used for scope tests. + "funcscope": false, + // Whether es.next specific syntax should be allowed. + "esnext": false, + + + // Style preferences + + // Whether constructor names must be capitalized. + "newcap": false, + // Whether empty blocks should be forbidden. + "noempty": false, + // Whether using `new` for side-effects should be forbidden. + "nonew": false, + // Whether names should be checked for leading or trailing underscores + // (object._attribute would be forbidden). + "nomen": false, + // Whether only one var statement per function should be allowed. + "onevar": false, + // Whether increment and decrement (`++` and `--`) should be forbidden. + "plusplus": false, + // Whether all forms of subscript notation are allowed. + "sub": false, + // Whether trailing whitespace rules apply. + "trailing": false, + // Specify indentation. + "indent": 4, + // Whether strict whitespace rules apply. + "white": false, + // Quote formatting + "quotmark": true, + + // Complexity + + // Maximum number of function parameters. + "maxparams": 5, + // Maximum block nesting depth. + "maxdepth": 3, + // Maximum number of statements per function. + "maxstatements": 25, + // Maximum cyclomatic complexity. + "maxcomplexity": 6 +} diff --git a/.nodemonignore b/.nodemonignore new file mode 100644 index 0000000..5a67173 --- /dev/null +++ b/.nodemonignore @@ -0,0 +1,5 @@ +/.build/* # Build folder +/public/* # ignore all public resources +/.* # any hidden (dot) files +*.md # Markdown files +*.css # CSS files diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..47d753d --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,91 @@ +'use strict'; + + +module.exports = function (grunt) { + + grunt.initConfig({ + jshint: { + files: ['controllers/**/*.js', 'lib/**/*.js', 'models/**/*.js'], + options: { + jshintrc: '.jshintrc' + } + }, + requirejs: { + compile: { + options: { + baseUrl: 'public/js', + mainConfigFile: 'public/js/config.js', + dir: '.build/js', + optimize: 'uglify', + modules: [{name: 'app'}] + } + } + }, + less: { + compile: { + options: { + yuicompress: true, + paths: ['public/css'] + }, + files: { + '.build/css/app.css': 'public/css/app.less' + } + } + }, + makara: { + files: ['public/templates/**/*.dust'], + options: { + contentPath: ['locales/**/*.properties'] + } + }, + dustjs: { + compile: { + files: [ + { + expand: true, + cwd: 'tmp/', + src: '**/*.dust', + dest: '.build/templates', + ext: '.js' + } + ], + options: { + fullname: function (filepath) { + var path = require('path'), + name = path.basename(filepath, '.dust'), + parts = filepath.split(path.sep), + fullname = parts.slice(3, -1).concat(name); + + return fullname.join(path.sep); + } + } + } + }, + clean: { + 'tmp': 'tmp', + 'build': '.build/templates' + }, + mochatest: { + src: ['test/*.js'], + options: { + globals: ['chai'], + timeout: 6000, + ignoreLeaks: false, + ui: 'bdd', + reporter: 'spec' + } + } + }); + + //grunt.loadNpmTasks('grunt-ci-suite'); + grunt.loadNpmTasks('grunt-contrib-less'); + grunt.loadNpmTasks('grunt-contrib-requirejs'); + grunt.loadNpmTasks('grunt-contrib-clean'); + grunt.loadNpmTasks('grunt-dustjs'); + grunt.loadTasks('./node_modules/makara/tasks/'); + + grunt.registerTask('i18n', ['clean', 'makara', 'dustjs', 'clean:tmp']); + grunt.registerTask('build', ['jshint', 'less', 'requirejs', 'i18n']); + grunt.registerTask('test', ['jshint', 'mochatest']); + +}; diff --git a/README.md b/README.md new file mode 100644 index 0000000..33b4f00 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Kraken_Example_Custom_Middleware + +An application to show the use of custom middleware for kraken. diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..311bbf6 --- /dev/null +++ b/bower.json @@ -0,0 +1,5 @@ +{ + "name": "kraken-example-custom-middleware", + "version": "0.0.1", + "dependencies": {} +} diff --git a/config/app.json b/config/app.json new file mode 100644 index 0000000..8be175b --- /dev/null +++ b/config/app.json @@ -0,0 +1,47 @@ +{ +// Uncomment and change as needed (Be careful not to leave trailing commas!) + +// "port": 8000, +// +// "host": "localhost", +// +// "i18n": { +// "fallback": "en-US", +// "contentPath": "path:./locales" +// }, +// +// "routes": { +// "routePath": "path:./controllers" +// }, +// +// "view engines": { +// "js": { +// "module": "adaro", +// "settings": { +// "helpers": null, +// "stream": false +// } +// }, +// +// "dust": { +// "module": "adaro", +// "settings": { +// "helpers": null, +// "stream": false +// } +// } +// }, +// "express": { +// "x-powered-by": false, +// "trust proxy": false, +// "jsonp callback name": null, +// "json replacer": null, +// "json spaces": 0, +// "case sensitive routing": false, +// "strict routing": false, +// "view cache": true, +// "view engine": "js", +// "views": "path:./.build/templates" +// } + +} diff --git a/config/middleware.json b/config/middleware.json new file mode 100644 index 0000000..07662a4 --- /dev/null +++ b/config/middleware.json @@ -0,0 +1,8 @@ +{ + "middleware": { + "session": { + "module": "memory", + "secret": "ca713a42e9a443ac93836cfbc9ea441a9d947667" + } + } +} diff --git a/controllers/index.js b/controllers/index.js new file mode 100644 index 0000000..c40005c --- /dev/null +++ b/controllers/index.js @@ -0,0 +1,13 @@ +'use strict'; + + +module.exports = function (server) { + + server.get('/', function (req, res) { + var model = { name: 'kraken-example-custom-middleware' }; + + res.render('index', model); + + }); + +}; diff --git a/index.js b/index.js new file mode 100644 index 0000000..3a1928c --- /dev/null +++ b/index.js @@ -0,0 +1,33 @@ +'use strict'; + + +var kraken = require('kraken-js'), + app = {}; + + +app.configure = function configure(nconf, next) { + // Fired when an app configures itself + next(null); +}; + + +app.requestStart = function requestStart(server) { + // Fired at the beginning of an incoming request +}; + + +app.requestBeforeRoute = function requestBeforeRoute(server) { + // Fired before routing occurs +}; + + +app.requestAfterRoute = function requestAfterRoute(server) { + // Fired after routing occurs +}; + + +kraken.create(app).listen(function (err) { + if (err) { + console.error(err); + } +}); diff --git a/locales/US/en/index.properties b/locales/US/en/index.properties new file mode 100644 index 0000000..3c47aee --- /dev/null +++ b/locales/US/en/index.properties @@ -0,0 +1 @@ +index.greeting=Hello, {name}! diff --git a/models/index.js b/models/index.js new file mode 100644 index 0000000..e69de29 diff --git a/package.json b/package.json new file mode 100644 index 0000000..b093a00 --- /dev/null +++ b/package.json @@ -0,0 +1,32 @@ +{ + "name": "kraken-example-custom-middleware", + "version": "0.0.1", + "description": "An application to show the use of custom middleware for kraken.", + "author": "@LennyMarkus", + "main": "index.js", + "scripts": { + "start": "node index.js" + }, + "engines": { + "node": ">=0.10.0" + }, + "dependencies": { + "kraken-js": "~0.6.1", + "express": "~3.4.4", + "adaro": "~0.1.x", + "nconf": "~0.6.8", + "less": "~1.3.3", + "dustjs-linkedin": "~2.0.3", + "dustjs-helpers": "~1.1.1", + "makara": "~0.3.0" + }, + "devDependencies": { + "mocha": "~1.10.0", + "grunt": "~0.4.1", + + "grunt-contrib-less": "~0.7.0", + "grunt-contrib-requirejs": "~0.4.1", + "grunt-dustjs": "~1.1.1", + "grunt-contrib-clean": "~0.5.0" + } +} diff --git a/public/css/app.less b/public/css/app.less new file mode 100644 index 0000000..e69de29 diff --git a/public/js/.jshintignore b/public/js/.jshintignore new file mode 100644 index 0000000..a65b417 --- /dev/null +++ b/public/js/.jshintignore @@ -0,0 +1 @@ +lib diff --git a/public/js/.jshintrc b/public/js/.jshintrc new file mode 100644 index 0000000..13e2bdb --- /dev/null +++ b/public/js/.jshintrc @@ -0,0 +1,72 @@ +{ + "passfail": false, + "maxerr": 100, + + "browser": true, + "node": false, + "rhino": false, + "couch": false, + "wsh": false, + + "jquery": false, + "prototypejs": false, + "mootools": false, + "dojo": false, + + "debug": false, + "devel": false, + + "es5": true, + "strict": true, + "globalstrict": true, + + "asi": false, + "laxbreak": false, + "bitwise": false, + "boss": true, + "curly": true, + "eqeqeq": true, + "eqnull": false, + "evil": false, + "expr": true, + "forin": false, + "immed": true, + "latedef": false, + "loopfunc": false, + "noarg": false, + "regexp": false, + "regexdash": false, + "scripturl": false, + "shadow": false, + "supernew": false, + "undef": true, + "validthis": false, + "smarttabs": true, + "proto": false, + "onecase": false, + "nonstandard": false, + "multistr": false, + "laxcomma": false, + "lastsemic": false, + "iterator": false, + "funcscope": false, + "esnext": false, + + "newcap": false, + "noempty": false, + "nonew": false, + "nomen": false, + "onevar": false, + "plusplus": false, + "sub": false, + "trailing": false, + "indent": 4, + "white": true, + + "maxparams": 5, + "maxdepth": 3, + "maxstatements": 25, + "maxcomplexity": 6, + + "predef": ["define", "requirejs"] +} diff --git a/public/js/app.js b/public/js/app.js new file mode 100644 index 0000000..702d618 --- /dev/null +++ b/public/js/app.js @@ -0,0 +1,14 @@ +'use strict'; + + +require(['config' /*, Dependencies */], function (config) { + + var app = { + initialize: function () { + // Your code here + } + }; + + app.initialize(); + +}); diff --git a/public/js/config.js b/public/js/config.js new file mode 100644 index 0000000..0fb02aa --- /dev/null +++ b/public/js/config.js @@ -0,0 +1,6 @@ +'use strict'; + + +requirejs.config({ + paths: {} +}); diff --git a/public/templates/index.dust b/public/templates/index.dust new file mode 100644 index 0000000..d99ff8d --- /dev/null +++ b/public/templates/index.dust @@ -0,0 +1,5 @@ +{>"layouts/master" /} + +{{@pre type="content" key="index.greeting"/} +{/body} diff --git a/public/templates/layouts/master.dust b/public/templates/layouts/master.dust new file mode 100644 index 0000000..c87d320 --- /dev/null +++ b/public/templates/layouts/master.dust @@ -0,0 +1,14 @@ + + + + + {+title /} + + + +
+ {+body /} +
+ + +