public CompiledTemplate Build(ParsedTemplate template)
		{
			Precondition.Require(template, () => Error.ArgumentNull("template"));
			OnPreCompile(template);

			foreach (TemplateExpression expression in template.ExpressionTree)
				VisitExpression(expression);

			OnPostCompile(template);
			return CreateCompiledTemplate();
		}
Example #2
0
        public ParsedTemplate Parse(string text, Encoding encoding)
        {
            HandlePreParse();
            ParseInternal(text, encoding);
            HandlePostParse();

            ParsedTemplate template =
                new ParsedTemplate(_virtualPath, encoding, Expressions);

            template.Name = _templateName;
            return(template);
        }
        private static string GetMethodName(ParsedTemplate template)
        {
            string templateName = template.Name;

            if (String.IsNullOrEmpty(templateName))
            {
                templateName = (String.IsNullOrEmpty(template.VirtualPath))
                                        ? "__untitledTemplate"
                                        : Path.GetFileNameWithoutExtension(template.VirtualPath);
            }

            return(EnsureValidMethodName(templateName));
        }
Example #4
0
        public CompiledTemplate Build(ParsedTemplate template)
        {
            Precondition.Require(template, () => Error.ArgumentNull("template"));
            OnPreCompile(template);

            foreach (TemplateExpression expression in template.ExpressionTree)
            {
                VisitExpression(expression);
            }

            OnPostCompile(template);
            return(CreateCompiledTemplate());
        }
        protected override void OnPostCompile(ParsedTemplate template)
        {
            string methodNameFormat = (Inline)
                                ? "{0}: function({1}) {{"
                                : "function {0}({1}) {{";

            PrependCodeBlock(String.Format(methodNameFormat, _templateName,
                                           String.Join(", ", _parameters.OrderBy(p => p.Index)
                                                       .Select(p => p.Name).ToArray())));

            AppendCodeBlock(String.Format("return {0}.join('');",
                                          CodeBufferVariableName));

            AppendCodeBlock("}");
        }
        protected virtual CompiledTemplate CompileTemplate(TemplateInfo info)
        {
            TemplateParser parser   = new TemplateParser();
            ParsedTemplate template = parser.ParseFile(info.VirtualPath);

            JavaScriptTemplateCompiler compiler =
                new JavaScriptTemplateCompiler(info.Debug);

            if (!String.IsNullOrEmpty(info.BufferVariableName))
            {
                compiler.CodeBufferVariableName = info.BufferVariableName;
            }

            return(compiler.Build(template));
        }
		protected virtual void OnPostCompile(ParsedTemplate template)
		{
		}
 protected override void OnPreCompile(ParsedTemplate template)
 {
     _templateName = GetMethodName(template);
     AppendCodeBlock(String.Format("var {0} = [];",
                                   CodeBufferVariableName));
 }
		protected override void OnPostCompile(ParsedTemplate template)
		{
			string methodNameFormat = (Inline) 
				? "{0}: function({1}) {{" 
				: "function {0}({1}) {{";

			PrependCodeBlock(String.Format(methodNameFormat, _templateName, 
				String.Join(", ", _parameters.OrderBy(p => p.Index)
				.Select(p => p.Name).ToArray())));
			
			AppendCodeBlock(String.Format("return {0}.join('');", 
				CodeBufferVariableName));

			AppendCodeBlock("}");
		}
		protected override void OnPreCompile(ParsedTemplate template)
		{
			_templateName = GetMethodName(template);
			AppendCodeBlock(String.Format("var {0} = [];", 
				CodeBufferVariableName));
		}
		private static string GetMethodName(ParsedTemplate template)
		{
			string templateName = template.Name;

			if (String.IsNullOrEmpty(templateName))
				templateName = (String.IsNullOrEmpty(template.VirtualPath))
					? "__untitledTemplate" 
					: Path.GetFileNameWithoutExtension(template.VirtualPath);

			return EnsureValidMethodName(templateName);
		}
Example #12
0
 protected virtual void OnPostCompile(ParsedTemplate template)
 {
 }
		public ParsedTemplate Parse(string text, Encoding encoding)
		{
			HandlePreParse();
			ParseInternal(text, encoding);
			HandlePostParse();

			ParsedTemplate template = 
				new ParsedTemplate(_virtualPath, encoding, Expressions);

			template.Name = _templateName;
			return template;
		}