Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Cheetah macros without source body #1

Closed
wants to merge 5 commits into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 13, 2012
  1. @Roguelazer

    Merge pull request #10 from bukzor/master

    Roguelazer authored
    None and empty-string are legitimate values to return from a function
Commits on Jul 14, 2012
  1. @Roguelazer

    Merge pull request #11 from bukzor/master

    Roguelazer authored
    restore compatibility with 2.4.5
Commits on Jul 27, 2012
  1. @asottile
  2. @asottile
  3. @asottile

    Comment fix.

    asottile authored
This page is out of date. Refresh to see the latest.
Showing with 75 additions and 0 deletions.
  1. +7 −0 cheetah/Parser.py
  2. +68 −0 cheetah/Tests/SyntaxAndOutput.py
View
7 cheetah/Parser.py
@@ -2325,6 +2325,8 @@ def eatMacroCall(self):
args = self.getExpression(useNameMapper=False,
pyTokensToBreakAt=[':']).strip()
+ # define the property emptySourceBlock on your macro in order to have it parsed as a macro without contents
+ # In this case, the macro will only pick up arguments just as before
if self.matchColonForSingleLineShortFormDirective():
isShortForm = True
self.advance() # skip over :
@@ -2332,6 +2334,11 @@ def eatMacroCall(self):
srcBlock = self.readToEOL(gobble=False)
EOLCharsInShortForm = self.readToEOL(gobble=True)
#self.readToEOL(gobble=False)
+ elif getattr(macro, 'emptySourceBlock', False):
+ isShortForm = True
+ srcBlock = ''
+ self.readToEOL(gobble=False)
+ EOLCharsInShortForm = self.readToEOL(gobble=True)
else:
isShortForm = False
if self.peek()==':':
View
68 cheetah/Tests/SyntaxAndOutput.py
@@ -3107,6 +3107,74 @@ def test1(self):
"0123456789")
+class MacroEmptySourceBlock(OutputTest):
+ """Tests that emptySourceBlock property on macro is parsed correctly."""
+
+ class TestMacroNoArgs(object):
+ """
+ Define a macro which does not take parameters but has an empty source block
+ """
+
+ emptySourceBlock = True
+
+ def __init__(self, parser): pass
+ def __call__(self, src, **kwargs): return 'TestMacroNoArgs'
+
+ class TestMacroTakesArgs(object):
+ """
+ Define a macro which takes parameters and spits them back out and has an empty source block
+ """
+
+ emptySourceBlock = True
+
+ def __init__(self, parser): pass
+ def __call__(self, src, customParam=None, **kwargs): return customParam
+ def convertArgStrToDict(self, argumentString, **kwargs):
+ return {'customParam': argumentString}
+
+ class TestMacroNotEmptySourceBlock(object):
+ """
+ Define a macro that requires the end block by having emptySourceBlock = False
+ """
+
+ emptySourceBlock = False
+
+ def __init__(self, parser): pass
+ def __call__(self, src, **kwargs): return 'TestMacroNotEmptySourceBlock'
+
+
+ def _getCompilerSettings(self):
+ return {'macroDirectives': {
+ 'TestMacroNoArgs': self.TestMacroNoArgs ,
+ 'TestMacroTakesArgs': self.TestMacroTakesArgs,
+ 'TestMacroNotEmptySourceBlock': self.TestMacroNotEmptySourceBlock
+ }}
+
+ def test1(self):
+ """Test that a macro with no args is processed correctly."""
+
+ self.verify("""\
+#TestMacroNoArgs
+""",
+ 'TestMacroNoArgs')
+
+ def test2(self):
+ """Test that a macro with args is processed correctly."""
+
+ self.verify("""\
+#TestMacroTakesArgs arguments, passed
+""",
+ 'arguments, passed')
+
+ def test3(self):
+ """Test that a macro with emptySourceBlock = False requires end macro."""
+
+ self.verify("""\
+#TestMacroNotEmptySourceBlock
+herp
+#end TestMacroNotEmptySourceBlock
+""",
+ 'TestMacroNotEmptySourceBlock')
class DefmacroDirective(OutputTest):
def _getCompilerSettings(self):
Something went wrong with that request. Please try again.