├── .gitignore ├── LICENSE ├── README ├── haml ├── __init__.py └── management │ ├── __init__.py │ └── commands │ ├── __init__.py │ └── compilehaml.py ├── setup.py └── tests ├── __init__.py ├── fixtures ├── test1.hamlpy ├── test1.html.expected ├── test2.hamlpy └── test2.html.expected └── haml_test.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.swp 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Adolfo Fitoria 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without limitation 7 | the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the 9 | Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice 13 | shall be included in all copies or substantial portions of 14 | the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 17 | KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 19 | PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 20 | OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 21 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 22 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Django-haml 2 | 3 | Django Management Command to convert hamlpy templates to Django Templates 4 | 5 | Requirements: 6 | -Hamlpy (http://github.com/jessemiller/HamlPy) 7 | 8 | Installation an use: 9 | 1. python setup.py install 10 | 2. Add 'haml' to your INSTALLED_APPS settings in your Django project. 11 | 3. Make your hamlpy templates in your template dir. 12 | 4. ./manage.py compilehaml 13 | 14 | TODO: 15 | -More test cases 16 | -------------------------------------------------------------------------------- /haml/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fitoria/django-haml/525dc97315db8ed2265285f60f7c7c9aebbd8d4a/haml/__init__.py -------------------------------------------------------------------------------- /haml/management/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fitoria/django-haml/525dc97315db8ed2265285f60f7c7c9aebbd8d4a/haml/management/__init__.py -------------------------------------------------------------------------------- /haml/management/commands/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fitoria/django-haml/525dc97315db8ed2265285f60f7c7c9aebbd8d4a/haml/management/commands/__init__.py -------------------------------------------------------------------------------- /haml/management/commands/compilehaml.py: -------------------------------------------------------------------------------- 1 | from django.core.management.base import BaseCommand, CommandError 2 | #TODO:from hamlpy.hamlpy import Compiler 3 | import os 4 | import sys 5 | 6 | def compile_haml(basedirs=[]): 7 | if os.environ.get('DJANGO_SETTINGS_MODULE'): 8 | from django.conf import settings 9 | basedirs.extend(settings.TEMPLATE_DIRS) 10 | 11 | basedirs = set(map(os.path.abspath, filter(os.path.isdir, basedirs))) 12 | 13 | if not basedirs: 14 | raise CommandError("This script should be run on your Django project or app tree") 15 | 16 | for basedir in basedirs: 17 | for dirpath, dirnames, filenames in os.walk(basedir): 18 | for f in filenames: 19 | if f.endswith('.hamlpy'): 20 | sys.stderr.write('processing file %s in %s\n' % (f, dirpath)) 21 | pf = os.path.splitext(os.path.join(dirpath, f))[0] 22 | 23 | cmd = 'hamlpy %s.hamlpy %s.html' % (pf, pf) 24 | os.system(cmd) 25 | 26 | class Command(BaseCommand): 27 | '''This will compile all the haml templates into 28 | django templates''' 29 | 30 | help = 'Compiles all the haml templates into html' 31 | 32 | def handle(self, *args, **options): 33 | compile_haml() 34 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | try: 5 | from setuptools.core import setup 6 | except ImportError: 7 | from distutils.core import setup 8 | 9 | import os 10 | 11 | install_requires = [ 12 | 'hamlpy', 13 | ] 14 | 15 | setup( 16 | name = "django-haml", 17 | version = "0.1", 18 | url = "http://github.com/fitoria/django-haml", 19 | licence = 'MIT', 20 | description = 'Django haml management command.', 21 | author = 'Adolfo Fitoria', 22 | author_email = 'adolfo.fitoria@gmail.com', 23 | install_requires = install_requires, 24 | packages = ['haml', 25 | 'haml.management', 26 | 'haml.management.commands'], 27 | include_package_data = True, 28 | classifiers = [ 29 | 'Development Status :: 3 - Alpha', 30 | 'Framework :: Django', 31 | 'Intended Audience :: Developers', 32 | 'Licence :: OSI Approved :: MIT Licence', 33 | 'Programming Languaje :: Python', 34 | 'Topic :: Internet :: WWW/HTTP', 35 | ], 36 | test_suite = "tests", 37 | ) 38 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | import haml_test 2 | 3 | def suite(): 4 | import unittest 5 | suite = unittest.TestSuite() 6 | suite.addTests(haml_test.suite()) 7 | return suite 8 | 9 | if __name__ == '__main__': 10 | unittest.TextTestRunner(verbosity=2).run(suite()) 11 | 12 | -------------------------------------------------------------------------------- /tests/fixtures/test1.hamlpy: -------------------------------------------------------------------------------- 1 | #profile 2 | .left.column 3 | #date 2010/02/18 4 | #address Toronto, ON 5 | .right.column 6 | #bio Jesse Miller 7 | -------------------------------------------------------------------------------- /tests/fixtures/test1.html.expected: -------------------------------------------------------------------------------- 1 |
2 |
3 |
2010/02/18
4 |
Toronto, ON
5 |
6 |
7 |
Jesse Miller
8 |
9 |
10 | -------------------------------------------------------------------------------- /tests/fixtures/test2.hamlpy: -------------------------------------------------------------------------------- 1 | %ul#athletes 2 | - for athlete in athlete_list 3 | %li.athlete{'id': 'athlete_{{ athlete.pk }}'}= athlete.name -------------------------------------------------------------------------------- /tests/fixtures/test2.html.expected: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /tests/haml_test.py: -------------------------------------------------------------------------------- 1 | from haml.management.commands.compilehaml import compile_haml 2 | import unittest 3 | import os 4 | 5 | class CompileHamlTestCase(unittest.TestCase): 6 | 7 | def testAll(self): 8 | tests = ['test1', 'test2'] 9 | 10 | for test in tests: 11 | test_file = 'tests/fixtures/%s.html' % (test,) 12 | if os.path.isfile(test_file): 13 | os.unlink(test_file) 14 | 15 | compile_haml(['tests']) 16 | 17 | for test in tests: 18 | test_file = 'tests/fixtures/%s.html' % (test,) 19 | assert os.path.isfile(test_file) 20 | assert os.system('cmp %s %s.expected' % (test_file, test_file)) == 0 21 | 22 | def suite(): 23 | loader = unittest.TestLoader() 24 | suite = unittest.TestSuite() 25 | suite.addTest(loader.loadTestsFromTestCase(CompileHamlTestCase)) 26 | return suite 27 | 28 | if __name__ == '__main__': 29 | unittest.TextTestRunner(verbosity=2).run(suite()) 30 | --------------------------------------------------------------------------------