diff options
author | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-22 23:26:25 +0000 |
---|---|---|
committer | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-22 23:28:26 +0000 |
commit | 68edde91fe6afbf2af183ca3d451c466ca4196a6 (patch) | |
tree | 1723e0534e24327eb83d44eea97c226cab0bdd2f | |
parent | 59b165d93221b2d55d96996dafcf46044b23161c (diff) | |
download | chromium_src-68edde91fe6afbf2af183ca3d451c466ca4196a6.zip chromium_src-68edde91fe6afbf2af183ca3d451c466ca4196a6.tar.gz chromium_src-68edde91fe6afbf2af183ca3d451c466ca4196a6.tar.bz2 |
Rename the docserver third_party dependency "handlebar" to "motemplate", as part
of updating that templating library.
History: this dependency is owned by me, and I changed the name to avoid
confusion with the "handlebars" templating system.
R=yoz@chromium.org, brettw@chromium.org
Review URL: https://codereview.chromium.org/498813002
Cr-Commit-Position: refs/heads/master@{#291550}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@291550 0039d316-1c4b-4281-b951-d872f2087c98
17 files changed, 48 insertions, 51 deletions
diff --git a/chrome/common/extensions/docs/README b/chrome/common/extensions/docs/README index 256889b9..385193c 100644 --- a/chrome/common/extensions/docs/README +++ b/chrome/common/extensions/docs/README @@ -46,9 +46,9 @@ Editing docs API documentation) or "articles" (if changing non-API documentation). If adding files or APIs you'll also need to add something to "public". - - Files in templates directory use the Handlebar template language. It is + - Files in templates directory use the Motemplate template language. It is extremely simple, essentially: write HTML. - See third_party/handlebar/README.md. + See third_party/motemplate/README.md. - static/css/out/site.css is generated by compiling static/sass/*.scss files. Don't change site.css directly. Instead, change the *.scss files diff --git a/chrome/common/extensions/docs/server2/build_server.py b/chrome/common/extensions/docs/server2/build_server.py index 58bd9d7..f31eaa0 100755 --- a/chrome/common/extensions/docs/server2/build_server.py +++ b/chrome/common/extensions/docs/server2/build_server.py @@ -58,7 +58,7 @@ def main(): '*-------------------------------------------------------------*\n') - CopyThirdParty(os.path.join(THIRD_PARTY_DIR, 'handlebar'), 'handlebar') + CopyThirdParty(os.path.join(THIRD_PARTY_DIR, 'motemplate'), 'motemplate') CopyThirdParty(os.path.join(THIRD_PARTY_DIR, 'markdown'), 'markdown', make_init=False) CopyThirdParty(os.path.join(SRC_DIR, 'ppapi', 'generators'), @@ -79,11 +79,11 @@ def main(): CopyThirdParty(os.path.join(THIRD_PARTY_DIR, 'google_appengine_cloudstorage', 'cloudstorage'), 'cloudstorage') - # To be able to use the Handlebar class we need this import in __init__.py. + # To be able to use the Motemplate class we need this import in __init__.py. with open(os.path.join(LOCAL_THIRD_PARTY_DIR, - 'handlebar', + 'motemplate', '__init__.py'), 'a') as f: - f.write('from handlebar import Handlebar\n') + f.write('from motemplate import Motemplate\n') if __name__ == '__main__': main() diff --git a/chrome/common/extensions/docs/server2/compiled_file_system.py b/chrome/common/extensions/docs/server2/compiled_file_system.py index 58ab967..7a2ba6a 100644 --- a/chrome/common/extensions/docs/server2/compiled_file_system.py +++ b/chrome/common/extensions/docs/server2/compiled_file_system.py @@ -9,9 +9,9 @@ from docs_server_utils import ToUnicode from file_system import FileNotFoundError from future import Future from path_util import AssertIsDirectory, AssertIsFile, ToDirectory -from third_party.handlebar import Handlebar from third_party.json_schema_compiler import json_parse from third_party.json_schema_compiler.memoize import memoize +from third_party.motemplate import Motemplate _SINGLE_FILE_FUNCTIONS = set() @@ -111,7 +111,7 @@ class CompiledFileSystem(object): ''' return self.Create( file_system, - SingleFile(lambda path, text: Handlebar(ToUnicode(text), name=path)), + SingleFile(lambda path, text: Motemplate(ToUnicode(text), name=path)), CompiledFileSystem) @memoize diff --git a/chrome/common/extensions/docs/server2/content_provider.py b/chrome/common/extensions/docs/server2/content_provider.py index 84e3d2c..e04dc7f 100644 --- a/chrome/common/extensions/docs/server2/content_provider.py +++ b/chrome/common/extensions/docs/server2/content_provider.py @@ -15,8 +15,8 @@ from future import All, Future from path_canonicalizer import PathCanonicalizer from path_util import AssertIsValid, IsDirectory, Join, ToDirectory from special_paths import SITE_VERIFICATION_FILE -from third_party.handlebar import Handlebar from third_party.markdown import markdown +from third_party.motemplate import Motemplate _MIMETYPE_OVERRIDES = { @@ -42,7 +42,7 @@ class ContentProvider(object): Typically the file contents will be either str (for binary content) or unicode (for text content). However, HTML files *may* be returned as - Handlebar templates (if |supports_templates| is True on construction), in + Motemplate templates (if |supports_templates| is True on construction), in which case the caller will presumably want to Render them. Zip file are automatically created and returned for .zip file extensions if @@ -89,7 +89,7 @@ class ContentProvider(object): content = markdown(ToUnicode(text), extensions=('extra', 'headerid', 'sane_lists')) if self._supports_templates: - content = Handlebar(content, name=path) + content = Motemplate(content, name=path) mimetype = 'text/html' elif mimetype is None: content = text @@ -97,7 +97,7 @@ class ContentProvider(object): elif mimetype == 'text/html': content = ToUnicode(text) if self._supports_templates: - content = Handlebar(content, name=path) + content = Motemplate(content, name=path) elif (mimetype.startswith('text/') or mimetype in ('application/javascript', 'application/json')): content = ToUnicode(text) diff --git a/chrome/common/extensions/docs/server2/content_provider_test.py b/chrome/common/extensions/docs/server2/content_provider_test.py index afe47e2..c93815b 100755 --- a/chrome/common/extensions/docs/server2/content_provider_test.py +++ b/chrome/common/extensions/docs/server2/content_provider_test.py @@ -14,7 +14,7 @@ from file_system import FileNotFoundError from object_store_creator import ObjectStoreCreator from path_canonicalizer import PathCanonicalizer from test_file_system import TestFileSystem -from third_party.handlebar import Handlebar +from third_party.motemplate import Motemplate _REDIRECTS_JSON = json.dumps({ 'oldfile.html': 'storage.html', @@ -99,7 +99,7 @@ class ContentProviderUnittest(unittest.TestCase): def _assertTemplateContent(self, content, path, version): content_and_type = self._content_provider.GetContentAndType(path).Get() - self.assertEqual(Handlebar, type(content_and_type.content)) + self.assertEqual(Motemplate, type(content_and_type.content)) content_and_type.content = content_and_type.content.source self._assertContent(content, 'text/html', content_and_type) self.assertEqual(version, self._content_provider.GetVersion(path).Get()) diff --git a/chrome/common/extensions/docs/server2/jsc_view.py b/chrome/common/extensions/docs/server2/jsc_view.py index 70718d3..48aa9cc 100644 --- a/chrome/common/extensions/docs/server2/jsc_view.py +++ b/chrome/common/extensions/docs/server2/jsc_view.py @@ -62,7 +62,7 @@ def _FormatValue(value): class JSCView(object): '''Uses a Model from the JSON Schema Compiler and generates a dict that - a Handlebar template can use for a data source. + a Motemplate template can use for a data source. ''' def __init__(self, @@ -550,7 +550,7 @@ class JSCView(object): if ext_type not in node.get('extension_types', (ext_type,)): continue # If there is a 'partial' argument and it hasn't already been - # converted to a Handlebar object, transform it to a template. + # converted to a Motemplate object, transform it to a template. if 'partial' in node: # Note: it's enough to copy() not deepcopy() because only a single # top-level key is being modified. diff --git a/chrome/common/extensions/docs/server2/jsc_view_test.py b/chrome/common/extensions/docs/server2/jsc_view_test.py index 57d9823..b21763b 100755 --- a/chrome/common/extensions/docs/server2/jsc_view_test.py +++ b/chrome/common/extensions/docs/server2/jsc_view_test.py @@ -31,7 +31,7 @@ from test_util import Server2Path class _FakeTemplateCache(object): def GetFromFile(self, key): - return Future(value='handlebar %s' % key) + return Future(value='motemplate %s' % key) class _FakeFeaturesBundle(object): @@ -189,7 +189,7 @@ class JSCViewTest(unittest.TestCase): }, { 'title': 'Availability', 'content': [ - { 'partial': 'handlebar chrome/common/extensions/docs/' + + { 'partial': 'motemplate chrome/common/extensions/docs/' + 'templates/private/intro_tables/stable_message.html', 'version': 5, 'scheduled': None @@ -214,7 +214,7 @@ class JSCViewTest(unittest.TestCase): { 'title': 'Content Scripts', 'content': [ { - 'partial': 'handlebar chrome/common/extensions/docs' + + 'partial': 'motemplate chrome/common/extensions/docs' + '/templates/private/intro_tables/content_scripts.html', 'contentScriptSupport': { 'name': 'tester', @@ -247,7 +247,7 @@ class JSCViewTest(unittest.TestCase): expected_list[1] = { 'title': 'Availability', 'content': [ - { 'partial': 'handlebar chrome/common/extensions/docs/' + + { 'partial': 'motemplate chrome/common/extensions/docs/' + 'templates/private/intro_tables/beta_message.html', 'version': 27, 'scheduled': 28 @@ -396,7 +396,7 @@ class JSCViewWithNodeAvailabilityTest(unittest.TestCase): self.assertEquals({ 'scheduled': None, 'version': 26, - 'partial': 'handlebar chrome/common/extensions/docs/templates/' + + 'partial': 'motemplate chrome/common/extensions/docs/templates/' + 'private/intro_tables/deprecated_message.html' }, model_dict['types'][2]['availability']) diff --git a/chrome/common/extensions/docs/server2/permissions_data_source_test.py b/chrome/common/extensions/docs/server2/permissions_data_source_test.py index a4b37cf..f7a9090 100755 --- a/chrome/common/extensions/docs/server2/permissions_data_source_test.py +++ b/chrome/common/extensions/docs/server2/permissions_data_source_test.py @@ -10,7 +10,7 @@ import unittest from extensions_paths import CHROME_EXTENSIONS from permissions_data_source import PermissionsDataSource from server_instance import ServerInstance -from third_party.handlebar import Handlebar +from third_party.motemplate import Motemplate from test_file_system import TestFileSystem @@ -158,13 +158,13 @@ class PermissionsDataSourceTest(unittest.TestCase): # - Sort keys. Since the tests don't use OrderedDicts we can't make # assertions about the order, which is unfortunate. Oh well. # - Render all of the Handlerbar instances so that we can use ==. - # Handlebars don't implement __eq__, but they probably should. + # Motemplates don't implement __eq__, but they probably should. for lst in (actual_apps, actual_extensions, expected_apps, expected_extensions): lst.sort(key=itemgetter('name')) for mapping in lst: for key, value in mapping.iteritems(): - if isinstance(value, Handlebar): + if isinstance(value, Motemplate): mapping[key] = value.Render().text self.assertEqual(expected_extensions, actual_extensions) diff --git a/chrome/common/extensions/docs/server2/render_servlet.py b/chrome/common/extensions/docs/server2/render_servlet.py index 4ef19bc..26caca2 100644 --- a/chrome/common/extensions/docs/server2/render_servlet.py +++ b/chrome/common/extensions/docs/server2/render_servlet.py @@ -13,7 +13,7 @@ from file_system import FileNotFoundError from redirector import Redirector from servlet import Servlet, Response from special_paths import SITE_VERIFICATION_FILE -from third_party.handlebar import Handlebar +from third_party.motemplate import Motemplate def _MakeHeaders(content_type, etag=None): @@ -111,7 +111,7 @@ class RenderServlet(Servlet): logging.error('%s had empty content' % path) content = content_and_type.content - if isinstance(content, Handlebar): + if isinstance(content, Motemplate): template_content, template_warnings = ( server_instance.template_renderer.Render(content, self._request)) # HACK: the site verification file (google2ed...) doesn't have a title. diff --git a/chrome/common/extensions/docs/server2/template_data_source_test.py b/chrome/common/extensions/docs/server2/template_data_source_test.py index 423acce..fee3c9a 100755 --- a/chrome/common/extensions/docs/server2/template_data_source_test.py +++ b/chrome/common/extensions/docs/server2/template_data_source_test.py @@ -10,7 +10,7 @@ from extensions_paths import SERVER2 from server_instance import ServerInstance from template_data_source import TemplateDataSource from test_util import DisableLogging, ReadFile -from third_party.handlebar import Handlebar +from third_party.motemplate import Motemplate def _ReadFile(*path): return ReadFile(SERVER2, 'test_data', 'template_data_source', *path) @@ -38,12 +38,12 @@ class TemplateDataSourceTest(unittest.TestCase): def testSimple(self): test_data_source = _CreateTestDataSource('simple') - template_a1 = Handlebar(_ReadFile('simple', 'test1.html')) + template_a1 = Motemplate(_ReadFile('simple', 'test1.html')) context = [{}, {'templates': {}}] self.assertEqual( template_a1.Render(*context).text, test_data_source.get('test1').Render(*context).text) - template_a2 = Handlebar(_ReadFile('simple', 'test2.html')) + template_a2 = Motemplate(_ReadFile('simple', 'test2.html')) self.assertEqual( template_a2.Render(*context).text, test_data_source.get('test2').Render(*context).text) diff --git a/chrome/common/extensions/docs/server2/template_renderer.py b/chrome/common/extensions/docs/server2/template_renderer.py index 6b7e7c4..8408a90 100644 --- a/chrome/common/extensions/docs/server2/template_renderer.py +++ b/chrome/common/extensions/docs/server2/template_renderer.py @@ -3,7 +3,7 @@ # found in the LICENSE file. from data_source_registry import CreateDataSources -from third_party.handlebar import Handlebar +from third_party.motemplate import Motemplate from url_constants import GITHUB_BASE, EXTENSIONS_SAMPLES @@ -27,7 +27,7 @@ class TemplateRenderer(object): Specify |additional_context| to inject additional template context when rendering the template. ''' - assert isinstance(template, Handlebar), type(template) + assert isinstance(template, Motemplate), type(template) render_context = CreateDataSources(self._server_instance, request) if data_sources is not None: render_context = dict((name, d) for name, d in render_context.iteritems() diff --git a/chrome/common/extensions/docs/server2/template_renderer_test.py b/chrome/common/extensions/docs/server2/template_renderer_test.py index 986b877..386f3e7 100755 --- a/chrome/common/extensions/docs/server2/template_renderer_test.py +++ b/chrome/common/extensions/docs/server2/template_renderer_test.py @@ -6,7 +6,7 @@ import unittest from server_instance import ServerInstance -from third_party.handlebar import Handlebar +from third_party.motemplate import Motemplate class TemplateRendererTest(unittest.TestCase): @@ -20,7 +20,7 @@ class TemplateRendererTest(unittest.TestCase): self._template_renderer = ServerInstance.ForLocal().template_renderer def testSimpleWiring(self): - template = Handlebar('hello {{?true}}{{strings.extension}}{{/}}') + template = Motemplate('hello {{?true}}{{strings.extension}}{{/}}') text, warnings = self._template_renderer.Render(template, None) self.assertEqual('hello extension', text) self.assertEqual([], warnings) diff --git a/third_party/handlebar/.gitignore b/third_party/motemplate/.gitignore index 0d20b64..0d20b64 100644 --- a/third_party/handlebar/.gitignore +++ b/third_party/motemplate/.gitignore diff --git a/third_party/handlebar/LICENSE b/third_party/motemplate/LICENSE index d645695..d645695 100644 --- a/third_party/handlebar/LICENSE +++ b/third_party/motemplate/LICENSE diff --git a/third_party/handlebar/OWNERS b/third_party/motemplate/OWNERS index d3c3af29..d3c3af29 100644 --- a/third_party/handlebar/OWNERS +++ b/third_party/motemplate/OWNERS diff --git a/third_party/handlebar/README.chromium b/third_party/motemplate/README.chromium index 06d305b..c46c025 100644 --- a/third_party/handlebar/README.chromium +++ b/third_party/motemplate/README.chromium @@ -1,9 +1,9 @@ -Name: Handlebar, cross-platform data binding templates. -Short Name: handlebar +Name: Motemplate, cross-platform data binding templates. +Short Name: motemplate URL: https://github.com/kalman/templates Version: 0 -Date: November 16, 2013 -Revision: commit 3e74633948a386d0a77a1c2b1df4c40546f4ec95 +Date: August 22, 2014 +Revision: commit 76237c8ece0272dc02d104eef24b66365b4feaf3 License: Apache 2.0 License File: NOT_SHIPPED Security Critical: no diff --git a/third_party/handlebar/handlebar.py b/third_party/motemplate/motemplate.py index 7e06868..397228b 100644 --- a/third_party/handlebar/handlebar.py +++ b/third_party/motemplate/motemplate.py @@ -12,18 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -# TODO: New name, not "handlebar". # TODO: Escaping control characters somehow. e.g. \{{, \{{-. import json import re -'''Handlebar templates are data binding templates more-than-loosely inspired by +'''Motemplate templates are data binding templates more-than-loosely inspired by ctemplate. Use like: - from handlebar import Handlebar + from motemplate import Motemplate - template = Handlebar('hello {{#foo bar/}} world') + template = Motemplate('hello {{#foo bar/}} world') input = { 'foo': [ { 'bar': 1 }, @@ -33,14 +32,14 @@ ctemplate. Use like: } print(template.render(input).text) -Handlebar will use get() on contexts to return values, so to create custom +Motemplate will use get() on contexts to return values, so to create custom getters (for example, something that populates values lazily from keys), just provide an object with a get() method. class CustomContext(object): def get(self, key): return 10 - print(Handlebar('hello {{world}}').render(CustomContext()).text) + print(Motemplate('hello {{world}}').render(CustomContext()).text) will print 'hello 10'. ''' @@ -648,11 +647,9 @@ class _JsonNode(_LeafNode): def __repr__(self): return '{{*%s}}' % self._id -# TODO: Better common model of _PartialNodeWithArguments, _PartialNodeInContext, -# and _PartialNode. class _PartialNodeWithArguments(_DecoratorNode): def __init__(self, partial, args): - if isinstance(partial, Handlebar): + if isinstance(partial, Motemplate): # Preserve any get() method that the caller has added. if hasattr(partial, 'get'): self.get = partial.get @@ -666,7 +663,7 @@ class _PartialNodeWithArguments(_DecoratorNode): class _PartialNodeInContext(_DecoratorNode): def __init__(self, partial, context): - if isinstance(partial, Handlebar): + if isinstance(partial, Motemplate): # Preserve any get() method that the caller has added. if hasattr(partial, 'get'): self.get = partial.get @@ -707,11 +704,11 @@ class _PartialNode(_LeafNode): if value is None: render_state.AddResolutionError(self._id) return - if not isinstance(value, (Handlebar, _Node)): + if not isinstance(value, (Motemplate, _Node)): render_state.AddResolutionError(self._id, description='not a partial') return - if isinstance(value, Handlebar): + if isinstance(value, Motemplate): node, name = value._top_node, value._name else: node, name = value, None @@ -912,8 +909,8 @@ class _TokenStream(object): def __str__(self): return repr(self) -class Handlebar(object): - '''A handlebar template. +class Motemplate(object): + '''A motemplate template. ''' def __init__(self, template, name=None): self.source = template |