Giter VIP home page Giter VIP logo

nustache's Introduction

Nustache - Logic-less templates for .NET

Nustache.Core Nustache.Core

  • Nustache.Core: Nustache.Core
  • Nustache.Mvc3: Nustache.Mvc3
  • Nustache.Compliation: Nustache.Compliation

NEW NOTICE - 2015-03-29:

Hello, as you may have noticed this repository has been silent for awhile. I worked on it awhile ago when I had a problem but didn't contribute any more.

I'm planning to commit some time to looking at outstanding pull-requests and issues and try get the project moving again. With that in mind feel free to open issues and contribute pull requests.

  • Romanx

NOTICE (JDiamond):

I haven't used Nustache in a while and don't have enough bandwidth to responsibly maintain it. If you depend on Nustache and want committ access, please contact me!

For a list of implementations (other than .NET) and editor plugins, see http://mustache.github.com/.

Installation:

  • Pull from GitHub or download the repository and build it.
  • Or, install via NuGet (search for Nustache).
  • If you're using MVC, you'll want to build/install the Nustache.Mvc3 project, too.

Usage:

For non-MVC projects:

  • Add a reference to Nustache.Core.dll (done for you if you used NuGet).
  • Import the Nustache.Core namespace.
  • Use one of the static, helper methods on the Render class.
var html = Render.FileToString("foo.template", myData);
  • Data can be object, IDictionary, or DataTable.
  • If you need more control, use Render.Template.
  • See the source and tests for more information.
  • For compiled templates:
var template = new Template();
template.Load(new StringReader(templateText));
var compiled = template.Compile<Foo>(null);

var html = compiled(fooInstance);

For MVC projects:

  • Add a reference to Nustache.Mvc3.dll (done for you if you used NuGet).
  • Add NustacheViewEngine to the global list of view engines.
  • See Global.asax.cs in the Nustache.Mvc3.Example project for an example.

nustache.exe:

  • Command-line wrapper around Render.FileToFile.

  • Parameters are templatePath, dataPath, and outputPath.

  • Reads JSON or XML from dataPath for data.

    • If extension is .js or .json, assumes JSON. Must wrap with { }.

    • If extension is .xml, assumes XML. Initial context is the document element.

      nustache.exe foo.template myData.json foo.html
      
  • External templates are assumed to be in the same folder as the template mentioned in templatePath.

  • Extension is also assumed to be the same as the template in templatePath.

Syntax:

  • The same as Mustache with some extensions.
  • Support for defining internal templates:
{{<foo}}This is the foo template.{{/foo}}
The above doesn't get rendered until it's included
like this:
{{>foo}}

You can define templates inside sections. They override templates defined in outer sections which override external templates.

Helpers usage:

Helpers may be useful to:

  • Apply custom format on the values to be rendered
  • To call extension methods
  • ...

Example: Following line should print time like 13:21:10 instead of default format of DateTime.

{{FormatDateTime FooDateTime format="HH:mm:ss"}}

To get this working use following code before rendering.

Nustache.Core.Helpers.Register("FormatDateTime", FormatDateTime);

And implement the function FormatDateTime, which could look like this:

static void FormatDateTime(RenderContext context, IList<object> arguments, IDictionary<string, object> options, RenderBlock fn, RenderBlock inverse)
{
	if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is DateTime)
	{
		DateTime datetime = (DateTime)arguments[0];
		if (options != null && options.ContainsKey("format"))
			context.Write(datetime.ToString(options["format"] as string));
		else
			context.Write(datetime.ToString());
	}
}

