private void run(String testName, bool pretty, JadeModel model) { JadeParser parser = null; try { FileTemplateLoader loader = new FileTemplateLoader(TestFileHelper.getCompilerErrorsResourcePath(""), "UTF-8"); parser = new JadeParser(testName, loader); } catch (IOException e) { Trace.WriteLine(e); } Node root = parser.parse(); Jade.Compiler.Compiler compiler = new Jade.Compiler.Compiler(root); compiler.setPrettyPrint(pretty); String expected = readFile(testName + ".html"); model.addFilter("markdown", new MarkdownFilter()); model.addFilter("plain", new PlainFilter()); String html; try { html = compiler.compileToString(model); Assert.AreEqual(expected.Trim(), html.Trim(), testName); Assert.Fail(); } catch (JadeCompilerException e) { Trace.WriteLine(e); } }
protected void loadInParser(String fileName) { try { FileTemplateLoader loader = new FileTemplateLoader( TestFileHelper.getParserResourcePath(""), "UTF-8"); parser = new JadeParser(fileName, loader); } catch (IOException e) { Trace.WriteLine(e); Assert.Fail("template " + fileName + " was not found"); } root = parser.parse(); }
private Node parseInclude() { Token token = expect(typeof(Include)); Include includeToken = (Include)token; String templateName = includeToken.getValue().Trim(); String extension = Path.GetExtension(templateName); if (!"".Equals(extension) && !"jade".Equals(extension)) { FilterNode node = new FilterNode(); node.setLineNumber(_jadeLexer.getLineno()); node.setFileName(filename); node.setValue(extension); try { TextReader reader = templateLoader.getReader(resolvePath(templateName)); Node textNode = new TextNode(); textNode.setFileName(filename); textNode.setLineNumber(_jadeLexer.getLineno()); textNode.setValue(reader.ReadToEnd()); node.setTextBlock(textNode); } catch (IOException e) { throw new JadeParserException(filename, _jadeLexer.getLineno(), templateLoader, "the included file [" + templateName + "] could not be opened\n" + e.Message); } return(node); } JadeParser jadeParser = createParser(templateName); jadeParser.setBlocks(blocks); contexts.AddLast(jadeParser); Node ast = jadeParser.parse(); contexts.RemoveLast(); if (peek() is Indent && ast is BlockNode) { ((BlockNode)ast).getIncludeBlock().push(block()); } return(ast); }
private Node parseExtends() { Token token = expect(typeof(ExtendsToken)) ; ExtendsToken extendsToken = (ExtendsToken)token; String templateName = extendsToken.getValue().Trim(); JadeParser jadeParser = createParser(templateName); jadeParser.setBlocks(blocks); jadeParser.setContexts(contexts); extending = jadeParser; LiteralNode node = new LiteralNode(); node.setValue(""); return(node); }
private Node parseExtends() { Token token = expect(typeof (ExtendsToken)) ; ExtendsToken extendsToken = (ExtendsToken) token; String templateName = extendsToken.getValue().Trim(); JadeParser jadeParser = createParser(templateName); jadeParser.setBlocks(blocks); jadeParser.setContexts(contexts); extending = jadeParser; LiteralNode node = new LiteralNode(); node.setValue(""); return node; }
// throws IOException private static JadeTemplate createTemplate(String filename, TemplateLoader loader) { JadeParser jadeParser = new JadeParser(filename, loader); Node root = jadeParser.parse(); JadeTemplate template = new JadeTemplate(); template.setTemplateLoader(loader); template.setRootNode(root); return template; }
//throws JadeException, IOException private JadeTemplate createTemplate(String name) { JadeTemplate template = new JadeTemplate(); JadeParser parser = new JadeParser(name, templateLoader); Node root = parser.parse(); template.setTemplateLoader(templateLoader); template.setRootNode(root); template.setPrettyPrint(prettyPrint); template.setMode(getMode()); return template; }