def parse(self, parser):
lineno = next(parser.stream).lineno
next_token = parser.stream.look()
# if there are parameters
if next_token.type == "comma":
args = [parser.parse_expression()]
if parser.stream.skip_if('comma'):
args.append(parser.parse_expression())
else:
raise TemplateSyntaxError("Missing Lorem Ipsum generator parameter: kind", lineno)
if args[1].value not in self.GENERATORS:
raise TemplateSyntaxError(
"Supported Lorem Ipsum generator kinds are: %s" % ", ".join(self.GENERATORS.keys()),
lineno
)
else:
# if no parameters were supplied
args = [nodes.Const(1), nodes.Const("paragraphs")]
return nodes.Output(
[self.call_method("_lipsum", args)],
lineno=lineno
)
评论列表
文章目录