Skip to content

Commit

Permalink
Add setup.py, move code into angular2tmpl directory, and submit to PyPI.
Browse files Browse the repository at this point in the history
  • Loading branch information
emosenkis committed Jan 19, 2014
1 parent 6a0dd6f commit f32b985
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 26 deletions.
48 changes: 22 additions & 26 deletions README.md → README.rst
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
angular2tmpl
============

Convert AngularJS templates to server-side templates for SEO.
Convert AngularJS templates to Jinja2 templates for SEO.

The basic idea is to create a version of an Angular-powered website that can be
rendered on the server for consumption by search engines. This is accomplished
in two parts:

1. Use angulart2tmpl to convert Angular templates to Jinja2 templates. This may
require implementing custom Angular directives in Python (using
xml.dom.minidom).
``xml.dom.minidom``).
2. Implement a Python WSGI app that gathers the necessary data using the same
API that powers your Angular app and passes it to the generated Jinja2
templates.
Expand All @@ -23,18 +22,16 @@ roughly the same as their JavaScript-based counterparts.

Features
--------

- Reuses existing Angular templates and API
- Reuses existing Angular templates and backend API
- Avoids the expense and complexity of running a headless browser
- Compatible with PaaS platforms such as Google App Engine


Status
------

angular2tmpl is pre-alpha software. It currently implements a *very* minimal
subset of the ng and ngRoute modules and makes little attempt to address edge
cases. No guarantees are made at this time about maintaining backwards
subset of the ``ng`` and ``ngRoute`` modules and makes little attempt to address
edge cases. No guarantees are made at this time about maintaining backwards
compatibility. Unit tests are still a twinkle in its eye.

That said, angular2tmpl does currently satisfy the needs of the site that it was
Expand All @@ -43,38 +40,38 @@ built for.

Installation & Dependencies
---------------------------
Installation is easy::

pip install angular2tmpl

The only dependencies are jinja2 and html5lib. The best way to install at the
moment is to clone the repository and add it to your PYTHONPATH. angular2tmpl
was built on Python 2.7, but with the intention of making conversion with 2to3
fairly painless. If you try it, let me know how it goes.
The only dependencies are Jinja2 and html5lib, both of which will be
automatically installed. angular2tmpl was built on Python 2.7, but with the
intention of making conversion with 2to3 fairly painless. If you try it, let me
know how it goes.


Usage
-----

The main entrypoint into angular2tmpl is bin/convert.py. Try running it with
--help to see how it can be configured, then run it on each of your Angular
templates. angular2tmpl directives are intended to be similar to Angular
directives while staying Pythonic and taking advantage of the reduced
complexity that comes from non-interactive rendering. See modules/ng.py for
examples.
Just run ``angular2tmpl``. Try ``--help`` to see the available flags and default
values, then run it on each of your Angular templates. angular2tmpl directives
are intended to be similar to Angular directives while staying Pythonic and
taking advantage of the reduced complexity that comes from non-interactive
rendering. See ``modules/ng.py`` for examples.

Due to differences in the semantics of Angular vs. Jinja2 expressions, some
modifications to the default Jinja2 environment and your template data are
necessary:

1. Angular is extremely generous about ignoring errors and missing values in
templates. To emulate this behavior, set the 'undefined' property of your
Jinja2 environment object to angular2tmpl.jinja2.PermissiveUndefined.
2. JavaScript objects allow access to non-existent properties and treat foo.bar
and foo['bar'] the same way. To get the same behavior out of your template
variables, convert them using angular2tmpl.jinja2.js_data.
templates. To emulate this behavior, set the ``undefined`` property of your
Jinja2 environment object to ``angular2tmpl.jinja2.PermissiveUndefined``.
2. JavaScript objects allow access to non-existent properties and treat
``foo.bar`` and ``foo['bar']`` the same way. To get the same behavior out of
your template variables, convert them using ``angular2tmpl.jinja2.js_data``.


Background
----------

For more information about how Google handles JavaScript-heavy sites and how to
make it request a special server-rendered version of your site, see
https://developers.google.com/webmasters/ajax-crawling/docs/specification. For
Expand All @@ -86,5 +83,4 @@ http://www.ng-newsletter.com/posts/serious-angular-seo.html.

Disclaimers
-----------

angular2tmpl is not affiliated in any way with Google or AngularJS.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python

from setuptools import setup, find_packages

setup(
name='angular2tmpl',
version='0.1.0',
packages=find_packages(),
scripts=['bin/angular2tmpl'],
author='Eitan Mosenkis',
author_email='[email protected]',
description='Convert AngularJS templates to Jinja2 templates for SEO.',
long_description=open('README.rst').read(),
license='MIT',
keywords='angularjs jinja2 seo',
url='https://github.com/emosenkis/angular2tmpl',
install_requires=['html5lib >= 1.0b3', 'Jinja2 >= 2.7.1']
)

0 comments on commit f32b985

Please sign in to comment.