From 317554aff398a823beae63fa09a6014ee1508f4b Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 2 Mar 2015 15:31:53 +0100 Subject: [PATCH] fix(mako): unify generated constants like library-name. That way, they are always the same, even if I change my mind. Good coding style is easy, using the current setup. --- src/mako/README.md.mako | 4 ++-- src/mako/cargo.toml.mako | 4 ++-- src/mako/lib/util.mako | 6 +++++- src/mako/lib/util.py | 4 ++++ 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/mako/README.md.mako b/src/mako/README.md.mako index 4b4fe66bcf..13a0251d47 100644 --- a/src/mako/README.md.mako +++ b/src/mako/README.md.mako @@ -1,6 +1,6 @@ -<%! import util %>\ <%namespace name="lib" file="lib/lib.mako"/>\ -The `${util.library_name(name, version)}` library allows access to all features of *${canonicalName}*. +<%namespace name="util" file="lib/util.mako"/>\ +The `${util.library_name()}` library allows access to all features of *${canonicalName}*. <%lib:docs /> <%lib:license /> \ No newline at end of file diff --git a/src/mako/cargo.toml.mako b/src/mako/cargo.toml.mako index 055d73f033..0b81485440 100644 --- a/src/mako/cargo.toml.mako +++ b/src/mako/cargo.toml.mako @@ -5,7 +5,7 @@ # DO NOT EDIT ! [package] -name = "${name}${util.to_api_version(version)}" +name = "${mutil.library_name()}" version = "${cargo.build_version}" authors = [${",\n ".join('"%s"' % a for a in cargo.authors)}] description = "A complete library to interact with ${canonicalName} (protocol ${version})" @@ -13,7 +13,7 @@ repository = "${mutil.repository_url()}" homepage = "${documentationLink}" documentation = "${cargo.doc_base_url}" license = "${copyright.license_abbrev}" -keywords = ["${name}", ${", ".join('"%s"' % k for k in cargo.keywords)}] +keywords = ["${name}", ${", ".join(util.estr(cargo.keywords))}] [dependencies] # Just to get hyper to work ! diff --git a/src/mako/lib/util.mako b/src/mako/lib/util.mako index 8b0d22c207..49cce71ddf 100644 --- a/src/mako/lib/util.mako +++ b/src/mako/lib/util.mako @@ -1,4 +1,4 @@ - +<%! import util %>\ ## This will only work within a substitution, not within python code @@ -10,4 +10,8 @@ ${v[1:]}\ <%def name="repository_url()">\ ${cargo.repo_base_url}/${OUTPUT_DIR}\ + + +<%def name="library_name()">\ +${util.library_name(name, version)}\ \ No newline at end of file diff --git a/src/mako/lib/util.py b/src/mako/lib/util.py index 70090c4082..9466840016 100644 --- a/src/mako/lib/util.py +++ b/src/mako/lib/util.py @@ -20,6 +20,10 @@ def put_and(l): return l[0] return ', '.join(l[:-1]) + ' and ' + l[-1] +# escape each string in l with "s" and return the new list +def estr(l): + return ["%s" % i for i in l] + # build a full library name (non-canonical) def library_name(name, version): return name + to_api_version(version)