Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
yumike committed Jun 25, 2012
0 parents commit b8a60d0
Show file tree
Hide file tree
Showing 170 changed files with 40,411 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.egg-info
*.pyc
dist
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright (c) 2012, Mike Yumatov <mike@yumatov.org>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
5 changes: 5 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include LICENSE
include README.rst

include gears_handlebars/compiler.js
recursive-include gears_handlebars/node_modules *
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
update:
rm -rf gears_handlebars/node_modules
cd gears_handlebars && npm install handlebars
rm -rf gears_handlebars/node_modules/.bin
38 changes: 38 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
gears-handlebars
==================

Handlebars_ compiler for Gears_. This package already includes the Handlebars
source code for you, so you don't need to worry about installing it yourself.

Installation
------------

Install ``gears-handlebars`` with pip::

$ pip install gears-handlebars


Requirements
------------

``gears-handlebars`` requires node.js_ to be installed in your system.


Usage
-----

Add ``gears_handlebars.HandlebarsCompiler`` to ``environment``'s compilers
registry::

from gears_handlebars import HandlebarsCompiler
environment.compilers.register('.handlebars', HandlebarsCompiler.as_handler())

If you use Gears in your Django project, add this code to its settings::

GEARS_COMPILERS = {
'.handlebars': 'gears_handlebars.HandlebarsCompiler',
}

.. _Handlebars: http://handlebarsjs.com/
.. _Gears: https://github.com/gears/gears
.. _node.js: http://nodejs.org/
1 change: 1 addition & 0 deletions gears_handlebars/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .compiler import HandlebarsCompiler
13 changes: 13 additions & 0 deletions gears_handlebars/compiler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var handlebars = require('handlebars'),
template = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');

process.stdin.on('data', function(chunk) {
template += chunk;
});

process.stdin.on('end', function() {
process.stdout.write(handlebars.precompile(template));
});
24 changes: 24 additions & 0 deletions gears_handlebars/compiler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import os
from gears.compilers import ExecCompiler


SOURCE = '\n'.join((
"(function() {",
" var template = Handlebars.template,",
" templates = Handlebars.templates = Handlebars.templates || {};",
" templates['%(name)s'] = template(%(source)s);",
"}).call(this);"))


class HandlebarsCompiler(ExecCompiler):

result_mimetype = 'application/javascript'
executable = 'node'
params = [os.path.join(os.path.dirname(__file__), 'compiler.js')]

def __call__(self, asset):
super(HandlebarsCompiler, self).__call__(asset)
asset.processed_source = SOURCE % {
'name': asset.attributes.path_without_suffix,
'source': asset.processed_source,
}
11 changes: 11 additions & 0 deletions gears_handlebars/node_modules/handlebars/.npmignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions gears_handlebars/node_modules/handlebars/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b8a60d0

Please sign in to comment.