Exemplo n.º 1
0
        private void InitTmpls()
        {
            _tmpls = new Dictionary <string, Volt> (StringComparer.InvariantCultureIgnoreCase);

            foreach (Token elem in _elements)
            {
                if (elem is Tag)
                {
                    Tag tag = (Tag)elem;

                    if (string.Compare(tag.Name, "define", true) == 0)
                    {
                        Expression ename = tag.AttributeValue("name");
                        string     tname;

                        if (ename is StringLiteral)
                        {
                            tname = ((StringLiteral)ename).Content;
                        }
                        else
                        {
                            tname = "?";
                        }

                        Volt tmpl = new Volt(tname, tag.Tokens, this);
                        _tmpls[tname] = tmpl;
                    }
                }
            }
        }
Exemplo n.º 2
0
        public Volt(string name, List <Token> elements)
        {
            _name     = name;
            _elements = elements;
            _parent   = null;

            InitTmpls();
        }
Exemplo n.º 3
0
        public Volt(string name, List <Token> elements, Volt parent)
        {
            _name     = name;
            _elements = elements;
            _parent   = parent;

            InitTmpls();
        }
Exemplo n.º 4
0
        public VoltEngine(Volt tmpl)
        {
            _mainTmpl     = tmpl;
            _currentTmpl  = tmpl;
            _silentErrors = false;
            _scriptMode   = false;

            Initialize();
        }
Exemplo n.º 5
0
        private void ProcessTmpl(string name, Tag tag)
        {
            if (customTags != null && customTags.ContainsKey(name))
            {
                ExecuteCustomTag(tag);
                return;
            }

            Volt useTmpl = _currentTmpl.FindTmpl(name);

            if (useTmpl == null)
            {
                string msg = string.Format("Volt '{0}' not found", name);
                throw new VoltException(msg, tag.Line, tag.Col);
            }

            TextWriter saveWriter = writer;

            writer = new StringWriter();
            string content = string.Empty;

            try {
                ProcessTokens(tag.Tokens);

                content = writer.ToString();
            } finally {
                writer = saveWriter;
            }

            Volt saveTmpl = _currentTmpl;

            _variables = new Variable(_variables);
            _variables["innerText"] = content;

            try {
                foreach (DotAttribute attrib in tag.Attributes)
                {
                    object val = EvalExpression(attrib.Expression);
                    _variables[attrib.Name] = val;
                }

                _currentTmpl = useTmpl;
                ProcessTokens(_currentTmpl.Elements);
            } finally {
                _variables   = _variables.Parent;
                _currentTmpl = saveTmpl;
            }
        }
Exemplo n.º 6
0
        public void Process(TextWriter writer)
        {
            this.writer       = writer;
            this._currentTmpl = _mainTmpl;

            if (_handler != null)
            {
                SetValue("this", _handler);
                _handler.BeforeProcess(this);
            }

            ProcessTokens(_mainTmpl.Elements);

            if (_handler != null)
            {
                _handler.AfterProcess(this);
            }
        }
Exemplo n.º 7
0
        public static VoltEngine Parser(string name, string tmpl)
        {
            Volt iTmpl = Volt.Parser(name, tmpl);

            return(new VoltEngine(iTmpl));
        }
Exemplo n.º 8
0
 public void AddTmpl(Volt tmpl)
 {
     _mainTmpl.Tmpls.Add(tmpl.Name, tmpl);
 }