Beispiel #1
0
 public void CompileTemplate()
 {
     _engine.Compile("test", template);
     //
     // TODO: Add test logic here
     //
 }
Beispiel #2
0
        public void CompileThenRender()
        {
            _engine.Compile("test-then-render", "<body>{{body}}</body>");
            var result = _engine.Render("test-then-render", "{\"body\":\"This is a test\"}");

            Assert.AreEqual(result, "<body>This is a test</body>");
        }
Beispiel #3
0
        public void Run(string export = "all.js", bool debug = false)
        {
            foreach (var path in _templates)
            {
                var name = path.Replace(_root, "")
                           .Replace("_template\\", "")
                           .Replace("template\\", "")
                           .Replace(".hbs", "")
                           .Replace(".handlebars", "")
                           .Replace("\\", "/")
                           .Trim('/')
                           .ToLower();

                Console.WriteLine("Compiling template \"" + name + "\"");

                var template = CompactTemplate(File.ReadAllText(path, System.Text.Encoding.UTF8));

                EnsurePartial(template);

                _handlebars.Compile(name, template);
                if (debug)
                {
                    _handlebars.ExportPrecompile();
                }
            }

            File.WriteAllText(export,
                              _handlebars.ExportPrecompile(),
                              System.Text.Encoding.UTF8);

            _handlebars.Clear();
        }
Beispiel #4
0
        public string Render(string name, string json)
        {
            if (!_engine.Exists(name))
            {
                var template = _provider.GetTemplate(name);
                if (string.IsNullOrEmpty(template))
                {
                    return(template);
                }

                EnsurePartialTemplate(template);
                _engine.Compile(name, template);
            }

            return(_engine.Render(name, json));
            // File.ReadAllText(MapPath.Map("~/bin/_template/" + masterPath + ".handlebars"))
        }