Exemplo n.º 1
0
        public void FormatMoney()
        {
            var template = "{{money 10000}}";
            var result   = _engine.Render("test", template, null);

            Assert.AreEqual("$100.00", result);
        }
Exemplo n.º 2
0
        public void Stringify_Context()
        {
            var template = "{{stringify this}}";
            var result   = _engine.Render("test", template, "{ \"jas\": 123, \"foo\": \"bar\" }");

            Assert.AreEqual("{\"jas\":123,\"foo\":\"bar\"}", result);
        }
Exemplo n.º 3
0
        public void FormatNumber()
        {
            var template = "{{format foo}}";

            var result = _engine.Render("test", template, "{ \"foo\": 1 }");

            Assert.AreEqual("1", result);
        }
Exemplo n.º 4
0
        public void ImportPreCompileJS()
        {
            _engine.Compile("test-precompile", template);
            var js = _engine.ExportPrecompile();

            _engine.ImportPrecompile(js);

            var output = _engine.Render("test-precompile", new { title = "My New Post", body = "This is my first post!" });

            // note: yui compress can gain 50% before gzip, 70% after.
            Assert.AreEqual("<div class=\"entry\"><h1>My New Post</h1><div class=\"body\">This is my first post!</div></div>",
                            output);
        }
Exemplo n.º 5
0
        public void BasicPropertyCheck()
        {
            var template = "{{#if foo}}" +
                           "bar" +
                           "{{else}}" +
                           "notbar" +
                           "{{/if}}";

            var result = _engine.Render("test", template, "{ \"foo\": true }");

            Assert.AreEqual("bar", result);
            result = _engine.Render("test", template, "{ \"foo\": false }");
            Assert.AreEqual("notbar", result);
        }
Exemplo n.º 6
0
        public void StringConcat()
        {
            var template = "{{concat 'foo' 'bar'}}";
            var result   = _engine.Render("test", template, null);

            Assert.AreEqual("foobar", result);
        }
Exemplo n.º 7
0
        public void PluckFromObjectArray()
        {
            var template = "{{pluck foo 'name'}}";
            var result   = _engine.Render("test", template, "{ foo: [{ id: 0, name: 'James' },{ id: 1, name: 'Andrew' },{ id: 2, name: 'Smith' }] }");

            Assert.AreEqual("James,Andrew,Smith", result);
        }
Exemplo n.º 8
0
        public void Pluralize_WithCount()
        {
            var template = "{{pluralize 'record' 1}}";
            var result   = _engine.Render("test", template, null);

            Assert.AreEqual("record", result);
        }
Exemplo n.º 9
0
 public string Render(string name, string json)
 {
     try
     {
         return(_engine.Render(name.ToLower(), json));
     }
     catch (Exception exp)
     {
         return(@"<html>
                  <head></head>
                  <body>
                  <h4>" + exp.Message + @"</h4>
                  <pre>" + exp.StackTrace + @"</pre>
                  </body>
                  </html>");
     }
 }
Exemplo n.º 10
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"))
        }
Exemplo n.º 11
0
 public string Render(string name, string json)
 {
     try
     {
         lock (_sync)
         {
             var template = _provider.GetTemplate(name);
             EnsurePartialTemplate(template);
             var html = _engine.Render(name, template, json);
             _engine.Clear();
             return(html);
         }
     }
     catch (Exception exp)
     {
         return(@"<h4>" + exp.Message + @"</h4>
                  <pre>" + exp.StackTrace + @"</pre>");
     }
 }
Exemplo n.º 12
0
        public string FillDonutHoles(string input)
        {
            // todo:
            // potentially make this a parallel operation

            foreach (Match m in DonutAction.Matches(input))
            {
                var split = m.Value.Split(':');

                string action     = split[1].TrimEnd('#');
                string controller = controller = split[1];
                string area       = "";

                if (m.Groups["area"].Success)
                {
                    area = m.Groups["area"].Value;
                }

                // Console.WriteLine("TODO: Fill Donut for: " + (string.IsNullOrEmpty(area) ? "" :  area + "\\") + controller + "\\" + action);

                using (var client = new WebClient())
                {
                    // client.Headers["User-Agent"] = context.Request.Headers["User-Agent"];
                    // client.Headers["Cookie"] = context.Request.Headers["Cookie"];

                    if (_authHeader != null)
                    {
                        client.Headers.Add("auth", _authHeader.Parameter);
                    }

                    var data = client.DownloadData(GetProxyUri(new Uri(HandlebarsProxyConfiguration.Instance.Scheme +
                                                                       "://" +
                                                                       HandlebarsProxyConfiguration.Instance.Domain + ":" +
                                                                       HandlebarsProxyConfiguration.Instance.DomainPort +
                                                                       "/" +
                                                                       (string.IsNullOrEmpty(area) ? "" : area + "/") +
                                                                       (string.IsNullOrEmpty(controller) ? "" : controller + "/") +
                                                                       (string.IsNullOrEmpty(action) ? "" : action)
                                                                       )));
                    var json = Encoding.UTF8.GetString(data);
                    var o    = JObject.Parse(json);

                    o["debug"] = true;
                    // o["_config"]["cdn"] = "//" + HandlebarsProxyConfiguration.Instance.Hostname + ":" + HandlebarsProxyConfiguration.Instance.CdnPort;
                    o["_request"]["fqdn"]     = "http://" + HandlebarsProxyConfiguration.Instance.Hostname + ":" + HandlebarsProxyConfiguration.Instance.Port;
                    o["_request"]["hostname"] = HandlebarsProxyConfiguration.Instance.Hostname + ":" + HandlebarsProxyConfiguration.Instance.Port;
                    json = o.ToString(Formatting.None);

                    var templateName = client.ResponseHeaders["x-template"];
                    var templatePath = Path.Combine(HandlebarsProxyConfiguration.Instance.Directory +
                                                    "\\template",
                                                    templateName.Replace("/", "\\") + ".handlebars");

                    if (!File.Exists(templatePath))
                    {
                        templatePath = Path.Combine(HandlebarsProxyConfiguration.Instance.Directory +
                                                    "\\template",
                                                    templateName.Replace("/", "\\") + ".hbs");
                    }

                    var templateData = File.ReadAllText(templatePath);

                    var html = _handlebars.Render(templateData, json);
                    input = input.Replace(m.Value, html);
                }
            }

            return(input);
        }
Exemplo n.º 13
0
        public void RenderSingle()
        {
            var result = _engine.Render("test", "<body>{{body}}</body>", "{\"body\":\"This is a test\"}");

            Assert.AreEqual(result, "<body>This is a test</body>");
        }