Helpers syntax in nustache is HelperName [arguments] [options]. Difference between arguments and options is that the options specifie the tuples key=value while arguments are simple values. If value (from arguments or options) is not closed within double quotes it gets evaluated (e.g. FooDateTime is evaluated to value of the member called FooDateTime, and therefore the argument[0] is of DateTime type. On the other hand the string "HH:mm:ss" is not evaluated.

All arguments and options are separated by spaces and even closed in double-quotes they cannot contain spaces. arguments and options may be mixed (equation sign marks it is option instead of argument).

Development:

  • Build with VS2012 or MSBuild.
  • To run the tests that use Mustache specs, run this command from your Nustache clone:
git submodule update --init

nustache's People

Contributors

adamjernst avatar aelij avatar anaisbetts avatar bartul avatar brendanhay avatar dhgoldman avatar jdiamond avatar joaompneves avatar jonwingfield avatar josephwoodward avatar lukasz-lysik avatar markborcherding avatar mdevilliers avatar mrydengren avatar mschaad avatar nolanw avatar rafarhat avatar raoulmillais avatar rdingwall avatar romanx avatar taschmidt avatar unarist avatar wallymathieu avatar zacherates avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nustache's Issues

Issues in the nuget package

It looks like the current package does not work well with the latest nuget version. The assemblies are being stored in the wrong folder so visual studio does not know how to automatically reference them in the project. The assemblies should be stored in
packages[nustache]\lib\net35 (or net40) to be picked automatically by visual studio. However, the current package is putting those in packages[nustache]\net35 (or net40) directly.

Thanks
Pablo.

BOM problem

Greetings,

When I use a StringToString method (I cannot use a Template) I cannot control some rendering behavior. For example I cannot specify which encoder must be used and how, and as consequence I cannot control BOMs (bad surprises). What about change StringToString signature and add more params for more flexibility?

Issues in the nuget package

It looks like the current package does not work well with the latest nuget version. The assemblies are being stored in the wrong folder so visual studio does not know how to automatically reference them in the project. The assemblies should be stored in
packages[nustache]\lib\net35 (or net40) to be picked automatically by visual studio. However, the current package is putting those in packages[nustache]\net35 (or net40) directly.

Thanks
Pablo.

Issues with paths, nested objects

Given a JSON file that looks like

{
  "data": {
    "subkey": {
      "list": [{ "item": { "foo" : "red" } }, { "item": {"foo" : "orange"}}]
    }
  },
  "monkey": {
    "list" :  [{ "foo" : "red" }, { "foo" : "orange"}]
  },
  "bobos": [{ "item": { "foo" : "red" } }, { "item": {"foo" : "orange"}}],
  "fudge" : "delicious"
}

and a template that looks like

Should be 'red orange':
{{#data.subkey}}subkey ok{{#list}}list ok{{#item}}item ok{{foo}} {{/item}}{{/list}}{{/data.subkey}}
Should be 'red orange':
{{#data}}data ok{{#subkey}}subkey ok{{#list}}list okay{{#item}}item ok{{foo}} {{/item}}{{/list}}{{/subkey}}{{/data}}
Should be 'red orange':
{{#monkey}}{{#list}}{{foo}} {{/list}}{{/monkey}}
Also should be 'red orange':
{{#monkey.list}}{{foo}} {{/monkey.list}}
Also should be 'red orange':
{{#bobos}}{{#item}}{{foo}} {{/item}}{{/bobos}}

I think all the cases should work? Right now, the only case that is rendering correctly seems to be the second to last one (monkey.list).

I'm looking at the source now, but I thought I'd report it to make sure I'm not looking for something that in fact shouldn't work.

In the example app @Url.Content paths are not being expanded

If I view source on the page, @Url.Content shows up in the markup. I'm not sure how to fix this otherwise I would send a PR :)

<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>

Does not support adding partial views

There is no support for adding partial views from a mustache template.

Steps to reproduce:

  1. Create a .mustache view
  2. create a .mustache partialview
  3. link to a partial view {{>_list}}

Access Elements of Array

In mustache.js one can access array by using a.0

mustache.render("{{a.0}}", {a: ['hello','world']})
=> 'hello'

Apparently this is not possible in Nustache. Is there any workaround or any fix?

Setting RootContext doesn`t work with Partials called from Razor

This configuration string:

           // Uncomment out this line to not need Model in front of all your expressions.
           // This makes it easier to share templates between the client and server.
          // But it also means that ViewData/ViewBag will be inaccessible.
          RootContext = NustacheViewEngineRootContext.Model

does NOT work with nustache partial view called from Razor view with @Html.Partial("PartialNustache").
You still need to write in the Partial

         Model Property: {{ Model.DoModelPropertiesWork }}

instead of

          Model Property: {{ DoModelPropertiesWork }}.

This is making client/server templates sharing much more complicated, which is big advantage of Mustache.

How do I render a array

Hi seems the documentation is less sparse ( for usage with .net) how do i render a array using nustache. Seems this does not work

ltrHeading.Text = Nustache.Core.Render.StringToString("{{}}", new string[] { "1", "2", "3", "4" }); where ltrHeading is the literal control. Generally this would have template like {{#key}}{{/key}} but i am out of idea as how to render an simple array

Support for Mono

Are you planning to support using Nustache in Mono(droid/Touch) projects?

1.13.8.22 breaks nested fully qualified access.

In my application I use nustache to generate sql statement that I send to dapper.

I use a dictionary to represent my rendering universe with variables for server side consumption prefixed with a $ sign. I also do this to "mustachify" certain system variables. so I might want to do certain things on GET or on certain routes. Based on the presence of an id in a route.

Here is a simplified template that Is breaking:

{{#$request.$isGET}}
{{#$request.id}}
select 'TruePath' [Path],@id [id]
###params###
id
{{/$request.id}}
{{^$request.id}}
select 'FalsePath' [Path]
###params###
{{/$request.id}}
{{/$request.$isGET}}

params### is a construct I use to help with query plan caching.

And the state of my universe (jsonified version of the universe object)::

{
    "$request": {
        "$route": {
            "hasId": true
        },
        "id": 3,
        "hasIdId": 3,
        "$isGET": true
    },
    "$sqlparams": {
        "id": 3,
        "hasIdId": 3
    },
    "$template": "hasId"
}

payload,$request,$sqlparams are all Dictionary<string,object>

Expected output from this should be that the template renders

select 'TruePath' [Path],@id [id]
###params###
id

instead it renders:

select 'FalsePath' [Path]
###params###

Edit again:
Here is the test simplified into a single failing statement.

Render.StringToString(@"{{#a.b}}{{#a.c}}I should render.{{/a.c}}{{/a.b}}", new Dictionary<string, object> { { "a", new Dictionary<string, object> { { "b", 3 }, { "c", true } } } })

Trymustache.com renders this correctly even when I just use this as my json

{
    "a":{"b":3,"c":true}
}

Also this case was working in 1.13.6.20

Nustache Key's Cannot Contain a Period "."

I'd like to be able to have a JSON data file that looks like:

{
"Namespace.Key1": "firstValue",
"Namespace.Key2": "secondValue"
}

This is valid JSON, but it will not render because of the "." in the key. We are using this for configuration values across hundreds of projects. Namespaces provide a very nice way of organizing the Nustache keys in the data file. Do you think this is functionality you would be willing to support?

StringToString Help

This test I wrote is failing. My goal is to take two strings and have it render like the demo on http://mustache.github.com/#demo ; I want to do this without using a file. I'm not sure what the format of the string is supposed to be if it isn't in JSON. output in this example returns string.empty. Or do I need to do use another method?

[Test]
public void Sean_string_string()
{
var output = Render.StringToString("{{#foo}}{{cid}}{{/foo}}", "{"foo":[{"cid":123},{"cid":456}]}");
Assert.AreEqual("123 456", output);
}

Encoder encodes foreign languages improperly

Just if you try in MVC3.example

DoModelPropertiesWork = "Model properties work! größten europäischen | Привет, как дела"

You will get in HTML-code:

Model properties work! gr&#246;&#223;ten europ&#228;ischen | &#1055;&#1088;&#1080;&#1074;&#1077;&#1090;, &#1082;&#1072;&#1082; &#1076;&#1077;&#1083;&#1072;

Which is bad for SEO.

nonblocking API

I'm kinda unhappy with the API.
It is designed from the ground up to block and it doesn't make me happy :(

I would like to see something Template::Render(string source, object objs, StringWriter writer), where source is just the plain simple text and everything gets written into writer.

Maybe there is some similar API like that?
Could you enlighten me?

Using Model & sharing templates, ugliness

The current way to access model properties in templates is {{Model.SomeProperty}}, which seems appropriate because it follows the convention that Razor templates use. However, this requires mustache templates to either have the Model. prefix on every property, or a {{#Model}} block around the template. Now this isn't so bad, except for when I need to share my templates between server / client, in which case I must have a root "Model : ... " property in my JSON data, as well as in my client template.

To avoid this ugliness, I suppose that I could just use ViewBag properties, but I like the idea of being able to just send one class as the model (it works well with the way I use automapper). Plus, using the ViewBag/ViewData just feels wrong :).

It would be a quick change to change (back) the way Model properties are accessed in templates, and I think I'll do so for myself, but I just wanted you to to be aware of this (IMO, valid) reason to break the convention that Razor sets.

rendering properties which have leading or trailing space in markup

Hey,

Nustache doesn't seem to render {{ propertyName }} (space before & after property name) but does render {{propertyName}} (no spaces). Was this a designed behavior? It would be nice if spaces can be present for readibility & also the JS renderer works just fine with spaces.

Thank You,
Vish

Can't use with client profile

The .NET client profile doesn't include System.Web, so the dependency on it from Nustache.Core prevents me from using Nustache in an app targeting the client profile.

Near as I can tell, the only usage is in Nustache.Core.VariableReference, which calls HttpUtility.HtmlEncode.

Any thoughts on removing the System.Web dependency from Nustache.Core?

Set Delimiters do not work

Set delimiters do not seem to work in Nustache

According to mustache.js set delimiter tags start with an equal sign and change the tag delimiters from {{ and }} to custom strings.

    {{default_tags}}
    {{=<% %>=}}
    <% erb_style_tags %>
    {{dontrender}}
    <%={{ }}=%>
    {{render}}

When rendered in nustache {{dontrender}} is still replaced, while it should just output {{dontrender}}

How do i render Dictionary<string,string>

Hi J,
Since NameValueCollection did not work with Nustache, i decided to stick to Dictionary<string,string> surprisingly it does not understand how to render them too. Have a look at this

        Dictionary<string, string> testKeyValuePair = new Dictionary<string, string>(4);

        for (int dictionaryCount = 0; dictionaryCount < 4; dictionaryCount++)
        {
            testKeyValuePair.Add("Key:" + dictionaryCount, "Value:" + dictionaryCount);
        }

        string output = Nustache.Core.Render.StringToString("{{#.}}{{.}}{{/.}}", testKeyValuePair);

nested partials

Hello,

I'd like to use Nustache in combination with Razor. Razor would be responsible for most of my views, but I would use Nustache for specific templates that I wanted to render on both the client and server.

When I wire Nustache in as a secondary view engine:

    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterRoutes(RouteTable.Routes);
        ViewEngines.Engines.Add(new NustacheViewEngine());
    }

and then attempt to render any partials (either Mustache or Razor), it throws the following:

    The property 'PartialViewLocationFormats' cannot be null or empty. 

Add Nustache.Core.dll as download

Hi,

could you please add the binary as download on GitHub? I mean, I just want to download this thing and start working without having to install NuGet or download the complete project and build it. I guess it's common to add recent builds to a project.

Thank you.

Is the Template class thread-safe/reusable?

I'm calling Render.FileToString a lot in an asp.net environment and was wondering if it would be possible to cache the parsed template in the asp.net cache (with a FileDependency). Is the Template class considered to be thread-safe enough to be rendered by several threads simultaneously, or do I have to write my own wrapping items which enforces only one Template per thread?

Wrong behaviour on property = null

Hi. Using nustache on commercial proejct and sharing templates between client and server, which is really nice. Makes AJAX-application completely SEO-friendly. Anyway...

Say, we have this model:

namespace Nustache.Mvc3.Example.Models
{
    public class Parent
    {
        public Parent()
        {
            Children = new List<Child>();
            Children.Add(new Child("Jessica"));
            Children.Add(new Child("John"));
        }



        public string Name = "Mr. Freeman";
        public bool IsParent = true;
        public List<Child> Children;


    }

    public class Child
    {
        public Child(string n)
        {
            Name = n;
        }


        public string Name { get; set; }
        public bool? IsParent = null;

    }
}

And template like this:

Name: {{ Name }}<br />
IsParent: {{#IsParent}} yes {{/IsParent}}<br />

Children:<br /><br />

{{#Children}}
Children name: {{ Name }}<br />
IsParent: {{#IsParent}} yes {{/IsParent}}<br />
{{/Children}}

Output is:

Name: Mr. Freeman
IsParent: yes
Children:

Children name: Jessica
IsParent: yes                      <<<<
Children name: John
IsParent: yes                      <<<<

This means, that when IsParent property of children equals null, Nustache somehow performs fallback to IsParent property of original main object. Which it should do only if there is no property at all.

When IsParent of children is true and false - everything is as expected. JS library does the same thing.
When IsParent of children is null - MustacheJS acts like it is false, which is what we need, I think, and Nustache goes to property with same name on higher-level object.

This is a difference, which makes sharing templates a bit complicated.
Please, fix this.

Localization support for .net

Seem there is not way to implement localize content via the template. Tried using razor chtml and .aspx, both renders statically without dynamically data.

Anyone have this issue?

Non-valid tags in IE8

I need to retract this. After testing some more, I was able to break it in IE8 with the original markup. I'm not really sure what I did before, but I believe this to be a non-issue. Sorry.
I will leave my original post below even though I am embarrassed.

I am working on a non-MVC web application project that is heavy on unordered lists. In the process, I am using 'lh' tags for list headers. I understand this is not valid markup and I may get blasted for it, but here is the issue.
Previous to using Nustache, the markup was spit to the page from a handler with markup like so:
<ul>
<lh>
<div>Some Text</div>
</lh>
<li>A list item</li>
<li>Another list item</li>
</ul>

This worked fine in Firefox, Chrome, IE9 and IE8.

Since switching to Nustache, only IE8 is rendering wrong. All other browsers render correctly.
The result in IE8's inspector renders like so (only the lh is broken):
<ul>
<div>
Some Text
</lh/>
<li>
A list Item
<li>
Another list Item

It seems to be breaking the 'lh' tag. I have stepped through with the debugger, and I do not see any difference in the markup prior to IE8 rendering it. Please keep in mind that before Nustache, this markup rendered perfect in IE8

Here is my template:
<ul>
<lh>
<div>{{ColumnHeader}}</div>
</lh>
{{#Items}}
<li>{{Item}}</li>
{{/Items}}
</ul>

I have tried removing the white-space out of the template already with no luck.
Are there any thoughts on this or does Nustache not support non-valid tags?
Why does it render correctly in all other browsers?
(sorry if I have made this hard to read :s)

RenderContext treats values of type IDictionary<K, V> as lists rather than hashes

Nustache's RenderContext treats values of type IDictionary<K, V> as lists rather than as hashes/objects because IDictionary<K, V> does not implement IDictionary.
RenderContext.GetValues(String) needs another "if" statement to check for IDictionary<K, V>.

Note that this problem will not manifest when the runtime type of the value in question is Dictionary<K, V> because Dictionary<K, V> also happens to implement IDictionary!

Rendering DataTable

Hi,

I cannot seem to be able to render a datatable, can anyone please provide an example for what the place holders in mustache need to be?

Thanks

Unclosed Tag Throws System.IndexOutOfRangeException

I've been finding some great uses for Nustche. Its a great library. I did find an odd error.

Given the following template:

{{=% %=}}
%Value%
%

%Value%

Nustache throws an IndexOutOfRangeException

The Mustache.js library returns "Error: Unclosed tag at 29"

Any way this could be handled more gracefully?

Thanks!

Using with datatable

I Need Use it with datatable to load ul>li
My Template is

    {{#Item}}
  • {{Name}}
  • {{/Item}}

Rendering Name Value collections

Having a class Company that contains method GetWorkers that returns a type of NameValueCollection. Is this the correct way i invoke the method? How do i access name ,* value* for each entry in the NameValueCollection

{{#.}}Workers for this company {{GetWorkers}} {{/.}}

actually i wanted to render these workers in ul, li tags.

Rendering a Func

Consider the following snippet:

Nustache.Core.Render.StringToString("{{ foo }}, {{ bar }}", new {
            foo = "bar",
            bar = new Func<string>( () => {return "foo";} )
});

//Result:  "bar, System.Func`1[System.String]"

Rather than literally calling .toString() on the Func, should it instead invoke it and call .toString() on the results, similar to how if this was a normal class that contained a method "bar"? This was tested on the version of Nustache available from NuGet.

Double and triple mustaches

In mustache.js they use triple mustaches to render unescaped content:

All variables are HTML-escaped by default.
If you want to render unescaped HTML, use the triple mustache: {{{name}}}.
You can also use & to unescape a variable.

Triple mustaches in Nustache don`t work.
Since I share templates between client and server, this forces me to use double mustaches everywhere, and I get unneccesary HTML-escaping of data, which is already escaped (in database).

It would be great if triple mustaches for unescaped data worked in Nustache as well.

XML Parsing Help

For some reason, I can't get this test to pass.

    [Test]
    public void Sean_RenderXMLContent()
    {
        string XMLContent = @"<group><couponid>123</couponid><couponid>124</couponid></group>";
        string template2 = @"{{#group}}{{couponid}}{{/group}}";
        string expectedHTML = @"123124";
        XmlDocument doc = new XmlDocument();
        doc.LoadXml(XMLContent);
        object data = doc.DocumentElement;
        var output = Render.StringToString(template2, data);
        Assert.AreEqual(expectedHTML, output);
    }

Any ideas what I'm doing wrong?

support nested objects notation in nustache

You can use the dot notation to access object properties in Mustache but this not work in Nustache and force us to use dereferencing (not very clean and more verbose).

now:

<tr>
    <td>
        {{#question}}{{Description}}{{/question}}
    </td>
    <td>
        {{#result}}{{Answer}}{{/result}}
    </td>
</tr>

after:

<tr>
    <td>
        {{question.Description}}
    </td>
    <td>
        {{result.Answer}}
    </td>
</tr>

Itterating over a list overrides variables with the same name, but in a different scope

Using this example data:
{ Id: 5, List: [ { Id: 1 }, { Id: 2 }, { Id: 3 }, ] }

to rendering the following template:
{{Id}}
{{#List}}{{Id}},{{/List}}
{{Id}}

Should result in the following:
5
1,2,3,
5

But instead results in the following:
5
1,2,3,
3

This issue appears across templates and is especially a problem when uses two lists one inside of the other.

My template works in Mustache, not in Nustache

I am having trouble getting a Template to work, tried a bunch of things but am close to going crazy:

<h1>{{Title}}</h1>
{{{Body}}}
{{#Weeks}}
    <h2>{{Title}}</h2>
{{#Events}}
    <h2>{{Title}}</h2>
    {{#IsAllDayEvent}}
        <span class="IsAllDayEvent">Evenement duurt gehele dag</span>
    {{/IsAllDayEvent}}
    {{^IsAllDayEvent}}
        <span class="StartDateTime">Van: {{StartDate}} - {{StartTime}}</span>
        <span class="EndDateTime">Van: {{EndDate}} - {{EndTime}}</span>
    {{/IsAllDayEvent}}
    <span class="Location">{{LocationDescription}}</span>
{{/Events}}
{{^Events}}
    No events found in {{Title}}
{{/Events}}
{{/Weeks}}
{{^Weeks}}
    Weeks not found!?
{{/Weeks}}

This template works perfectly when tested on http://trymustache.com/
With the following JSON:

{
"Weeks": [
  {
    "Title": "week 26",
    "Events": [
      {
        "HeadingID": "L121",
        "Url": "/118/opleiding-3/",
        "Title": "Opleiding 3",
        "MoreLink": null,
        "LinkRelation": null,
        "LinkTitle": null,
        "LinkText": null,
        "StartDate": "29 juni 2013",
        "StartTime": "11:12",
        "EndDate": "03 juli 2013",
        "EndTime": "11:12",
        "LocationDescription": "",
        "Summary": "",
        "LinkUrl": null,
        "Class": "event",
        "IsAllDayEvent": false,
        "IsRepeatedOcurrence": false,
        "MainEventUrl": "#L121",
        "Event": null
      }
    ]
  }
],
"CalendarModel": null,
"Body": "<p>Deze pagina heeft gelukkig ook nog een Body :)</p>",
"Title": "Opleidingen",
"Summary": "Deze pagina heeft gelukkig ook nog een Body :) ",
"InfoType": "Calendar"

}

But the problem is that it returns Weeks not found!?
Any ideas why this isn't working in Nustache, but does in Mustache?

context of the lambda function

When you have a lambda, is there a way to get access to the current context object?

Imagine:

var model = new {
    RefDates = new System.DateTime[] {}
};

Is there a way to do this without wrapping the DateTime objects?

{{#RefDates}}
    <th>{{! each date formatted M/d/yy}}</th>
{{/RefDates}

My initial try was this:

{{#RefDates}}
    <th>{{#ToString}}M/d/yy{{/ToString}}</th>
{{/RefDates}}

which did not work as it seemed to call ToString on DateTime immediately and returning the result, ignoring the inner content.

In current implementation of Nustache, there doesn't seem to be a scoped render function available, although I'm not sure if I'll be able to solve my problem with it either.

Or perhaps what I'm trying to do is completely against the philosophy of mustache (Logic-less).

Need caching around GetTemplate

I think you know this already based on the comments in the code, but after running some performance test, definitely need caching in GetTemplate method of NustacheView.

Something like this :

    private Template GetTemplate(string path)
    {
        if (_controllerContext.HttpContext.Cache["tmp_" + path] != null)
        {
            return (Template)_controllerContext.HttpContext.Cache["tmp_" + path];
        }

        var templatePath = _controllerContext.HttpContext.Server.MapPath(path);

        var templateSource = File.ReadAllText(templatePath);
        templateSource = Razor.Parse(templateSource, new { Request = _controllerContext.HttpContext.Request});

        var template = new Template();
        template.Load(new StringReader(templateSource));

        CacheDependency dep = new CacheDependency(templatePath);

        _controllerContext.HttpContext.Cache.Insert("tmp_" + path, template, dep);

        return template;
    }

Encoding error, Not supports CJK ?

When I have a lot of data in CJK coding, {{{ is not works, the result become to the HTML encode.

And it is possible to turn off the convert to the HTML encode ?

Helpers not available via NuGet Package

I was trying to access Helpers class via NuGet assembly reference to Nustache.Core but that class seems to be missing. However downloading and compiling the source works fine.

Is the NuGet Package at the latest version (I was using 1.13.8.22)?

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.