public void GivenAssetNotSubPathOfBundlePath_ThenGetTemplateIdReturnsJustFilename()
        {
            var bundle = new HtmlTemplateBundle("~/bundle");
            var id     = bundle.GetTemplateId(new StubAsset("~/test.htm"));

            id.ShouldEqual("test");
        }
        public void GetTemplateIdIncludesDirectoryAndFilenameSeparatedWithHyphen()
        {
            var bundle = new HtmlTemplateBundle("~");
            var id     = bundle.GetTemplateId(new StubAsset("~/dir/test.htm"));

            id.ShouldEqual("dir-test");
        }
        public void GetTemplateIdReturnsAssetFilenameWithoutExtension_WhenTemplateBundlePerFile()
        {
            var bundle = new HtmlTemplateBundle("~/test.htm");
            var id     = bundle.GetTemplateId(new StubAsset("~/test.htm"));

            id.ShouldEqual("test");
        }
Beispiel #4
0
 public Func <Stream> Transform(Func <Stream> openSourceStream, IAsset asset)
 {
     return(delegate
     {
         var id = bundle.GetTemplateId(asset);
         var template = openSourceStream().ReadToEnd();
         return string.Format("$.template('{0}', {1});{2}", id, template, Environment.NewLine).AsStream();
     });
 }
 public Func <Stream> Transform(Func <Stream> openSourceStream, IAsset asset)
 {
     return(delegate
     {
         var template = openSourceStream().ReadToEnd();
         var scriptElement = String.Format(
             "<script id=\"{0}\" type=\"{1}\">{2}</script>",
             bundle.GetTemplateId(asset),
             bundle.ContentType,
             template
             );
         return scriptElement.AsStream();
     });
 }
        public Func <Stream> Transform(Func <Stream> openSourceStream, IAsset asset)
        {
            return(delegate
            {
                var compiledTemplate = openSourceStream().ReadToEnd();

                var id = bundle.GetTemplateId(asset);
                var template = javaScriptVariableName + "['" + id + "']";

                var output = template + "=new Hogan.Template();" +
                             template + ".r=" + compiledTemplate + ";";
                return output.AsStream();
            });
        }
        public Func <Stream> Transform(Func <Stream> openSourceStream, IAsset asset)
        {
            return(delegate
            {
                var id = bundle.GetTemplateId(asset);
                var compiled = openSourceStream().ReadToEnd();
                var template = javaScriptVariableName + "['" + id + "']";
                var sb = new StringBuilder();

                sb.AppendLine("var " + javaScriptVariableName + " = " + javaScriptVariableName + "|| {};");
                sb.AppendLine(template + "= new HoganTemplate();");
                sb.AppendLine(template + ".render = " + compiled);

                return sb.ToString().AsStream();
            });
        }
 public void GivenAssetNotSubPathOfBundlePath_ThenGetTemplateIdReturnsJustFilename()
 {
     var bundle = new HtmlTemplateBundle("~/bundle");
     var id = bundle.GetTemplateId(new StubAsset("~/test.htm"));
     id.ShouldEqual("test");
 }
 public void GetTemplateIdReturnsAssetFilenameWithoutExtension_WhenTemplateBundlePerFile()
 {
     var bundle = new HtmlTemplateBundle("~/test.htm");
     var id = bundle.GetTemplateId(new StubAsset("~/test.htm"));
     id.ShouldEqual("test");
 }
 public void GetTemplateIdIncludesDirectoryAndFilenameSeparatedWithHyphen()
 {
     var bundle = new HtmlTemplateBundle("~");
     var id = bundle.GetTemplateId(new StubAsset("~/dir/test.htm"));
     id.ShouldEqual("dir-test");
 }