Пример #1
0
        //throws JadeCompilerException
        public override void execute(IndentWriter writer, JadeModel model, JadeTemplate template)
        {
            try
            {
                Object result = ExpressionHandler.evaluateStringExpression(getValue(), model);
                if (result == null || !buffer)
                {
                    return;
                }
                String str = result.ToString();
                if (escape)
                {
                    str = Utils.escapeHTML(str);
                }
                writer.append(str);

                if (hasBlock())
                {
                    writer.increment();
                    block.execute(writer, model, template);
                    writer.decrement();
                    writer.newline();
                }

            }
            catch (ExpressionException e)
            {
                throw new JadeCompilerException(this, template.getTemplateLoader(), e);
            }
        }
Пример #2
0
        public void testEachLoopWithIterableMap()
        {
            Dictionary <string, string> users = new Dictionary <string, string>();

            users.Add("bob", "Robert Smith");
            users.Add("alex", "Alex Supertramp");

            Dictionary <String, Object> root = new Dictionary <String, Object>();

            root.Add("users", users);
            JadeModel model = new JadeModel(root);

            JadeTemplate temp = cfg.getTemplate(getResourcePath("each_loop"));

            StringWriter outStream = new StringWriter();

            try
            {
                temp.process(model, outStream);
            }
            catch (JadeCompilerException e)
            {
                Trace.WriteLine(e);
                Assert.Fail();
            }
            outStream.Flush();
            Assert.AreEqual("<ul><li>Robert Smith</li><li>Alex Supertramp</li></ul>", outStream.ToString());
        }
Пример #3
0
        //throws JadeCompilerException
        public override void execute(IndentWriter writer, JadeModel model, JadeTemplate template)
        {
            String name = getValue();
            if (name == null)
            {
                name = "5";
            }
            String doctypeLine = Doctypes.get(name);
            if (doctypeLine == null)
            {
                doctypeLine = "<!DOCTYPE " + name + ">";
            }

            if (doctypeLine.StartsWith("<?xml"))
            {
                template.setMode(Jade4Net.Mode.XML);
            }
            else if (doctypeLine.Equals("<!DOCTYPE html>"))
            {
                template.setMode(Jade4Net.Mode.HTML);
            }
            else
            {
                template.setMode(Jade4Net.Mode.XHTML);
            }

            writer.append(doctypeLine);
        }
Пример #4
0
        // throws JadeCompilerException
        public override void execute(IndentWriter writer, JadeModel model, JadeTemplate template)
        {
            MixinNode mixin = model.getMixin(getName());
            if (mixin == null)
            {
                throw new JadeCompilerException(this, template.getTemplateLoader(), "mixin " + getName() + " is not defined");
            }

            // Clone mixin
            try
            {
                mixin = (MixinNode)mixin.Clone();
            }
            catch (Exception e)
            {
                // Can't happen
                throw;
            }

            if (hasBlock())
            {
                List<BlockNode> injectionPoints = getInjectionPoints(mixin.getBlock());
                foreach (BlockNode point in injectionPoints)
                {
                    point.getNodes().AddLast(block);
                }
            }

            model.pushScope();
            model.put("block", hasBlock());
            writeVariables(model, mixin, template);
            writeAttributes(model, mixin, template);
            mixin.getBlock().execute(writer, model, template);
            model.popScope();
        }
Пример #5
0
 public void process(JadeModel model, TextWriter writer)
 {
     Compiler.Compiler compiler = new Compiler.Compiler(rootNode);
     compiler.setPrettyPrint(prettyPrint);
     compiler.setTemplate(this);
     compiler.compile(model, writer);
 }
Пример #6
0
        public static string interpolate(List <Object> prepared, JadeModel model)
        {
            StringBuilder result = new StringBuilder();

            foreach (Object entry in prepared)
            {
                if (entry is String)
                {
                    result.Append(entry);
                }
                else if (entry is ExpressionString)
                {
                    ExpressionString expression  = (ExpressionString)entry;
                    string           stringValue = "";
                    string           value       = ExpressionHandler.evaluateStringExpression(expression.getValue(), model);
                    if (value != null)
                    {
                        stringValue = value;
                    }
                    if (expression.isEscape())
                    {
                        stringValue = escapeHTML(stringValue);
                    }
                    result.Append(stringValue);
                }
            }

            return(result.ToString());
        }
