Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/optimize #100

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ compiled/**/*.*
app/lib/
dist/
example-widget/
.cram/
build/
24 changes: 23 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,29 @@ 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-concat');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-shell');
grunt.initConfig({
bower: grunt.file.readJSON('bower.json'),
clean: {
all: {
src: ["compiled", "dist"]
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: {
Expand All @@ -32,6 +49,10 @@ module.exports = function(grunt) {
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: {
Expand All @@ -44,4 +65,5 @@ module.exports = function(grunt) {
grunt.registerTask("build", ["shell:build_example"]);
grunt.registerTask("test", ["clean", "build", "karma"]);
grunt.registerTask("default", ["clean", "build", "connect", "watch"]);
grunt.registerTask("dist", ["clean", "shell:build_cram", "uglify", "concat"]);
};
52 changes: 21 additions & 31 deletions app/main.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
define(['./lib/bonzo/bonzo', './lib/qwery/qwery', './lib/eventEmitter/EventEmitter', 'domReady!'],
function(bonzo, qwery, Emitter) {
define(['require', './lib/bonzo/bonzo', './lib/qwery/qwery', 'bean', 'curl/plugin/domReady!'],
function(require, bonzo, qwery, bean) {

var SqwidgetCore = (function() {

function SqwidgetCore() {}

for (var key in Emitter.prototype) {
SqwidgetCore.prototype[key] = Emitter.prototype[key];
}

SqwidgetCore.prototype.packages = {};

//convert data-sqwidget to dictionary
Expand Down Expand Up @@ -36,65 +32,59 @@ function(bonzo, qwery, Emitter) {
};

SqwidgetCore.prototype.register = function(el) {
var opts, pkg, _this = this, id = this.guid();

pkg = new Emitter();
var $el = bonzo(el).addClass('sqwidget').addClass(id);
pkg.opts = opts = this.getWidgetParams($el);
opts.el = pkg.el = $el;
opts.id = id;
var opts,
_this = this,
$el = bonzo(el).addClass('sqwidget');
opts = this.getWidgetParams($el);
opts.el = $el;
opts.id = this.guid();

if (!opts.url) {
throw new Error("No widget source defined (set data-sqwidget-url)");
}

this.packages[id] = {
location: opts.url,
main: 'app/index',
config: opts
};

return pkg;
return this.packages[opts.url] = opts;
};

SqwidgetCore.prototype.initialize = function() {
var names = [], pkg, _this = this;
var names = [],
_this = this;

for(var k in _this.packages) names.push(k);

curl({
packages: _this.packages,
}, names, function() {
require(names, function() {
var loaded = Array.prototype.slice.call(arguments);
for (var i = 0; i < loaded.length; i++) {
var module = loaded[i];

if(module.Controller) {
var pkg = _this.packages[names[i]];
var widget = new module.Controller({
sqwidget: _this
sqwidget: _this,
config: pkg
});

//bus events
_this.trigger("rendered:" + _this.packages[names[i]].location);
_this.trigger("rendered:" + _this.packages[names[i]].id);
bean.fire(_this, "rendered:" + pkg.location);
bean.fire(_this, "rendered:" + pkg.id);
bean.fire(pkg, "rendered");
} else {
console.log("controller not found for " + module.location);
throw("controller not found for " + module.location);
}
}
});
}, function(err) { throw err; } );
};

return SqwidgetCore;

})();

sqwidget = new SqwidgetCore();
var sqwidget = new SqwidgetCore();

bonzo(qwery('div[data-sqwidget]')).each(function(el) {
sqwidget.register(el);
});

sqwidget.initialize();

return sqwidget;
});
7 changes: 1 addition & 6 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@
"tests"
],
"dependencies": {
"backbone-amd": "~1.1.0",
"bonzo": "~1.3.6",
"curl": "~0.8.4",
"qwery": "~3.4.1",
"underscore-amd": "~1.5.2",
"eventEmitter": "[email protected]:Wolfy87/EventEmitter.git#master",
"jquery": "~2.0.3",
"momentjs": "~2.4.0"
"qwery": "~3.4.1"
}
}
3 changes: 3 additions & 0 deletions build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"baseUrl": "."
}
2 changes: 2 additions & 0 deletions grunt-scaffold/root/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
app/nls
app/lib
app/compiled
build/
dist/
43 changes: 37 additions & 6 deletions grunt-scaffold/root/Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-open');
grunt.loadTasks('tasks');
grunt.initConfig({
jshint: {
Expand All @@ -20,21 +26,45 @@ module.exports = function(grunt) {
},
clean: {
all: {
src: ["compiled", "dist"]
src: ["compiled", "build", "dist"]
}
},
connect: {
widget: {
options: {
port: 8080,
port: 8082,
hostname: '*',
base: '.'
}
}
},
watch: {
uglify: {
widget: {
files: ["app/src/**/*"],
tasks: ["build"]
files: {
'dist/{%= name %}.js': ['build/app/index.js']
}
}
},
shell: {
build_cram: {
options: { stdout: true, stderr: true },
command: "./node_modules/cram/bin/cram build.js build.json --exclude ractive -o build/app/index.js -l loader.js"
}
},
open: {
widget: {
path: "http://127.0.0.1:8082/",
app: "Google Chrome"
}
},
watch: {
less: {
files: ["app/less/**/*.less"],
tasks: ["less"]
},
translate: {
files: ["app/i18n.yml"],
tasks: ["requirejs-i18n:widget"]
}
},
'requirejs-i18n': {
Expand All @@ -53,6 +83,7 @@ module.exports = function(grunt) {
}
}
});
grunt.registerTask('default', ['build', 'connect', 'watch']);
grunt.registerTask('default', ['build', 'connect', 'open', 'watch']);
grunt.registerTask('build', ['less:widget', 'requirejs-i18n:widget']);
grunt.registerTask('dist', ['clean', 'build', 'shell:build_cram', 'uglify']);
};
3 changes: 2 additions & 1 deletion grunt-scaffold/root/bower.json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"tests"
],
"dependencies": {
"ractive": "~0.3.7"
"ractive": "~0.3.7",
"sqwidget": "~2.0.3"
}
}
9 changes: 3 additions & 6 deletions grunt-scaffold/root/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
<meta charset=utf-8>
</head>
<body>
<h1>Before</h1>
<div data-sqwidget="http://localhost:8081"></div>
<h1>After</h1>
<div data-sqwidget="http://localhost:8082"></div>
</body>
<script type="text/javascript" src="app/lib/curl/dist/curl/curl.js" </script>
<script>curl.config({ baseUrl: '' });</script>
<script data-curl-run src="sqwidget/sqwidget.js"></script>

<script src="app/lib/sqwidget/dist/sqwidget.js"></script>

</html>
3 changes: 3 additions & 0 deletions node_modules/cram/.bowerrc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions node_modules/cram/.editorconfig

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions node_modules/cram/.jshintrc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions node_modules/cram/.npmignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions node_modules/cram/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions node_modules/cram/amd_modules/curl/.bower.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading