Comments (6)
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.
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.
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.
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.
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.
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)
- If ... Or ... HOT 2
- ConditionTagDefinition HOT 2
- Remove line hop on unix systems HOT 7
- Library doesn't work with dynamic object
- JToken HOT 1
- Escaping string for json templating HOT 2
- Creation of a custom tag HOT 2
- {{ }} around property with spaces in the name HOT 2
- adding padding spaces to an identifier HOT 3
- Calculation in identifier HOT 1
- Exception 'After parsing a value an unexpected character was encountered' is raised for properties containing single braces or empty strings HOT 3
- Redundancy and differencies with mustach spec making it not compliant.
- IF does not work when using JOject HOT 3
- Removal of newlines in HtmlFormatCompiler actually causing a problem HOT 1
- Help creating custom tag HOT 1
- {{#if}} does not work with JObject
- how i add if condition like {{#if condition == true}} {{do somthing} {{/if} mustache sharp HOT 1
- Invalid handlebarsjs else tag
- Rendering of template simply doubles each {{#newline}} HOT 1
- Is it a safe assumption that this project is dead? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mustache-sharp.