Commit 68edde91 authored by kalman@chromium.org's avatar kalman@chromium.org

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
parent 59b165d9
...@@ -46,9 +46,9 @@ Editing docs ...@@ -46,9 +46,9 @@ Editing docs
API documentation) or "articles" (if changing non-API documentation). API documentation) or "articles" (if changing non-API documentation).
If adding files or APIs you'll also need to add something to "public". 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. 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 - static/css/out/site.css is generated by compiling static/sass/*.scss
files. Don't change site.css directly. Instead, change the *.scss files files. Don't change site.css directly. Instead, change the *.scss files
......
...@@ -58,7 +58,7 @@ def main(): ...@@ -58,7 +58,7 @@ def main():
'*-------------------------------------------------------------*\n') '*-------------------------------------------------------------*\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', CopyThirdParty(os.path.join(THIRD_PARTY_DIR, 'markdown'), 'markdown',
make_init=False) make_init=False)
CopyThirdParty(os.path.join(SRC_DIR, 'ppapi', 'generators'), CopyThirdParty(os.path.join(SRC_DIR, 'ppapi', 'generators'),
...@@ -79,11 +79,11 @@ def main(): ...@@ -79,11 +79,11 @@ def main():
CopyThirdParty(os.path.join(THIRD_PARTY_DIR, 'google_appengine_cloudstorage', CopyThirdParty(os.path.join(THIRD_PARTY_DIR, 'google_appengine_cloudstorage',
'cloudstorage'), '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, with open(os.path.join(LOCAL_THIRD_PARTY_DIR,
'handlebar', 'motemplate',
'__init__.py'), 'a') as f: '__init__.py'), 'a') as f:
f.write('from handlebar import Handlebar\n') f.write('from motemplate import Motemplate\n')
if __name__ == '__main__': if __name__ == '__main__':
main() main()
...@@ -9,9 +9,9 @@ from docs_server_utils import ToUnicode ...@@ -9,9 +9,9 @@ from docs_server_utils import ToUnicode
from file_system import FileNotFoundError from file_system import FileNotFoundError
from future import Future from future import Future
from path_util import AssertIsDirectory, AssertIsFile, ToDirectory 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 import json_parse
from third_party.json_schema_compiler.memoize import memoize from third_party.json_schema_compiler.memoize import memoize
from third_party.motemplate import Motemplate
_SINGLE_FILE_FUNCTIONS = set() _SINGLE_FILE_FUNCTIONS = set()
...@@ -111,7 +111,7 @@ class CompiledFileSystem(object): ...@@ -111,7 +111,7 @@ class CompiledFileSystem(object):
''' '''
return self.Create( return self.Create(
file_system, file_system,
SingleFile(lambda path, text: Handlebar(ToUnicode(text), name=path)), SingleFile(lambda path, text: Motemplate(ToUnicode(text), name=path)),
CompiledFileSystem) CompiledFileSystem)
@memoize @memoize
......
...@@ -15,8 +15,8 @@ from future import All, Future ...@@ -15,8 +15,8 @@ from future import All, Future
from path_canonicalizer import PathCanonicalizer from path_canonicalizer import PathCanonicalizer
from path_util import AssertIsValid, IsDirectory, Join, ToDirectory from path_util import AssertIsValid, IsDirectory, Join, ToDirectory
from special_paths import SITE_VERIFICATION_FILE from special_paths import SITE_VERIFICATION_FILE
from third_party.handlebar import Handlebar
from third_party.markdown import markdown from third_party.markdown import markdown
from third_party.motemplate import Motemplate
_MIMETYPE_OVERRIDES = { _MIMETYPE_OVERRIDES = {
...@@ -42,7 +42,7 @@ class ContentProvider(object): ...@@ -42,7 +42,7 @@ class ContentProvider(object):
Typically the file contents will be either str (for binary content) or Typically the file contents will be either str (for binary content) or
unicode (for text content). However, HTML files *may* be returned as 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. which case the caller will presumably want to Render them.
Zip file are automatically created and returned for .zip file extensions if Zip file are automatically created and returned for .zip file extensions if
...@@ -89,7 +89,7 @@ class ContentProvider(object): ...@@ -89,7 +89,7 @@ class ContentProvider(object):
content = markdown(ToUnicode(text), content = markdown(ToUnicode(text),
extensions=('extra', 'headerid', 'sane_lists')) extensions=('extra', 'headerid', 'sane_lists'))
if self._supports_templates: if self._supports_templates:
content = Handlebar(content, name=path) content = Motemplate(content, name=path)
mimetype = 'text/html' mimetype = 'text/html'
elif mimetype is None: elif mimetype is None:
content = text content = text
...@@ -97,7 +97,7 @@ class ContentProvider(object): ...@@ -97,7 +97,7 @@ class ContentProvider(object):
elif mimetype == 'text/html': elif mimetype == 'text/html':
content = ToUnicode(text) content = ToUnicode(text)
if self._supports_templates: if self._supports_templates:
content = Handlebar(content, name=path) content = Motemplate(content, name=path)
elif (mimetype.startswith('text/') or elif (mimetype.startswith('text/') or
mimetype in ('application/javascript', 'application/json')): mimetype in ('application/javascript', 'application/json')):
content = ToUnicode(text) content = ToUnicode(text)
......
...@@ -14,7 +14,7 @@ from file_system import FileNotFoundError ...@@ -14,7 +14,7 @@ from file_system import FileNotFoundError
from object_store_creator import ObjectStoreCreator from object_store_creator import ObjectStoreCreator
from path_canonicalizer import PathCanonicalizer from path_canonicalizer import PathCanonicalizer
from test_file_system import TestFileSystem from test_file_system import TestFileSystem
from third_party.handlebar import Handlebar from third_party.motemplate import Motemplate
_REDIRECTS_JSON = json.dumps({ _REDIRECTS_JSON = json.dumps({
'oldfile.html': 'storage.html', 'oldfile.html': 'storage.html',
...@@ -99,7 +99,7 @@ class ContentProviderUnittest(unittest.TestCase): ...@@ -99,7 +99,7 @@ class ContentProviderUnittest(unittest.TestCase):
def _assertTemplateContent(self, content, path, version): def _assertTemplateContent(self, content, path, version):
content_and_type = self._content_provider.GetContentAndType(path).Get() 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 content_and_type.content = content_and_type.content.source
self._assertContent(content, 'text/html', content_and_type) self._assertContent(content, 'text/html', content_and_type)
self.assertEqual(version, self._content_provider.GetVersion(path).Get()) self.assertEqual(version, self._content_provider.GetVersion(path).Get())
......
...@@ -62,7 +62,7 @@ def _FormatValue(value): ...@@ -62,7 +62,7 @@ def _FormatValue(value):
class JSCView(object): class JSCView(object):
'''Uses a Model from the JSON Schema Compiler and generates a dict that '''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, def __init__(self,
...@@ -550,7 +550,7 @@ class JSCView(object): ...@@ -550,7 +550,7 @@ class JSCView(object):
if ext_type not in node.get('extension_types', (ext_type,)): if ext_type not in node.get('extension_types', (ext_type,)):
continue continue
# If there is a 'partial' argument and it hasn't already been # 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: if 'partial' in node:
# Note: it's enough to copy() not deepcopy() because only a single # Note: it's enough to copy() not deepcopy() because only a single
# top-level key is being modified. # top-level key is being modified.
......
...@@ -31,7 +31,7 @@ from test_util import Server2Path ...@@ -31,7 +31,7 @@ from test_util import Server2Path
class _FakeTemplateCache(object): class _FakeTemplateCache(object):
def GetFromFile(self, key): def GetFromFile(self, key):
return Future(value='handlebar %s' % key) return Future(value='motemplate %s' % key)
class _FakeFeaturesBundle(object): class _FakeFeaturesBundle(object):
...@@ -189,7 +189,7 @@ class JSCViewTest(unittest.TestCase): ...@@ -189,7 +189,7 @@ class JSCViewTest(unittest.TestCase):
}, },
{ 'title': 'Availability', { 'title': 'Availability',
'content': [ 'content': [
{ 'partial': 'handlebar chrome/common/extensions/docs/' + { 'partial': 'motemplate chrome/common/extensions/docs/' +
'templates/private/intro_tables/stable_message.html', 'templates/private/intro_tables/stable_message.html',
'version': 5, 'version': 5,
'scheduled': None 'scheduled': None
...@@ -214,7 +214,7 @@ class JSCViewTest(unittest.TestCase): ...@@ -214,7 +214,7 @@ class JSCViewTest(unittest.TestCase):
{ 'title': 'Content Scripts', { 'title': 'Content Scripts',
'content': [ 'content': [
{ {
'partial': 'handlebar chrome/common/extensions/docs' + 'partial': 'motemplate chrome/common/extensions/docs' +
'/templates/private/intro_tables/content_scripts.html', '/templates/private/intro_tables/content_scripts.html',
'contentScriptSupport': { 'contentScriptSupport': {
'name': 'tester', 'name': 'tester',
...@@ -247,7 +247,7 @@ class JSCViewTest(unittest.TestCase): ...@@ -247,7 +247,7 @@ class JSCViewTest(unittest.TestCase):
expected_list[1] = { expected_list[1] = {
'title': 'Availability', 'title': 'Availability',
'content': [ 'content': [
{ 'partial': 'handlebar chrome/common/extensions/docs/' + { 'partial': 'motemplate chrome/common/extensions/docs/' +
'templates/private/intro_tables/beta_message.html', 'templates/private/intro_tables/beta_message.html',
'version': 27, 'version': 27,
'scheduled': 28 'scheduled': 28
...@@ -396,7 +396,7 @@ class JSCViewWithNodeAvailabilityTest(unittest.TestCase): ...@@ -396,7 +396,7 @@ class JSCViewWithNodeAvailabilityTest(unittest.TestCase):
self.assertEquals({ self.assertEquals({
'scheduled': None, 'scheduled': None,
'version': 26, 'version': 26,
'partial': 'handlebar chrome/common/extensions/docs/templates/' + 'partial': 'motemplate chrome/common/extensions/docs/templates/' +
'private/intro_tables/deprecated_message.html' 'private/intro_tables/deprecated_message.html'
}, model_dict['types'][2]['availability']) }, model_dict['types'][2]['availability'])
......
...@@ -10,7 +10,7 @@ import unittest ...@@ -10,7 +10,7 @@ import unittest
from extensions_paths import CHROME_EXTENSIONS from extensions_paths import CHROME_EXTENSIONS
from permissions_data_source import PermissionsDataSource from permissions_data_source import PermissionsDataSource
from server_instance import ServerInstance from server_instance import ServerInstance
from third_party.handlebar import Handlebar from third_party.motemplate import Motemplate
from test_file_system import TestFileSystem from test_file_system import TestFileSystem
...@@ -158,13 +158,13 @@ class PermissionsDataSourceTest(unittest.TestCase): ...@@ -158,13 +158,13 @@ class PermissionsDataSourceTest(unittest.TestCase):
# - Sort keys. Since the tests don't use OrderedDicts we can't make # - Sort keys. Since the tests don't use OrderedDicts we can't make
# assertions about the order, which is unfortunate. Oh well. # assertions about the order, which is unfortunate. Oh well.
# - Render all of the Handlerbar instances so that we can use ==. # - 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, for lst in (actual_apps, actual_extensions,
expected_apps, expected_extensions): expected_apps, expected_extensions):
lst.sort(key=itemgetter('name')) lst.sort(key=itemgetter('name'))
for mapping in lst: for mapping in lst:
for key, value in mapping.iteritems(): for key, value in mapping.iteritems():
if isinstance(value, Handlebar): if isinstance(value, Motemplate):
mapping[key] = value.Render().text mapping[key] = value.Render().text
self.assertEqual(expected_extensions, actual_extensions) self.assertEqual(expected_extensions, actual_extensions)
......
...@@ -13,7 +13,7 @@ from file_system import FileNotFoundError ...@@ -13,7 +13,7 @@ from file_system import FileNotFoundError
from redirector import Redirector from redirector import Redirector
from servlet import Servlet, Response from servlet import Servlet, Response
from special_paths import SITE_VERIFICATION_FILE 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): def _MakeHeaders(content_type, etag=None):
...@@ -111,7 +111,7 @@ class RenderServlet(Servlet): ...@@ -111,7 +111,7 @@ class RenderServlet(Servlet):
logging.error('%s had empty content' % path) logging.error('%s had empty content' % path)
content = content_and_type.content content = content_and_type.content
if isinstance(content, Handlebar): if isinstance(content, Motemplate):
template_content, template_warnings = ( template_content, template_warnings = (
server_instance.template_renderer.Render(content, self._request)) server_instance.template_renderer.Render(content, self._request))
# HACK: the site verification file (google2ed...) doesn't have a title. # HACK: the site verification file (google2ed...) doesn't have a title.
......
...@@ -10,7 +10,7 @@ from extensions_paths import SERVER2 ...@@ -10,7 +10,7 @@ from extensions_paths import SERVER2
from server_instance import ServerInstance from server_instance import ServerInstance
from template_data_source import TemplateDataSource from template_data_source import TemplateDataSource
from test_util import DisableLogging, ReadFile from test_util import DisableLogging, ReadFile
from third_party.handlebar import Handlebar from third_party.motemplate import Motemplate
def _ReadFile(*path): def _ReadFile(*path):
return ReadFile(SERVER2, 'test_data', 'template_data_source', *path) return ReadFile(SERVER2, 'test_data', 'template_data_source', *path)
...@@ -38,12 +38,12 @@ class TemplateDataSourceTest(unittest.TestCase): ...@@ -38,12 +38,12 @@ class TemplateDataSourceTest(unittest.TestCase):
def testSimple(self): def testSimple(self):
test_data_source = _CreateTestDataSource('simple') test_data_source = _CreateTestDataSource('simple')
template_a1 = Handlebar(_ReadFile('simple', 'test1.html')) template_a1 = Motemplate(_ReadFile('simple', 'test1.html'))
context = [{}, {'templates': {}}] context = [{}, {'templates': {}}]
self.assertEqual( self.assertEqual(
template_a1.Render(*context).text, template_a1.Render(*context).text,
test_data_source.get('test1').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( self.assertEqual(
template_a2.Render(*context).text, template_a2.Render(*context).text,
test_data_source.get('test2').Render(*context).text) test_data_source.get('test2').Render(*context).text)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# found in the LICENSE file. # found in the LICENSE file.
from data_source_registry import CreateDataSources 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 from url_constants import GITHUB_BASE, EXTENSIONS_SAMPLES
...@@ -27,7 +27,7 @@ class TemplateRenderer(object): ...@@ -27,7 +27,7 @@ class TemplateRenderer(object):
Specify |additional_context| to inject additional template context when Specify |additional_context| to inject additional template context when
rendering the template. rendering the template.
''' '''
assert isinstance(template, Handlebar), type(template) assert isinstance(template, Motemplate), type(template)
render_context = CreateDataSources(self._server_instance, request) render_context = CreateDataSources(self._server_instance, request)
if data_sources is not None: if data_sources is not None:
render_context = dict((name, d) for name, d in render_context.iteritems() render_context = dict((name, d) for name, d in render_context.iteritems()
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
import unittest import unittest
from server_instance import ServerInstance from server_instance import ServerInstance
from third_party.handlebar import Handlebar from third_party.motemplate import Motemplate
class TemplateRendererTest(unittest.TestCase): class TemplateRendererTest(unittest.TestCase):
...@@ -20,7 +20,7 @@ class TemplateRendererTest(unittest.TestCase): ...@@ -20,7 +20,7 @@ class TemplateRendererTest(unittest.TestCase):
self._template_renderer = ServerInstance.ForLocal().template_renderer self._template_renderer = ServerInstance.ForLocal().template_renderer
def testSimpleWiring(self): def testSimpleWiring(self):
template = Handlebar('hello {{?true}}{{strings.extension}}{{/}}') template = Motemplate('hello {{?true}}{{strings.extension}}{{/}}')
text, warnings = self._template_renderer.Render(template, None) text, warnings = self._template_renderer.Render(template, None)
self.assertEqual('hello extension', text) self.assertEqual('hello extension', text)
self.assertEqual([], warnings) self.assertEqual([], warnings)
......
Name: Handlebar, cross-platform data binding templates. Name: Motemplate, cross-platform data binding templates.
Short Name: handlebar Short Name: motemplate
URL: https://github.com/kalman/templates URL: https://github.com/kalman/templates
Version: 0 Version: 0
Date: November 16, 2013 Date: August 22, 2014
Revision: commit 3e74633948a386d0a77a1c2b1df4c40546f4ec95 Revision: commit 76237c8ece0272dc02d104eef24b66365b4feaf3
License: Apache 2.0 License: Apache 2.0
License File: NOT_SHIPPED License File: NOT_SHIPPED
Security Critical: no Security Critical: no
......
...@@ -12,18 +12,17 @@ ...@@ -12,18 +12,17 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# TODO: New name, not "handlebar".
# TODO: Escaping control characters somehow. e.g. \{{, \{{-. # TODO: Escaping control characters somehow. e.g. \{{, \{{-.
import json import json
import re 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: ctemplate. Use like:
from handlebar import Handlebar from motemplate import Motemplate
template = Handlebar('hello {{#foo bar/}} world') template = Motemplate('hello {{#foo bar/}} world')
input = { input = {
'foo': [ 'foo': [
{ 'bar': 1 }, { 'bar': 1 },
...@@ -33,14 +32,14 @@ ctemplate. Use like: ...@@ -33,14 +32,14 @@ ctemplate. Use like:
} }
print(template.render(input).text) 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 getters (for example, something that populates values lazily from keys), just
provide an object with a get() method. provide an object with a get() method.
class CustomContext(object): class CustomContext(object):
def get(self, key): def get(self, key):
return 10 return 10
print(Handlebar('hello {{world}}').render(CustomContext()).text) print(Motemplate('hello {{world}}').render(CustomContext()).text)
will print 'hello 10'. will print 'hello 10'.
''' '''
...@@ -648,11 +647,9 @@ class _JsonNode(_LeafNode): ...@@ -648,11 +647,9 @@ class _JsonNode(_LeafNode):
def __repr__(self): def __repr__(self):
return '{{*%s}}' % self._id return '{{*%s}}' % self._id
# TODO: Better common model of _PartialNodeWithArguments, _PartialNodeInContext,
# and _PartialNode.
class _PartialNodeWithArguments(_DecoratorNode): class _PartialNodeWithArguments(_DecoratorNode):
def __init__(self, partial, args): def __init__(self, partial, args):
if isinstance(partial, Handlebar): if isinstance(partial, Motemplate):
# Preserve any get() method that the caller has added. # Preserve any get() method that the caller has added.
if hasattr(partial, 'get'): if hasattr(partial, 'get'):
self.get = partial.get self.get = partial.get
...@@ -666,7 +663,7 @@ class _PartialNodeWithArguments(_DecoratorNode): ...@@ -666,7 +663,7 @@ class _PartialNodeWithArguments(_DecoratorNode):
class _PartialNodeInContext(_DecoratorNode): class _PartialNodeInContext(_DecoratorNode):
def __init__(self, partial, context): def __init__(self, partial, context):
if isinstance(partial, Handlebar): if isinstance(partial, Motemplate):
# Preserve any get() method that the caller has added. # Preserve any get() method that the caller has added.
if hasattr(partial, 'get'): if hasattr(partial, 'get'):
self.get = partial.get self.get = partial.get
...@@ -707,11 +704,11 @@ class _PartialNode(_LeafNode): ...@@ -707,11 +704,11 @@ class _PartialNode(_LeafNode):
if value is None: if value is None:
render_state.AddResolutionError(self._id) render_state.AddResolutionError(self._id)
return return
if not isinstance(value, (Handlebar, _Node)): if not isinstance(value, (Motemplate, _Node)):
render_state.AddResolutionError(self._id, description='not a partial') render_state.AddResolutionError(self._id, description='not a partial')
return return
if isinstance(value, Handlebar): if isinstance(value, Motemplate):
node, name = value._top_node, value._name node, name = value._top_node, value._name
else: else:
node, name = value, None node, name = value, None
...@@ -912,8 +909,8 @@ class _TokenStream(object): ...@@ -912,8 +909,8 @@ class _TokenStream(object):
def __str__(self): def __str__(self):
return repr(self) return repr(self)
class Handlebar(object): class Motemplate(object):
'''A handlebar template. '''A motemplate template.
''' '''
def __init__(self, template, name=None): def __init__(self, template, name=None):
self.source = template self.source = template
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment