Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
211 additions
and
62 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 |
---|---|---|
@@ -0,0 +1,127 @@ | ||
dom-module#melody-application | ||
style. | ||
#navigation { | ||
width: 100%; | ||
} | ||
|
||
template | ||
maki-datastore(name="maki") | ||
maki-channel(autoconnect, reconnect="true") | ||
|
||
.ui.page.grid | ||
.row | ||
#navigation | ||
maki-navbar | ||
|
||
.row | ||
.column.content(for="viewport") | ||
melody-index | ||
|
||
.row | ||
.ui.one.column.stackable.center.aligned | ||
small <a href="http://github.com/martindale/maki">Made</a> with care by <a href="http://www.ericmartindale.com/">Eric Martindale</a>. | ||
|
||
script(src="/js/page.min.js") | ||
script(src="/js/jquery.js") | ||
script. | ||
window.maki = Polymer({ | ||
is: 'melody-application', | ||
properties: { | ||
src: { | ||
type: String | ||
}, | ||
for: { | ||
type: String | ||
}, | ||
route: { | ||
type: String | ||
}, | ||
routes: { | ||
type: Object | ||
}, | ||
components: { | ||
type: Object, | ||
//observer: '_componentsChanged' | ||
}, | ||
resources: { | ||
type: Object, | ||
observer: '_resourcesUpdated' | ||
}, | ||
datastore: { | ||
type: Object | ||
}, | ||
worker: { type: Object } | ||
}, | ||
_route: function(ctx) { | ||
var self = this; | ||
|
||
var component = 'maki-undefined'; | ||
for (var route in self.routes) { | ||
var regex = self.routes[route]; | ||
if (regex.test(ctx.path)) { | ||
component = self.components[route]; | ||
break; | ||
} | ||
} | ||
|
||
var view = document.createElement(component); | ||
view.setAttribute('src', ctx.path); | ||
|
||
console.log(view); | ||
|
||
var viewport = document.querySelectorAll('[for=viewport]')[0]; | ||
while (viewport.hasChildNodes()) { | ||
viewport.removeChild(viewport.lastChild); | ||
} | ||
viewport.appendChild(view); | ||
}, | ||
_resourcesUpdated: function(resources) { | ||
var self = this; | ||
var _route = self._route.bind(self); | ||
|
||
self.routes['/'] = new RegExp(/^\/$/); | ||
self.components['/'] = 'maki-index'; | ||
|
||
page('/', _route); | ||
|
||
Object.keys(resources).forEach(function(name) { | ||
var resource = resources[name]; | ||
['get', 'query'].forEach(function(action) { | ||
var route = resource.routes[action]; | ||
self.routes[route] = new RegExp(eval(resource.paths[action])); | ||
self.components[route] = resource.components[action]; | ||
page(route, _route); | ||
}); | ||
|
||
//var schema = {}; | ||
//self.schema[name] = Schema(resource.options.attributes); | ||
//console.log(self.schema[name]); | ||
}); | ||
|
||
page(); | ||
}, | ||
_componentsChanged: function(components) { | ||
|
||
}, | ||
created: function() { | ||
var self = this; | ||
|
||
self.route = window.location.pathname; | ||
self.routes = {}; | ||
self.schema = {}; | ||
self.components = {}; | ||
//self.worker = new Worker('/worker.js'); | ||
|
||
$.ajax({ | ||
type: 'OPTIONS', | ||
url: '/', | ||
headers: { | ||
'Accept': 'application/json' | ||
}, | ||
success: function(data) { | ||
self.config = data.config; | ||
self.resources = data.resources; | ||
} | ||
}); | ||
} | ||
}); |
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,13 @@ | ||
dom-module#melody-index | ||
style. | ||
.melody-index { | ||
width: 100%; | ||
} | ||
|
||
template | ||
melody-posts(src="/posts") | ||
|
||
script. | ||
Polymer({ | ||
is: 'melody-index' | ||
}); |
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,29 @@ | ||
dom-module#melody-post | ||
style. | ||
.melody-post { | ||
width: 100%; | ||
} | ||
|
||
template | ||
.ui.fluid.card | ||
//-.image | ||
img(src="/img/maki-logo.png") | ||
.content | ||
a.header(href="{{item.href}}") name: {{item.name}} | ||
p.description description: {{item.description}} | ||
template(if="{{item.action}}") | ||
a.ui.bottom.attached.button(if="{{item.action}}", href="{{item.action.href}}") {{item.action.text}} | ||
|
||
script. | ||
Polymer({ | ||
is: 'melody-post', | ||
properties: { | ||
src: { | ||
type: String, | ||
//observer: '_srcChanged' | ||
} | ||
}, | ||
_srcChanged: function() { | ||
console.log('source changed for item'); | ||
} | ||
}); |
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,36 @@ | ||
dom-module#melody-posts | ||
style. | ||
.melody-posts { | ||
width: 100%; | ||
} | ||
|
||
template | ||
.ui.cards | ||
template(is="dom-repeat", items="{{items}}") | ||
melody-post(src="{{item.href}}", item="{{item}}") | ||
|
||
script. | ||
Polymer({ | ||
is: 'melody-posts', | ||
properties: { | ||
src: { | ||
type: String | ||
}, | ||
items: { | ||
type: Array | ||
}, | ||
as: { | ||
type: String, | ||
value: 'item' | ||
} | ||
}, | ||
ready: function() { | ||
var self = this; | ||
$.getJSON(self.src, function(data) { | ||
self.items = data; | ||
}); | ||
}, | ||
_resourceProperties: function() { | ||
|
||
} | ||
}); |
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