Esempio n. 1
0
 public virtual Volt FindTmpl(string name)
 {
     if (_tmpls.ContainsKey(name))
     {
         return(_tmpls[name]);
     }
     else if (_parent != null)
     {
         return(_parent.FindTmpl(name));
     }
     else
     {
         return(null);
     }
 }
Esempio n. 2
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;
            }
        }