Beispiel #1
0
        private void InitTmpls()
        {
            this.tmpls = new Dictionary <string, Tmpl> (StringComparer.InvariantCultureIgnoreCase);

            foreach (Element 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 = "?";
                        }

                        Tmpl tmpl = new Tmpl(tname, tag.InnerElements, this);
                        tmpls[tname] = tmpl;
                    }
                }
            }
        }
Beispiel #2
0
        public Tmpl(string name, List <Element> elements, Tmpl parent)
        {
            this.name     = name;
            this.elements = elements;
            this.parent   = parent;

            InitTmpls();
        }
Beispiel #3
0
        public Tmpl(string name, List <Element> elements)
        {
            this.name     = name;
            this.elements = elements;
            this.parent   = null;

            InitTmpls();
        }
Beispiel #4
0
        public Tmpl(string name, List<Token> elements, Tmpl parent)
        {
            this.name = name;
            this.elements = elements;
            this.parent = parent;

            InitTmpls();
        }
Beispiel #5
0
        public Tmpl(string name, List<Token> elements)
        {
            this.name = name;
            this.elements = elements;
            this.parent = null;

            InitTmpls();
        }
Beispiel #6
0
        public TmplManager(Tmpl tmpl)
        {
            _mainTmpl     = tmpl;
            _currentTmpl  = tmpl;
            _silentErrors = false;
            _scriptMode   = false;

            Init();
        }
Beispiel #7
0
        public TmplManager(Tmpl tmpl)
        {
            _mainTmpl     = tmpl;
            _currentTmpl  = tmpl;
            _silentErrors = false;
            _scriptMode   = false;

            Init();
        }
Beispiel #8
0
        private void ProcessTmpl(string name, Tag tag)
        {
            if (customTags != null && customTags.ContainsKey(name))
            {
                ExecuteCustomTag(tag);
                return;
            }

            Tmpl useTmpl = _currentTmpl.FindTmpl(name);

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

            TextWriter saveWriter = writer;

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

            try {
                ProcessElements(tag.InnerElements);

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

            Tmpl 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;
                ProcessElements(_currentTmpl.Elements);
            } finally {
                _variables   = _variables.Parent;
                _currentTmpl = saveTmpl;
            }
        }
Beispiel #9
0
        public void Process(TextWriter writer)
        {
            this.writer       = writer;
            this._currentTmpl = _mainTmpl;

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

            ProcessElements(_mainTmpl.Elements);

            if (_handler != null)
            {
                _handler.AfterProcess(this);
            }
        }
Beispiel #10
0
 public void AddTmpl(Tmpl tmpl)
 {
     _mainTmpl.Tmpls.Add(tmpl.Name, tmpl);
 }
Beispiel #11
0
        private void ProcessTmpl(string name, Tag tag)
        {
            if (customTags != null && customTags.ContainsKey(name)) {
                ExecuteCustomTag(tag);
                return;
            }

            Tmpl useTmpl = _currentTmpl.FindTmpl(name);

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

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

            try {
                ProcessElements(tag.InnerTokens);

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

            Tmpl 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;
                ProcessElements(_currentTmpl.Elements);
            } finally {
                _variables   = _variables.Parent;
                _currentTmpl = saveTmpl;
            }
        }
Beispiel #12
0
        public void Process(TextWriter writer)
        {
            this.writer = writer;
            this._currentTmpl = _mainTmpl;

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

            ProcessElements(_mainTmpl.Elements);

            if (_handler != null) {
                _handler.AfterProcess(this);
            }
        }
Beispiel #13
0
 public void AddTmpl(Tmpl tmpl)
 {
     _mainTmpl.Tmpls.Add(tmpl.Name, tmpl);
 }
Beispiel #14
0
        public static TmplManager Parser(string tmpl)
        {
            Tmpl iTmpl = Tmpl.Parser("", tmpl);

            return(new TmplManager(iTmpl));
        }
Beispiel #15
0
        private void InitTmpls()
        {
            this.tmpls = new Dictionary<string, Tmpl> (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 = "?";
                        }

                        Tmpl tmpl = new Tmpl(tname, tag.InnerTokens, this);
                        tmpls[tname] = tmpl;
                    }
                }
            }
        }