Пример #1
0
 //throws JadeCompilerException
 public override void execute(IndentWriter writer, JadeModel model, JadeTemplate template)
 {
     foreach (Node node in getNodes())
     {
         node.execute(writer, model, template);
     }
 }
Пример #2
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();
        }
Пример #3
0
        public void compile(JadeModel model, TextWriter w)
        {
            IndentWriter writer = new IndentWriter(w);

            writer.setUseIndent(prettyPrint);
            rootNode.execute(writer, model, template);
        }
Пример #4
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);
            }
        }
Пример #5
0
 private void executeElseNode(JadeModel model, IndentWriter writer, JadeTemplate template)
 {
     if (elseNode != null)
     {
         elseNode.execute(writer, model, template);
     }
 }
Пример #6
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);
        }
Пример #7
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);
     }
 }
Пример #8
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);
 }
Пример #9
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);
     }
 }
Пример #10
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);
     }
 }
Пример #11
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);
         }
     }
 }
Пример #12
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);
 }
Пример #13
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();
 }
Пример #14
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("-->");
     }
 }
Пример #15
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(">");
 }
Пример #16
0
 public abstract void execute(IndentWriter writer, JadeModel model, JadeTemplate template);
Пример #17
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++;
            }
        }
Пример #18
0
 public void compile(JadeModel model, TextWriter w)
 {
     IndentWriter writer = new IndentWriter(w);
     writer.setUseIndent(prettyPrint);
     rootNode.execute(writer, model, template);
 }
Пример #19
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);
     }
 }
Пример #20
0
 //throws JadeCompilerException
 public override void execute(IndentWriter writer, JadeModel model, JadeTemplate template)
 {
     writer.append(value);
 }
Пример #21
0
 //throws JadeCompilerException
 public override void execute(IndentWriter writer, JadeModel model, JadeTemplate template)
 {
     block.execute(writer, model, template);
 }