TRY ME OUT AT: http://bl.ocks.org/1483563
As is evident from the name chosen for this library - lumbar - this has been heavily influenced by the incredible Backbone.js. In fact, the full lumbar framework is designed to sit on top of Backbone.js for the time being. This is because the model, collection and router components of Backbone.js are 10x better than anything I can write.
I wrote this because I'm not a major fan of the way Backbone.js' View system works. This system is very similar, but has a few key differences. Please refer to the last section below.
This library probably won't suit your needs as using it in anything but Coffee-Script would be an exercise in self-mutilation. Furthermore, documentation simply does not exist.
lumbar.view "myapp.article",
mountPoint: "<article></article>"
template: ->
h1 @title
p @content
div ".about", ->
strong "Author:"
text @author
myapp.root = new class extends lumbar.View,
mountPoint: "body" # This takes over the body
template: ->
header ->
h1 "MyApp title"
section "#articles", ->
$v("myapp.article", article) for article in $m("myapp.articles")
# Now, when you're ready, you can render the whole shebang
myapp.root.render()
Define a view for as name, using the definition hash to augment the view's prototype.
Returns the generated view class.
# Default usage:
lumbar.view "app.section",
# The jQuery expression to find or create the containing element to be bound to @$
mountPoint: "<div/>"
# Value/object to be passed as the second argument at construction
mountArgs: null
# Method to be called on @$ in order to add the rendered template to the container
mountMethod: "html"
# The template for the view in CoffeeKup (https://github.com/mauricemach/coffeekup)
template: ->
# A hash of "event [selector]": callback | "event" pairs
events: null
# The function that can be overwritten to handle construction
initialize: ->
Retrieve a the lumbar.View class that was previously defined.
# Default usage:
lumbar.view("app.section")
Render a template with the supplied locals available under the @ namespace from within the template (see CoffeeKup documentation).
Create an instance of the supplied view and render it with locals inline.
Recursively look through globally defined variables according to a "." separated path. This also handles traversing on objects that supply a "get(key)" method such as Backbone.js.
This will eventually also tell the parent view that the view depends on the model. This will allow sub-views to intelligently refresh by listening to chances to their dependent models.
- Templates are defined in-line in the template using CoffeeKup.
- The @$ property of views refers to a jQuery collection, not a namespaced jQuery.find(). This is similar, but not the same as Backbone.js' View.el.
- Views can be defined using
lumbar.view
for referencing within view templates. - They are written in Coffee-Script. Caveat emptor.
- They are built to reflect the hierarchical nature of typical webapps.