Пример #7
0
 public JadeModelTest()
 {
     var map = new Dictionary<string, object>();
     map.Add("hello", "world");
     map.Add("foo", "bar");
     model = new JadeModel(map);
 }
Пример #8
0
        public override void execute(IndentWriter writer, JadeModel model, JadeTemplate template) //throws JadeCompilerException
        {
            try
            {
                Object result = ExpressionHandler.evaluateStringExpression(getValue(), model);
                if (result == null || !buffer)
                {
                    return;
                }
                String str = result.ToString();
                if (escape)
                {
                    str = Utils.escapeHTML(str);
                }
                writer.append(str);

                if (hasBlock())
                {
                    writer.increment();
                    block.execute(writer, model, template);
                    writer.decrement();
                    writer.newline();
                }
            }
            catch (ExpressionException e)
            {
                throw new JadeCompilerException(this, template.getTemplateLoader(), e);
            }
        }
        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);
            }
        }
Пример #10
0
 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);
     }
 }
Пример #11
0
        public void compile(JadeModel model, TextWriter w)
        {
            IndentWriter writer = new IndentWriter(w);

            writer.setUseIndent(prettyPrint);
            rootNode.execute(writer, model, template);
        }
Пример #12
0
        public String compileToString(JadeModel model)
        {
            StringWriter writer = new StringWriter();

            compile(model, writer);
            return(writer.ToString());
        }
Пример #13
0
        private void writeVariables(JadeModel model, MixinNode mixin, JadeTemplate template)
        {
            List <String> names  = mixin.getArguments();
            List <String> values = arguments;

            if (names == null)
            {
                return;
            }
            for (int i = 0; i < names.Count; i++)
            {
                String key   = names[i];
                Object value = null;
                if (i < values.Count)
                {
                    value = values[i];
                }
                if (value != null)
                {
                    try
                    {
                        value = ExpressionHandler.evaluateExpression(values[i], model);
                    }
                    catch (Exception e)
                    {
                        throw new JadeCompilerException(this, template.getTemplateLoader(), e);
                    }
                }
                if (key != null)
                {
                    model.put(key, value);
                }
            }
        }
Пример #14
0
 private void executeElseNode(JadeModel model, IndentWriter writer, JadeTemplate template)
 {
     if (elseNode != null)
     {
         elseNode.execute(writer, model, template);
     }
 }
Пример #15
0
 private void executeElseNode(JadeModel model, IndentWriter writer, JadeTemplate template)
 {
     if (elseNode != null)
     {
         elseNode.execute(writer, model, template);
     }
 }
Пример #16
0
        public override void execute(IndentWriter writer, JadeModel model, JadeTemplate template)
        //throws JadeCompilerException
        {
            String name = getValue();

            if (name == null)
            {
                name = "5";
            }
            String doctypeLine = Doctypes.get(name);

            if (doctypeLine == null)
            {
                doctypeLine = "<!DOCTYPE " + name + ">";
            }

            if (doctypeLine.StartsWith("<?xml"))
            {
                template.setMode(Jade4Net.Mode.XML);
            }
            else if (doctypeLine.Equals("<!DOCTYPE html>"))
            {
                template.setMode(Jade4Net.Mode.HTML);
            }
            else
            {
                template.setMode(Jade4Net.Mode.XHTML);
            }

            writer.append(doctypeLine);
        }
Пример #17
0
 //throws JadeCompilerException
 public override void execute(IndentWriter writer, JadeModel model, JadeTemplate template)
 {
     foreach (Node node in getNodes())
     {
         node.execute(writer, model, template);
     }
 }
Пример #18
0
        public static string interpolate(List<Object> prepared, JadeModel model)
        {
            StringBuilder result = new StringBuilder();

            foreach (Object entry in prepared)
            {
                if (entry is String)
                {
                    result.Append(entry);
                }
                else if (entry is ExpressionString)
                {
                    ExpressionString expression = (ExpressionString) entry;
                    string stringValue = "";
                    string value = ExpressionHandler.evaluateStringExpression(expression.getValue(), model);
                    if (value != null)
                    {
                        stringValue = value;
                    }
                    if (expression.isEscape())
                    {
                        stringValue = escapeHTML(stringValue);
                    }
                    result.Append(stringValue);
                }
            }

            return result.ToString();
        }
Пример #19
0
 public override void execute(IndentWriter writer, JadeModel model, JadeTemplate template)
 //throws JadeCompilerException
 {
     foreach (Node node in getNodes())
     {
         node.execute(writer, model, template);
     }
 }
Пример #20
0
        public JadeModelTest()
        {
            var map = new Dictionary <string, object>();

            map.Add("hello", "world");
            map.Add("foo", "bar");
            model = new JadeModel(map);
        }
Пример #21
0
        private static String templateToString(JadeTemplate template, Dictionary <String, Object> model)
        // throws JadeCompilerException
        {
            JadeModel    jadeModel = new JadeModel(model);
            StringWriter writer    = new StringWriter();

            template.process(jadeModel, writer);
            return(writer.ToString());
        }
Пример #22
0
 public override void execute(IndentWriter writer, JadeModel model, JadeTemplate template)// throws JadeCompilerException
 {
     if (!isBuffered())
     {
         return;
     }
     writer.newline();
     writer.append("<!--");
     writer.append(value);
     writer.append("-->");
 }
Пример #23
0
        private Object evaluateExpression(ExpressionString attribute, JadeModel model) //throws ExpressionException
        {
            String expression = ((ExpressionString)attribute).getValue();
            Object result     = ExpressionHandler.evaluateExpression(expression, model);

            if (result is ExpressionString)
            {
                return(evaluateExpression((ExpressionString)result, model));
            }
            return(result);
        }
Пример #24
0
        public void renderTemplate(JadeTemplate template, Dictionary <String, Object> model, TextWriter writer)
        //throws JadeCompilerException
        {
            JadeModel jadeModel = new JadeModel(sharedVariables);

            foreach (String filterName in filters.Keys)
            {
                jadeModel.addFilter(filterName, filters[filterName]);
            }
            jadeModel.putAll(model);
            template.process(jadeModel, writer);
        }
Пример #25
0
        public void Test()
        {
            var defaults = new Dictionary<string, object>();
            defaults.Add("hello", "world");

            model = new JadeModel(defaults);
            model.put("new", true);

            Assert.IsFalse(defaults.ContainsKey("new"));
            Assert.IsTrue(model.ContainsKey("new"));
            Assert.AreEqual(model.get("hello"), "world");
        }
Пример #26
0
 public override void execute(IndentWriter writer, JadeModel model, JadeTemplate template)
 //throws JadeCompilerException
 {
     if (hasBlock())
     {
         model.setMixin(getName(), this);
     }
     else
     {
         base.execute(writer, model, template);
     }
 }
Пример #27
0
 //throws JadeCompilerException
 public override void execute(IndentWriter writer, JadeModel model, JadeTemplate template)
 {
     Object result;
     try
     {
         result = ExpressionHandler.evaluateExpression(value, model);
     }
     catch (ExpressionException e)
     {
         throw new JadeCompilerException(this, template.getTemplateLoader(), e);
     }
     model.put(name, result);
 }
Пример #28
0
        public void Test()
        {
            var defaults = new Dictionary <string, object>();

            defaults.Add("hello", "world");

            model = new JadeModel(defaults);
            model.put("new", true);

            Assert.IsFalse(defaults.ContainsKey("new"));
            Assert.IsTrue(model.ContainsKey("new"));
            Assert.AreEqual(model.get("hello"), "world");
        }
Пример #29
0
 public static Object evaluateExpression(String expression, JadeModel model)
 {
     try
     {
         return expression;
         Lexer.Tokens.Expression e = jexl.createExpression(expression);
         return null;// e.evaluate(new MapContext(model));
     }
     catch (Exception)
     {
         throw;// new ExpressionException(expression, e);
     }
 }
Пример #30
0
 public override void execute(IndentWriter writer, JadeModel model, JadeTemplate template)
 //throws JadeCompilerException
 {
     try
     {
         String str = Utils.interpolate(preparedValue, model);
         writer.append(str);
     }
     catch (ExpressionException e)
     {
         throw new JadeCompilerException(this, template.getTemplateLoader(), e);
     }
 }
Пример #31
0
 private void run(IndentWriter writer, JadeModel model, Object result, JadeTemplate template)
 {
     if (result is IEnumerable) {
         runIterator(((IEnumerable) result).GetEnumerator(), model, writer, template);
     } else if (result.GetType().IsArray)
     {
         var iterator = ((IEnumerable)result).GetEnumerator();
         runIterator(iterator, model, writer, template);
     }
     else if (result is Dictionary<String, Object>) {
         runMap((Dictionary<String, Object>)result, model, writer, template);
     }
 }
Пример #32
0
 public void beanPropertyCondition()
 {
     Dictionary<String, Object> map = new Dictionary<String, Object>();
     map.Add("bean", getTestBean("beanie"));
     List<TestBean> moreBeans = new List<TestBean>();
     for (int i = 0; i < 5; i++)
     {
         moreBeans.Add(getTestBean("x"));
     }
     map.Add("beans", moreBeans);
     JadeModel model = new JadeModel(map);
     run("bean_property_condition", false, model);
 }
Пример #33
0
        public static Object evaluateExpression(String expression, JadeModel model)
        {
            try
            {
                return(expression);

                Lexer.Tokens.Expression e = jexl.createExpression(expression);
                return(null);// e.evaluate(new MapContext(model));
            }
            catch (Exception)
            {
                throw;// new ExpressionException(expression, e);
            }
        }
Пример #34
0
        public override void execute(IndentWriter writer, JadeModel model, JadeTemplate template)
        //throws JadeCompilerException
        {
            Object result;

            try
            {
                result = ExpressionHandler.evaluateExpression(value, model);
            }
            catch (ExpressionException e)
            {
                throw new JadeCompilerException(this, template.getTemplateLoader(), e);
            }
            model.put(name, result);
        }
Пример #35
0
 private void run(IndentWriter writer, JadeModel model, Object result, JadeTemplate template)
 {
     if (result is IEnumerable)
     {
         runIterator(((IEnumerable)result).GetEnumerator(), model, writer, template);
     }
     else if (result.GetType().IsArray)
     {
         var iterator = ((IEnumerable)result).GetEnumerator();
         runIterator(iterator, model, writer, template);
     }
     else if (result is Dictionary <String, Object> )
     {
         runMap((Dictionary <String, Object>)result, model, writer, template);
     }
 }
Пример #36
0
        private void runMap(Dictionary <String, Object> result, JadeModel model, IndentWriter writer, JadeTemplate template)
        {
            var keys = result.Keys;

            if (keys.Count == 0)
            {
                executeElseNode(model, writer, template);
                return;
            }
            foreach (String key in keys)
            {
                model.put(getValue(), result[key]);
                model.put(getKey(), key);
                getBlock().execute(writer, model, template);
            }
        }
Пример #37
0
 //throws JadeCompilerException
 public override void execute(IndentWriter writer, JadeModel model, JadeTemplate template)
 {
     try
     {
         model.pushScope();
         while (ExpressionHandler.evaluateBooleanExpression(value, model).Value)
         {
             block.execute(writer, model, template);
         }
         model.popScope();
     }
     catch (ExpressionException e)
     {
         throw new JadeCompilerException(this, template.getTemplateLoader(), e);
     }
 }
Пример #38
0
        public void beanPropertyCondition()
        {
            Dictionary <String, Object> map = new Dictionary <String, Object>();

            map.Add("bean", getTestBean("beanie"));
            List <TestBean> moreBeans = new List <TestBean>();

            for (int i = 0; i < 5; i++)
            {
                moreBeans.Add(getTestBean("x"));
            }
            map.Add("beans", moreBeans);
            JadeModel model = new JadeModel(map);

            run("bean_property_condition", false, model);
        }
Пример #39
0
 public override void execute(IndentWriter writer, JadeModel model, JadeTemplate template)
 //throws JadeCompilerException
 {
     try
     {
         model.pushScope();
         while (ExpressionHandler.evaluateBooleanExpression(value, model).Value)
         {
             block.execute(writer, model, template);
         }
         model.popScope();
     }
     catch (ExpressionException e)
     {
         throw new JadeCompilerException(this, template.getTemplateLoader(), e);
     }
 }
Пример #40
0
        private void runIterator(IEnumerator iterator, JadeModel model, IndentWriter writer, JadeTemplate template)
        {
            int index = 0;

            if (!iterator.MoveNext())
            {
                executeElseNode(model, writer, template);
                return;
            }

            while (iterator.MoveNext())
            {
                model.put(getValue(), iterator.Current);
                model.put(getKey(), index);
                getBlock().execute(writer, model, template);
                index++;
            }
        }
Пример #41
0
        protected Dictionary<String, Object> mergeInheritedAttributes(JadeModel model)
        {
            Dictionary<String, Object> mergedAttributes = this.attributes;

            if (inheritsAttributes)
            {
                Object o = model.get("attributes");
                if (o != null && o is Dictionary<String, Object>) {
                    Dictionary<String, Object> inheritedAttributes = (Dictionary<String, Object>)o;

                    foreach (var entry in inheritedAttributes)
                    {
                        addAttribute(mergedAttributes, (String)entry.Key, entry.Value);
                    }
                }
            }
            return mergedAttributes;
        }
Пример #42
0
 //throws JadeCompilerException
 public override void execute(IndentWriter writer, JadeModel model, JadeTemplate template)
 {
     try
     {
         foreach (CaseConditionNode caseConditionNode in caseConditionNodes)
         {
             if (caseConditionNode.isDefault() || checkCondition(model, caseConditionNode))
             {
                 caseConditionNode.execute(writer, model, template);
                 break;
             }
         }
     }
     catch (ExpressionException e)
     {
         throw new JadeCompilerException(this, template.getTemplateLoader(), e);
     }
 }
Пример #43
0
 //throws JadeCompilerException
 public override void execute(IndentWriter writer, JadeModel model, JadeTemplate template)
 {
     var filter = model.getFilter(getValue());
     String result = textBlock.getValue();
     if (filter != null)
     {
         result = filter.convert(result, attributes, model);
     }
     try
     {
         result = Utils.interpolate(result, model, false);
     }
     catch (ExpressionException e)
     {
         throw new JadeCompilerException(this, template.getTemplateLoader(), e);
     }
     writer.append(result);
 }
Пример #44
0
 //throws JadeCompilerException
 public override void execute(IndentWriter writer, JadeModel model, JadeTemplate template)
 {
     foreach (IfConditionNode conditionNode in this.conditions)
     {
         try
         {
             if (conditionNode.isDefault() || checkCondition(model, conditionNode.getValue()) ^ conditionNode.isInverse())
             {
                 conditionNode.getBlock().execute(writer, model, template);
                 return;
             }
         }
         catch (ExpressionException e)
         {
             throw new JadeCompilerException(conditionNode, template.getTemplateLoader(), e);
         }
     }
 }
Пример #45
0
        private String getInterpolatedAttributeValue(String name, Object attribute, JadeModel model, JadeTemplate template)
        //throws JadeCompilerException
        {
            if (!preparedAttributeValues.ContainsKey(name))
            {
                preparedAttributeValues.Add(name, Utils.prepareInterpolate((String)attribute, true));
            }
            List <Object> prepared = preparedAttributeValues[name];

            try
            {
                return(Utils.interpolate(prepared, model));
            }
            catch (ExpressionException e)
            {
                throw new JadeCompilerException(this, template.getTemplateLoader(), e);
            }
        }
Пример #46
0
        protected Dictionary <String, Object> mergeInheritedAttributes(JadeModel model)
        {
            Dictionary <String, Object> mergedAttributes = this.attributes;

            if (inheritsAttributes)
            {
                Object o = model.get("attributes");
                if (o != null && o is Dictionary <String, Object> )
                {
                    Dictionary <String, Object> inheritedAttributes = (Dictionary <String, Object>)o;

                    foreach (var entry in inheritedAttributes)
                    {
                        addAttribute(mergedAttributes, (String)entry.Key, entry.Value);
                    }
                }
            }
            return(mergedAttributes);
        }
Пример #47
0
 public override void execute(IndentWriter writer, JadeModel model, JadeTemplate template)
 //throws JadeCompilerException
 {
     try
     {
         foreach (CaseConditionNode caseConditionNode in caseConditionNodes)
         {
             if (caseConditionNode.isDefault() || checkCondition(model, caseConditionNode))
             {
                 caseConditionNode.execute(writer, model, template);
                 break;
             }
         }
     }
     catch (ExpressionException e)
     {
         throw new JadeCompilerException(this, template.getTemplateLoader(), e);
     }
 }
Пример #48
0
 public override void execute(IndentWriter writer, JadeModel model, JadeTemplate template)
 //throws JadeCompilerException
 {
     foreach (IfConditionNode conditionNode in this.conditions)
     {
         try
         {
             if (conditionNode.isDefault() || checkCondition(model, conditionNode.getValue()) ^ conditionNode.isInverse())
             {
                 conditionNode.getBlock().execute(writer, model, template);
                 return;
             }
         }
         catch (ExpressionException e)
         {
             throw new JadeCompilerException(conditionNode, template.getTemplateLoader(), e);
         }
     }
 }
Пример #49
0
 //throws JadeCompilerException
 public override void execute(IndentWriter writer, JadeModel model, JadeTemplate template)
 {
     Object result;
     try
     {
         result = ExpressionHandler.evaluateExpression(getCode(), model);
     }
     catch (ExpressionException e)
     {
         throw new JadeCompilerException(this, template.getTemplateLoader(), e);
     }
     if (result == null)
     {
         throw new JadeCompilerException(this, template.getTemplateLoader(), "[" + code + "] has to be iterable but was null");
     }
     model.pushScope();
     run(writer, model, result, template);
     model.popScope();
 }
Пример #50
0
 // throws JadeCompilerException
 public override void execute(IndentWriter writer, JadeModel model, JadeTemplate template)
 {
     if (!isBuffered())
     {
         return;
     }
     writer.newline();
     if (value.StartsWith("if"))
     {
         writer.append("<!--[" + value + "]>");
         block.execute(writer, model, template);
         writer.append("<![endif]-->");
     }
     else
     {
         writer.append("<!--" + value);
         block.execute(writer, model, template);
         writer.append("-->");
     }
 }
Пример #51
0
 //throws JadeCompilerException
 public override void execute(IndentWriter writer, JadeModel model, JadeTemplate template)
 {
     writer.newline();
     writer.append("<");
     writer.append(name);
     writer.append(Attributes(model, template));
     if (isTerse(template))
     {
         writer.append(">");
         return;
     }
     if (isSelfClosing(template) || (selfClosing && isEmpty()))
     {
         writer.append("/>");
         return;
     }
     writer.append(">");
     if (hasTextNode())
     {
         textNode.execute(writer, model, template);
     }
     if (hasBlock())
     {
         writer.increment();
         block.execute(writer, model, template);
         writer.decrement();
         writer.newline();
     }
     if (hasCodeNode())
     {
         codeNode.execute(writer, model, template);
     }
     writer.append("</");
     writer.append(name);
     writer.append(">");
 }
Пример #52
0
        // throws ExpressionException
        private String getAttributeString(String name, Object attribute, JadeModel model, JadeTemplate template)
        {
            String value = null;
            if (attribute is String) {
                value = getInterpolatedAttributeValue(name, attribute, model, template);
            } else if (attribute is bool) {
                if ((bool)attribute)
                {
                    value = name;
                }
                else
                {
                    return "";
                }
                if (template.isTerse())
                {
                    value = null;
                }
            } else if (attribute is ExpressionString) {
                Object expressionValue = evaluateExpression((ExpressionString)attribute, model);
                if (expressionValue == null)
                {
                    return "";
                }
                // TODO: refactor
                if (expressionValue is bool) {
                    if ((bool)expressionValue)
                    {
                        value = name;
                    }
                    else
                    {
                        return "";
                    }
                    if (template.isTerse())
                    {
                        value = null;
                    }
                } else {
                    value = expressionValue.ToString();
                    value = Utils.escapeHTML(value);
                }
            } else {
                return "";
            }

            StringBuilder sb = new StringBuilder();
            if (name != null)
            {
                sb.Append(" ").Append(name);
                if (value != null)
                {
                    sb.Append("=").Append('"');
                    sb.Append(value);
                    sb.Append('"');
                }
            }
            return sb.ToString();
        }
Пример #53
0
 //throws JadeCompilerException
 private String getInterpolatedAttributeValue(String name, Object attribute, JadeModel model, JadeTemplate template)
 {
     if (!preparedAttributeValues.ContainsKey(name))
     {
         preparedAttributeValues.Add(name, Utils.prepareInterpolate((String)attribute, true));
     }
     List<Object> prepared = preparedAttributeValues[name];
     try
     {
         return Utils.interpolate(prepared, model);
     }
     catch (ExpressionException e)
     {
         throw new JadeCompilerException(this, template.getTemplateLoader(), e);
     }
 }
Пример #54
0
 private void run(String testName, bool pretty)
 {
     JadeModel model = new JadeModel(getModelMap(testName));
     run(testName, pretty, model);
 }
Пример #55
0
 //throws JadeCompilerException
 public override void execute(IndentWriter writer, JadeModel model, JadeTemplate template)
 {
     block.execute(writer, model, template);
 }
Пример #56
0
 public abstract void execute(IndentWriter writer, JadeModel model, JadeTemplate template);
Пример #57
0
        private void runIterator(IEnumerator iterator, JadeModel model, IndentWriter writer, JadeTemplate template)
        {
            int index = 0;

            if (!iterator.MoveNext())
            {
                executeElseNode(model, writer, template);
                return;
            }

            while (iterator.MoveNext())
            {
                model.put(getValue(), iterator.Current);
                model.put(getKey(), index);
                getBlock().execute(writer, model, template);
                index++;
            }
        }
Пример #58
0
 private void runMap(Dictionary<String, Object> result, JadeModel model, IndentWriter writer, JadeTemplate template)
 {
     var keys = result.Keys;
     if (keys.Count == 0)
     {
         executeElseNode(model, writer, template);
         return;
     }
     foreach (String key in keys)
     {
         model.put(getValue(), result[key]);
         model.put(getKey(), key);
         getBlock().execute(writer, model, template);
     }
 }
Пример #59
0
        private String Attributes(JadeModel model, JadeTemplate template)
        {
            StringBuilder sb = new StringBuilder();

            Dictionary<String, Object> mergedAttributes = mergeInheritedAttributes(model);

            foreach (var entry in mergedAttributes)
            {
                try
                {
                    sb.Append(getAttributeString(entry.Key, entry.Value, model, template));
                }
                catch (ExpressionException e)
                {
                    throw new JadeCompilerException(this, template.getTemplateLoader(), e);
                }
            }

            return sb.ToString();
        }
Пример #60
0
 //throws ExpressionException
 private Object evaluateExpression(ExpressionString attribute, JadeModel model)
 {
     String expression = ((ExpressionString)attribute).getValue();
     Object result = ExpressionHandler.evaluateExpression(expression, model);
     if (result is ExpressionString) {
         return evaluateExpression((ExpressionString)result, model);
     }
     return result;
 }