Created
March 28, 2016 17:28
-
-
Save Deepwalker/6ecd03dd1c1a4c8d128c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from webassets.filter import Filter | |
class AngularTemplatesFilter(Filter): | |
input_template = "$templateCache.put('%s', '%s');" | |
output_template = """ | |
(function() { | |
angular.module('%s').run(['$templateCache', function($templateCache) { | |
%s | |
}]); | |
})(); | |
""" | |
def __init__(self, template_module, **kwargs): | |
super().__init__(**kwargs) | |
self.template_module = template_module | |
def output(self, _in, out, **kwargs): | |
out.write(self.output_template % (self.template_module, _in.read())) | |
def input(self, _in, out, **kwargs): | |
source_path = kwargs['source_path'] | |
rel_path = os.path.relpath(source_path, application.root_path) | |
path = os.path.join('/', rel_path) | |
data = _in.read().replace("\n", "\\n").replace("'", "\\'") | |
out.write(self.input_template % (path, data)) | |
assets.register('application_templates', | |
Bundle( | |
'angular/templates/some_template.html', | |
'angular/templates/some_template.html', | |
'angular/templates/some_template.html', | |
'angular/templates/some_template.html', | |
'angular/templates/some_template.html', | |
'angular/templates/some_template.html', | |
'angular/templates/some_template.html', | |
filters=AngularTemplatesFilter('MyApp.templates'), | |
output='assets/my-app-templates.js' | |
), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment