-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from premasagar/feature/curljs
Use curljs to build widgets
- Loading branch information
Showing
54 changed files
with
910 additions
and
419 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"directory": "sqwidget/lib" | ||
"directory": "app/lib" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
.DS_Store | ||
node_modules/ | ||
config.js | ||
|
||
# temporary! | ||
compiled/**/*.* | ||
app/lib/ | ||
dist/ | ||
compiled/ | ||
example-widget/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
npm-debug.log | ||
node_modules | ||
src | ||
test | ||
compiled |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module.exports = function(grunt) { | ||
grunt.loadNpmTasks('grunt-contrib-clean'); | ||
grunt.loadNpmTasks('grunt-contrib-watch'); | ||
grunt.loadNpmTasks('grunt-contrib-connect'); | ||
grunt.loadNpmTasks('grunt-karma'); | ||
grunt.loadNpmTasks('grunt-shell'); | ||
grunt.initConfig({ | ||
clean: { | ||
all: { | ||
src: ["compiled", "dist"] | ||
} | ||
}, | ||
connect: { | ||
publisher: { | ||
options: { | ||
port: 8000, | ||
base: '.' | ||
} | ||
}, | ||
sqwidget: { | ||
options: { | ||
port: 8002, | ||
base: 'example-widget' | ||
} | ||
} | ||
}, | ||
karma: { | ||
integration: { | ||
configFile: 'karma.conf.js' | ||
} | ||
}, | ||
shell: { | ||
build_example: { | ||
command: "./build_example.sh" | ||
} | ||
}, | ||
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("test", ["clean", "build", "karma"]); | ||
grunt.registerTask("default", ["clean", "build", "connect", "watch"]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
PATH := ./node_modules/.bin:${PATH} | ||
|
||
.PHONY : init bower build test dist publish | ||
|
||
init: bower | ||
npm install | ||
|
||
build: | ||
grunt build | ||
|
||
test: | ||
grunt test | ||
|
||
bower: | ||
bower install | ||
|
||
dist: | ||
grunt dist | ||
|
||
publish: dist | ||
npm publish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
define(['./lib/bonzo/bonzo', './lib/qwery/qwery', './lib/eventEmitter/EventEmitter', 'domReady!'], | ||
function(bonzo, qwery, Emitter) { | ||
|
||
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 | ||
SqwidgetCore.prototype.getWidgetParams = function($el) { | ||
var data, key, val, _ref; | ||
data = {}; | ||
_ref = $el.data(); | ||
|
||
for (key in _ref) { | ||
val = _ref[key]; | ||
if (!(key.match("sqwidget"))) { | ||
continue; | ||
} | ||
key = key.replace("sqwidget", "").toLowerCase(); | ||
data[key || "url"] = val; | ||
} | ||
return data; | ||
}; | ||
|
||
SqwidgetCore.prototype.guid = function() { | ||
return '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, 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; | ||
|
||
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; | ||
}; | ||
|
||
SqwidgetCore.prototype.initialize = function() { | ||
var names = [], pkg, _this = this; | ||
|
||
for(var k in _this.packages) names.push(k); | ||
|
||
curl({ | ||
packages: _this.packages, | ||
}, 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 widget = new module.Controller({ | ||
sqwidget: _this | ||
}); | ||
|
||
//bus events | ||
_this.trigger("rendered:" + _this.packages[names[i]].location); | ||
_this.trigger("rendered:" + _this.packages[names[i]].id); | ||
} else { | ||
console.log("controller not found for " + module.location); | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
return SqwidgetCore; | ||
|
||
})(); | ||
|
||
sqwidget = new SqwidgetCore(); | ||
|
||
bonzo(qwery('div[data-sqwidget]')).each(function(el) { | ||
sqwidget.register(el); | ||
}); | ||
|
||
sqwidget.initialize(); | ||
|
||
return sqwidget; | ||
}); |
Oops, something went wrong.