예제 #1
0
파일: BlockNode.cs 프로젝트: rnrn/Jade4Net
 //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
파일: EachNode.cs 프로젝트: rnrn/Jade4Net
 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
파일: EachNode.cs 프로젝트: rnrn/Jade4Net
 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
파일: WhileNode.cs 프로젝트: rnrn/Jade4Net
 //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
파일: CaseNode.cs 프로젝트: rnrn/Jade4Net
 //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
파일: FilterNode.cs 프로젝트: rnrn/Jade4Net
 //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
파일: EachNode.cs 프로젝트: rnrn/Jade4Net
 //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
파일: TagNode.cs 프로젝트: rnrn/Jade4Net
 //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
파일: Node.cs 프로젝트: rnrn/Jade4Net
 public abstract void execute(IndentWriter writer, JadeModel model, JadeTemplate template);
예제 #17
0
파일: EachNode.cs 프로젝트: rnrn/Jade4Net
        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
파일: Compiler.cs 프로젝트: rnrn/Jade4Net
 public void compile(JadeModel model, TextWriter w)
 {
     IndentWriter writer = new IndentWriter(w);
     writer.setUseIndent(prettyPrint);
     rootNode.execute(writer, model, template);
 }
예제 #19
0
파일: EachNode.cs 프로젝트: rnrn/Jade4Net
 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);
 }