Beispiel #1
0
        /// <summary>
        /// Return all the precompiled templates as a single JavaScript object
        /// with each template as a property, this means we don't need the
        /// front end to download all the templates (which are larger) and the
        /// code to compile the templates (again faster).
        /// </summary>
        /// <returns></returns>
        public string GetPreCompileJS()
        {
            var sb = new StringBuilder();

            sb.Append("var Handlebars = Handlebars || {};\n");
            sb.Append("Handlebars.templates = Handlebars.templates || {};\n");
            sb.Append("Handlebars.partials = Handlebars.partials || {};\n");

            foreach (var kvp in _partials)
            {
                sb.AppendLine("Handlebars.partials['" + kvp.Key + "'] = Handlebars.template(" + (string)_context.Evaluate("Handlebars.precompile('" + kvp.Value + "');") + ");");
            }

            foreach (var kvp in _templates)
            {
                sb.AppendLine("Handlebars.templates['" + kvp.Key + "'] = Handlebars.template(" + (string)_context.Evaluate("Handlebars.precompile('" + kvp.Value + "');") + ");");
            }

            return(sb.ToString());
        }