Permalink
Browse files

tests working again + new optimization stage

  • Loading branch information...
1 parent ff4b577 commit 2e4be2ae69c4221ca5144b772332a9124eef2199 @purge purge committed Nov 11, 2013
Showing with 321 additions and 558 deletions.
  1. +1 −1 .bowerrc
  2. +1 −2 .gitignore
  3. +33 −14 Gruntfile.js
  4. +0 −114 app/main.js
  5. +0 −193 app/plugins/i18n.js
  6. +0 −101 app/plugins/locale.js
  7. +6 −2 bower.json
  8. +0 −3 build.json
  9. +19 −54 karma.conf.js
  10. +5 −7 package.json
  11. +0 −18 sqwidget.js
  12. +110 −0 src/core.js
  13. +11 −0 src/index.js
  14. +44 −0 test/SpecRunnerMocha.html
  15. +8 −0 test/fixture/example.js
  16. +66 −0 test/spec/core.js
  17. +17 −0 test/test-main.js
  18. +0 −24 tests/spec/core.coffee
  19. +0 −25 tests/test-main.coffee
View
@@ -1,3 +1,3 @@
{
- "directory": "app/lib"
+ "directory": "src/lib"
}
View
@@ -2,8 +2,7 @@
node_modules/
config.js
compiled/**/*.*
-app/lib/
+src/lib/
dist/
example-widget/
-.cram/
build/
View
@@ -2,31 +2,27 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
- grunt.loadNpmTasks('grunt-contrib-uglify');
+ grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-shell');
grunt.initConfig({
bower: grunt.file.readJSON('bower.json'),
+
clean: {
all: {
src: ["build", "compiled", "dist"]
}
},
- concat: {
- sqwidget: {
- files: {
- 'dist/sqwidget-<%= bower.version %>.min.js': ['app/lib/curl/dist/curl/curl.js', 'build/sqwidget-min.js']
- }
- }
- },
+
uglify: {
sqwidget: {
files: {
'build/sqwidget-min.js': ['build/sqwidget.js']
}
}
},
+
connect: {
publisher: {
options: {
@@ -41,29 +37,52 @@ module.exports = function(grunt) {
}
}
},
+
karma: {
integration: {
configFile: 'karma.conf.js'
}
},
+
+ requirejs: {
+ compile: {
+ options: {
+ baseUrl: "src",
+ out: 'dist/<%= bower.name %>-<%= bower.version %>.js',
+ paths: {
+ almond: '../bower_components/almond/almond',
+ domReady: 'lib/requirejs-domready/domReady',
+ },
+ include: ['almond', 'index'],
+ // Wrapper for AMD
+ wrap: {
+ startFile: 'src/_wrapper/top.js',
+ endFile: 'src/_wrapper/bottom.js'
+ },
+ optimize: 'uglify2',
+ //optimize: 'none',
+ preserveLicenseComments: false,
+ generateSourceMaps: true
+ }
+ }
+ },
+
shell: {
build_example: {
command: "./build_example.sh"
- },
- build_cram: {
- options: { stdout: true, stderr: true },
- command: "./node_modules/cram/bin/cram sqwidget.js --include curl/plugin/domReady build.json -o build/sqwidget.js"
}
},
+
watch: {
scaffold: {
files: ["grunt-scaffold/root/main.js", "grunt-scaffold/root/app/**/*.js", "grunt-scaffold/**/*.tmpl"],
tasks: ["build"]
}
}
+
});
- grunt.registerTask("build", ["shell:build_example"]);
+ grunt.registerTask("build", ["requirejs:compile"]);
grunt.registerTask("test", ["clean", "build", "karma"]);
grunt.registerTask("default", ["clean", "build", "connect", "watch"]);
- grunt.registerTask("dist", ["clean", "shell:build_cram", "uglify", "concat"]);
+ grunt.registerTask("dist", ["clean", "build"]);
};
View
@@ -1,114 +0,0 @@
-define(['require', './lib/bonzo/bonzo', './lib/qwery/qwery', 'bean', 'curl/plugin/domReady!'],
-function(require, bonzo, qwery, bean) {
-
- var SqwidgetCore = (function() {
-
- function SqwidgetCore() {}
-
- SqwidgetCore.prototype.packages = {};
-
- //convert data-sqwidget to dictionary
- SqwidgetCore.prototype.getWidgetParams = function($el) {
- var key, val,
- data = {},
- elData = $el.data();
-
- //for compatibility data-sqwidget gets renamed data-sqwidget-url
- if(elData.sqwidget) {
- elData.sqwidgetUrl = elData.sqwidget;
- delete elData.sqwidget;
- }
-
- //convert list of names into a nested structure with val as the value
- var nest = function( names, val, data ) {
- for( var i = 0; i < names.length; i++ ) {
- data = data[ names[i].toLowerCase() ] =
- i === names.length - 1 ? val : data[ names[i] ] || {};
- }
- };
-
- for (key in elData) {
- val = elData[key];
- if (!(key.match("^sqwidget"))) { continue; }
- nest(key.match(/([A-Z]?[^A-Z]*)/g).slice(0,-1), val, data);
- }
-
- return data.sqwidget;
- };
-
- SqwidgetCore.prototype.guid = function() {
- return 'sqwidget-xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
- var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
- return v.toString(16);
- });
- };
-
- SqwidgetCore.prototype.register = function(el) {
- var opts,
- _this = this,
- id = this.guid(),
- $el = bonzo(el).addClass('sqwidget').addClass(id);
- opts = this.getWidgetParams($el);
- opts.el = $el;
- opts.id = id;
-
- if (!opts.url) {
- throw new Error("No widget source defined (set data-sqwidget-url)");
- }
-
- return this.packages[opts.url] = opts;
- };
-
- //when the promise is resolved initialise the bundle controller
- SqwidgetCore.prototype.resolve = function(pkg, bundle) {
- if(bundle.Controller) {
- var widget = new bundle.Controller({
- sqwidget: this,
- config: pkg
- });
-
- //bus events
- bean.fire(this, "rendered:" + pkg.location);
- bean.fire(this, "rendered:" + pkg.id);
- bean.fire(pkg, "rendered");
- } else {
- throw("controller not found for " + bundle.location);
- }
- };
-
- SqwidgetCore.prototype.initialize = function() {
- var names = [],
- _this = this;
-
- for(var k in _this.packages) names.push(k);
-
- require(names, function() {
- var loaded = Array.prototype.slice.call(arguments);
- for (var i = 0; i < loaded.length; i++) {
- var pkg = _this.packages[names[i]];
- //if the bundle is a promise, wait for it to resolve, otherwise handle
- //immediately
- if("then" in loaded[i]) {
- var resolve = function(bundle) {
- return _this.resolve(pkg, bundle); };
- loaded[i].then(resolve);
- } else {
- _this.resolve(pkg, loaded[i]);
- }
- }
- }, function(err) { throw err; } );
- };
-
- return SqwidgetCore;
-
- })();
-
- var sqwidget = new SqwidgetCore();
-
- bonzo(qwery('div[data-sqwidget]')).each(function(el) {
- sqwidget.register(el);
- });
-
- sqwidget.initialize();
- return sqwidget;
-});
Oops, something went wrong.

0 comments on commit 2e4be2a

Please sign in to comment.