summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2005-08-19 20:29:35 +0000
committerFred Drake <fdrake@acm.org>2005-08-19 20:29:35 +0000
commit5206c838f3c53c881cb0becab6a600206bd23eab (patch)
tree4edda908c64ec9799acc9a557027c0cbebcc64e7
parent9582f358f9cf0fa234f428346fe8bfe79f42c15f (diff)
downloadzope-tal-5206c838f3c53c881cb0becab6a600206bd23eab.tar.gz
"surface" portion of the move to METAL 1.1: macro extension requires the
extend-macro attribute instead of use-macro, and cannot be combined with use-macro
-rw-r--r--taldefs.py1
-rw-r--r--talgenerator.py18
-rw-r--r--tests/input/acme_template.pt2
-rw-r--r--tests/input/test_metal9.html2
-rw-r--r--tests/test_htmltalparser.py12
5 files changed, 31 insertions, 4 deletions
diff --git a/taldefs.py b/taldefs.py
index 9668ab1..591a8c8 100644
--- a/taldefs.py
+++ b/taldefs.py
@@ -36,6 +36,7 @@ NAME_RE = "[a-zA-Z_][-a-zA-Z0-9_]*"
# TODO: In Python 2.4 we can use frozenset() instead of dict.fromkeys()
KNOWN_METAL_ATTRIBUTES = dict.fromkeys([
"define-macro",
+ "extend-macro",
"use-macro",
"define-slot",
"fill-slot",
diff --git a/talgenerator.py b/talgenerator.py
index 203c68d..03819bc 100644
--- a/talgenerator.py
+++ b/talgenerator.py
@@ -508,6 +508,7 @@ class TALGenerator(object):
todo = {}
defineMacro = metaldict.get("define-macro")
+ extendMacro = metaldict.get("extend-macro")
useMacro = metaldict.get("use-macro")
defineSlot = metaldict.get("define-slot")
fillSlot = metaldict.get("fill-slot")
@@ -537,11 +538,24 @@ class TALGenerator(object):
raise I18NError("i18n:data must be accompanied by i18n:translate",
position)
- if defineMacro or useMacro:
+ if extendMacro:
+ if useMacro:
+ raise METALError(
+ "extend-macro cannot be used with use-macro", position)
+ if not defineMacro:
+ raise METALError(
+ "extend-macro must be used with define-macro", position)
+
+ if defineMacro or extendMacro or useMacro:
if fillSlot or defineSlot:
raise METALError(
"define-slot and fill-slot cannot be used with "
- "define-macro or use-macro", position)
+ "define-macro, extend-macro, or use-macro", position)
+ if defineMacro and useMacro:
+ raise METALError(
+ "define-macro may not be used with use-macro", position)
+
+ useMacro = useMacro or extendMacro
if content and msgid:
raise I18NError(
diff --git a/tests/input/acme_template.pt b/tests/input/acme_template.pt
index 35d88e3..0af01ba 100644
--- a/tests/input/acme_template.pt
+++ b/tests/input/acme_template.pt
@@ -1,6 +1,6 @@
<!-- This is ACME's generic look and feel, which is based on
PNOME's look and feel. -->
-<html metal:use-macro="pnome_macros_page" metal:define-macro="page">
+<html metal:extend-macro="pnome_macros_page" metal:define-macro="page">
<head>
<title metal:fill-slot="title">ACME Look and Feel</title>
</head>
diff --git a/tests/input/test_metal9.html b/tests/input/test_metal9.html
index f8ac37e..46b1b45 100644
--- a/tests/input/test_metal9.html
+++ b/tests/input/test_metal9.html
@@ -4,7 +4,7 @@ Default for macro1
</span>
</div>
-<div metal:define-macro="macro2" metal:use-macro="macro1" i18n:domain="zope">
+<div metal:define-macro="macro2" metal:extend-macro="macro1" i18n:domain="zope">
<span metal:fill-slot="slot1">
Macro 2's slot 1 decoration
<span metal:define-slot="slot1">
diff --git a/tests/test_htmltalparser.py b/tests/test_htmltalparser.py
index 40cea3a..eb53f51 100644
--- a/tests/test_htmltalparser.py
+++ b/tests/test_htmltalparser.py
@@ -557,6 +557,18 @@ class TALGeneratorTestCases(TestCaseBase):
self._should_error("<p metal:foobar='x' />", exc)
self._should_error("<p metal:define-macro='x'>", exc)
+ def test_extend_macro_errors(self):
+ exc = taldefs.METALError
+ # extend-macro requires define-macro:
+ self._should_error("<p metal:extend-macro='x'>xxx</p>", exc)
+ # extend-macro prevents use-macro:
+ self._should_error("<p metal:extend-macro='x'"
+ " metal:use-macro='x'"
+ " metal:define-macro='y'>xxx</p>", exc)
+ # use-macro doesn't co-exist with define-macro:
+ self._should_error("<p metal:use-macro='x'"
+ " metal:define-macro='y'>xxx</p>", exc)
+
#
# I18N test cases
#