Giter VIP home page Giter VIP logo

Comments (6)

jehugaleahsa avatar jehugaleahsa commented on June 27, 2024

Unfortunately, the library doesn't accept string or numeric constants. In the future, perhaps someone with a little more programming language theory under their belt can help out. Right now, I have a recursive descent parser doing all the work. If you take a look at the code base, the parsing and the processing are clumped together. It will be difficult to extend the language until I can separate those responsibilities.

In the meantime, the trick is to add to your model, generating properties for each of these comparisons. For instance, adding properties IsMainCategory and IsOverBudget.

from mustache-sharp.

PaulGrimshaw avatar PaulGrimshaw commented on June 27, 2024

Could this not work using a variation of your "Set" tag? Or by using a special character to parse the string/numeric value, such as {{#is amount #gt @200}} or so? Take your point about extending the model, but what i like about this library is it negates the need to form ViewModels etc...

Alternatively, would it be possible to build something with custom tags, using reflection to get the variable names? http://stackoverflow.com/questions/9801624/get-name-of-a-variable-or-parameter gets me thinking...

Any guidance would be much appreciated... afraid I don't have the know how or guts to dive in and change your code (yet!).

from mustache-sharp.

jehugaleahsa avatar jehugaleahsa commented on June 27, 2024

I could see a tag called #gt that took two variables: {{#gt amount @max}}.
Such a tag wouldn't be that hard to create. You could look at the code for
ConditionalTagDefinition and just override the ShouldGeneratePrimaryGroup
method.
On Feb 3, 2014 7:15 PM, "Paul Grimshaw" [email protected] wrote:

Could this not work using a variation of your "Set" tag? Or by using a
special character to parse the string/numeric value, such as {{#is amount
#gt @200 https://github.com/200}} or so? Take your point about
extending the model, but what i like about this library is it negates the
need to form ViewModels etc...

Alternatively, would it be possible to build something with custom tags,
using reflection to get the variable names?

Any guidance would be much appreciated... afraid I don't have the know how
or guts to dive in and change your code (yet!).

Reply to this email directly or view it on GitHubhttps://github.com//issues/17#issuecomment-34017196
.

from mustache-sharp.

PaulGrimshaw avatar PaulGrimshaw commented on June 27, 2024

This is great, got me well along the way and have successfullly made an {{#eq OneValue AnotherValue}} tag. Will complete the set with {{#gt OneValue AnotherValue}}, {{#gte...}}, {{#ls...}}, {{#lse}}. Will build in "{{#else}}" for all of them too.

Forked onto my GitHub profile, feel free to bring changes back in if you feel they'll be useful.

from mustache-sharp.

PaulGrimshaw avatar PaulGrimshaw commented on June 27, 2024

So now with that all running, could you give me any pointer as to how i might get a value straight from the template into a tag, without first feeding it into the model?

var model = new {Amount = 30, Limit = 31};
var format = {{#gt Amount Limit}}Over Limit!{{/gt}}

The above is working great. However I'd really like my users to be able to enter the limit into the template somehow...

 var model = new {Amount = 30};
 var format = {{#gt Amount 31}}Over Limit!{{/gt}}

or

 var model = new {Amount = 30};
 var format = {{#gt Amount @31}}Over Limit!{{/gt}}

or

 var model = new {Amount = 30};
 var format = {{#gt Amount ?31}}Over Limit!{{/gt}}

Any possible direction pointers?

from mustache-sharp.

PaulGrimshaw avatar PaulGrimshaw commented on June 27, 2024

Ok, I've made this work in the following manner, and any value, string or number can be written directly into the placeholder by prefixing with "_" (any idea of a better symbol are welcome, as the ideal one "@" is taken...)

Examples:

 var model = new {Amount = 30};
 var format = "{{#gt Amount _31}}Over Limit!{{/gt}}"

 var model = new {ViewId = "vid876"};
 var format = "<a class="{{#eq ViewId _vid876}}active{{/gt}}">home page</a>"

All available here https://github.com/PaulGrimshaw/mustache-sharp

FYI I did this simply by adding two lines to the "ArgumentCollectionCode.cs", in the "GetArguments(...)" method:

....
            if (pair.Value == null)
            {
                value = pair.Key.DefaultValue;
            }
            else if (pair.Value.StartsWith("@"))
            {
                value = contextScope.Find(pair.Value.Substring(1));
            }
            //ADDED THIS:
            else if (pair.Value.StartsWith("_")) {
                value = pair.Value.Remove(0, 1);
            }
            //END OF ADDITION
            else
            {
                value = keyScope.Find(pair.Value);
            }
            arguments.Add(pair.Key.Name, value);
        }
        return arguments;
....

from mustache-sharp.

Related Issues (20)

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.