Skip to content

Commit

Permalink
Bujagali updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarroll1283 committed Jan 17, 2014
1 parent f0d169f commit 31da735
Show file tree
Hide file tree
Showing 18 changed files with 14,825 additions and 1,927 deletions.
3 changes: 0 additions & 3 deletions .gitignore

This file was deleted.

71 changes: 2 additions & 69 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ There are 3 aspects to the system that require documentation.
* Converting templates to JavaScript
* Rendering templates

Also see:

* [Client JS API docs](http://rdio.github.com/bujagali/js-api)
* [Blog post on how Bujagali works](http://justin.harmonize.fm/index.php/2010/10/bujagali-incredibly-fast-javascript-templating/)

Writing Templates
-----------------
Expand Down Expand Up @@ -194,74 +190,11 @@ are available to you from your templates and how to extend that set.
Converting Templates to JavaScript
----------------------------------

Once you have written a template, converting it to javascript is pretty
straightforward. The scripts to generate the javascript are all in python,
so in python you would write somthing like this:

root = "/User/justin/awesomeTemplates"
t = Bujagali('/things.bg.html', root)
js = t.generate()

Now `js` will contain the javascript that should be returned to the client.

Rdio has a django view that generates templates on the fly for ease of
development (they're statically generated for production).

The view:

def build(request, template):
root = os.path.join(settings.RDIO_ROOT, 'web')
bg = Bujagali(template, root)

response = HttpResponse(bg.generate())
response['Content-Type'] = 'text/javascript; charset=utf-8'
# expires in a year
response['Cache-Control'] = 'public; max-age=31536000'

return response

The route:

urlpatterns = patterns('rdio.web.bujagali',
url(r'(?P<template>.+\.bg\.html).*\.js', 'template.build'))
Documentation in development...


Rendering Templates
-------------------

You need to include both underscore.js and bujagali.js to render templates.

<script src="client/underscore.js" type="text/javascript"></script>
<script src="client/bujagali.js" type="text/javascript"></script>

Rendering a template requires two things: a template name and a version of the
template. The server provides the version with the data used to render the
template.

On the server side:

from bujagali import create_context

root = /somewhere/on/my/filesystem
data = {
'name': 'Rdio',
'project': 'Bujagali',
}
template = 'projectDetails.bg.html'

context = create_context(template, data, root)

`context` is a dict, so from there, you need to serialize `context` and get
it to the client in whatever way you see fit. I suggest JSON.

On the client side:

Bujagali.render('projectDetails.bg.html', context, function(data, markup) {
// this will be called after the template as been evaluated.
// I suggest you inject your new markup in the DOM somewhere
});

`context` is expected to be a JS object, so unserialize whatever you did in the
first situation.
Documentation in development...

That should be all you need to know to get going.
Loading

0 comments on commit 31da735

Please sign in to comment.