-
Notifications
You must be signed in to change notification settings - Fork 20
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/tests #87
Merged
Merged
Feature/tests #87
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b569a51
refactor out core
purge a3cb04a
you don't need to require rjs
purge 4c4eedb
store registered widgets
purge d2fe7bd
example test
purge 18530f2
test loads widget
purge a8bd644
event triggering
purge d241b93
event OVERLOAD
purge 8ae6a47
pass god object in
purge c897ffb
use id if available
purge 23c53bf
params test
purge 8c13bca
spacing
purge 7faa26f
console
purge 0b575cc
rv
purge f581f97
karma has idiotic defaults
purge 497cb20
comment
purge 41802e5
ractive test
purge c186554
Merge branch 'development' into feature/tests
purge 0869db1
fix main
purge 52f1fea
rv comes from bower
purge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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
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,46 @@ | ||
define ['underscore','backbone'], (_, Backbone) -> | ||
|
||
class SqwidgetCore | ||
constructor: () -> | ||
_.extend(@, Backbone.Events) | ||
|
||
registered: [] | ||
|
||
register: (el) -> | ||
$this = $(el).addClass('sqwidget') | ||
opts = @getWidgetParams($this) | ||
pkg = el: $this, opts: opts | ||
_.extend(pkg, Backbone.Events) | ||
@registered.push(pkg) | ||
|
||
throw new Error("No widget source") unless opts.url | ||
|
||
# we're expecting an 'index.js' file inside every widget. | ||
require ["#{opts.url}/js/index.js"], (module) => | ||
# 'settings' object defines all the settings that were passed in via the | ||
# embed code. | ||
widget = new module.Controller({settings: opts, sqwidget: @, el: $this}) | ||
pkg.instance = widget | ||
# fire a 'rendered' method so that the widget can do any post-render | ||
# operations that it needs to do. | ||
#widget.view.trigger("rendered") | ||
pkg.trigger("rendered") | ||
@trigger("rendered:#{widget.id || opts.url}") | ||
return pkg | ||
|
||
# returns an array of all the custom widget parameters. The new keys are | ||
# lowercase concatenated attributes from the embed code with 'data-sqwidget-' | ||
# removed. | ||
# | ||
# eg: | ||
# 'data-sqwidget-color="#F00" -> `data['color'] = '#F00'` | ||
# 'data-sqwidget-bg-color='#FFF' -> data['bgcolor'] = '#FFF' | ||
# | ||
getWidgetParams: ($el) -> | ||
data = {} | ||
for key, val of $el.data() | ||
key = key.replace("sqwidget", "").toLowerCase() | ||
data[key || "url" ] = val | ||
data | ||
|
||
|
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,57 +1,24 @@ | ||
requirejs.config | ||
paths: | ||
require: '../../lib/requirejs/require' | ||
jquery: '../../lib/jquery/jquery' | ||
underscore: '../../lib/underscore-amd/underscore' | ||
backbone: '../../lib/backbone-amd/backbone' | ||
ractive: '../../lib/ractive/Ractive' | ||
Ractive: '../../lib/ractive/Ractive' | ||
text: '../../lib/requirejs-text/text', | ||
rv: '../../lib/requirejs-ractive/rv', | ||
normalize: '../../lib/normalize-css/normalize' | ||
config: '../../config' | ||
|
||
# The module that is loaded first | ||
requirejs [ | ||
'jquery' | ||
'underscore' | ||
'backbone' | ||
'require' | ||
'ractive' | ||
], ($, _, Backbone, require, Ractive) -> | ||
# the only global object that we will use. | ||
Sqwidget = window.Sqwidget || {} | ||
|
||
# add pub/sub to sqwidget. may be removed for a cleaner implementation | ||
_.extend(Sqwidget, Backbone.Events) | ||
'component/core' | ||
], ($, Core) -> | ||
|
||
# Just loads all the widgets | ||
# TODO: Remove jQuery. | ||
$(document).ready () => | ||
# the only global object that we will use. | ||
sqwidget = window.sqwidget = new Core() | ||
# Iterate all elements and register | ||
$(document).ready -> | ||
$('div[data-sqwidget]').each (index) -> | ||
$this = $(this).addClass('sqwidget') | ||
url = $this.data('sqwidget') | ||
# we're expecting an 'index.js' file inside every widget. | ||
# TODO: Use grunt to concat all the widget JS files into a single index.js | ||
# file. | ||
require ["#{url}/js/index.js"], (module) -> | ||
params = getWidgetParams($this) | ||
# 'settings' object defines all the settings that were passed in via the | ||
# embed code. | ||
widget = new module.Controller({settings: params}) | ||
$this.html(widget.view.el) | ||
# fire a 'rendered' method so that the widget can do any post-render | ||
# operations that it needs to do. | ||
widget.view.trigger("rendered") | ||
sqwidget.register(@) | ||
|
||
# returns an array of all the custom widget parameters. The new keys are | ||
# lowercase concatenated attributes from the embed code with 'data-sqwidget-' | ||
# removed. | ||
# | ||
# eg: | ||
# 'data-sqwidget-color="#F00" -> `data['color'] = '#F00'` | ||
# 'data-sqwidget-bg-color='#FFF' -> data['bgcolor'] = '#FFF' | ||
getWidgetParams = ($widget) -> | ||
data = [] | ||
for key, val of $widget.data() | ||
key = key.replace("sqwidget", "").toLowerCase() | ||
if key != "" | ||
data[key] = val | ||
data |
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,2 +1,2 @@ | ||
. | ||
* | ||
!*.js |
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,24 @@ | ||
define ['chai', 'jquery', 'component/core'], (chai, $, Core) -> | ||
assert = chai.assert | ||
describe 'Core', -> | ||
sqwidget = new Core() | ||
src = $("<div data-sqwidget-test='moo' data-sqwidget='/base/widgets/test'></div>'") | ||
|
||
describe '#register()', -> | ||
widget = sqwidget.register(src) | ||
|
||
it 'should register widget', -> | ||
assert.lengthOf(sqwidget.registered, 1, "Registered module") | ||
|
||
it 'should parse params correctly', -> | ||
assert.deepEqual( widget.opts, { test: 'moo', url: '/base/widgets/test' } , "params parsed") | ||
|
||
it 'should trigger rendered event', (done) -> | ||
widget.on 'rendered', -> | ||
assert.ok "Triggered event" | ||
assert.equal(src.html(), | ||
'<div>TEST</div>' | ||
'Rendered Ractive view correctly' | ||
) | ||
done() | ||
|
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
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
Empty file.
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 @@ | ||
../../compiled/widgets/js/test/src |
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,20 @@ | ||
#Example widget using ractive to handle its view | ||
|
||
define [ | ||
'underscore' | ||
'backbone' | ||
'Ractive' | ||
'rv!../templates/test.html' | ||
#"css!./css/app.css" | ||
], (_, Backbone, Ractive, template) -> | ||
module = {views: {}} | ||
|
||
class module.Controller | ||
constructor: ({@el, @settings} = {}) -> | ||
view = new Ractive | ||
el: @el, | ||
template: template, | ||
data: | ||
test: "TEST" | ||
|
||
module |
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 @@ | ||
<div>{{test}}</div> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll change this to send in a new element instead of
$this
but that is not needed as a part of this PR.