Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Vladimir Shmidt
@vladimir-shmidt
probably part of application
we generate source via razor temapltes
sorry for misspell
that razor templates already complied with RazorGenerator tool
Matthias Dittrich
@matthid
well yes it looks over engineered, but on the other hand you could provide your implementations and other people can use it without changing their usage code (only the setup/config), which is a good thing considering the complexity here.
Vladimir Shmidt
@vladimir-shmidt
good point
thanks
Matthias Dittrich
@matthid
and again getting it work bug-free without pitfalls by using ITemplate is almost impossible ;)
Vladimir Shmidt
@vladimir-shmidt
than can toy suggest something else?
*you = toy
Matthias Dittrich
@matthid
what you do now (using the interfaces) should work
*new interfaces
If you run into problems feel free to ask here and wait for an answer or open a new issue on github
Vladimir Shmidt
@vladimir-shmidt
ok try to do and maybe try to request changes :)
Matthias Dittrich
@matthid
Sure. Btw generating the templates as part of the build and including them as resources sounds like a really nice idea! If there is a chance to contribute this back I would gladly help with the integration part, I think quite some people would like to have this :) (as part of RazorEngine or a separate NuGet package)
Vincent Baaij
@vnbaaij
I was looking around for the difference between 3.7.0 and 4.2.0. Can't find it. Does anyone have a link to more info. tia
hoborg91
@hoborg91
Hello. I would like to convert my Razor templates (e. g., in ASP.NET MVC) to JavaScript template functions. For that purpose, I suppose that one should analyze ParserResults which is being returned by ParseTemplate method. Here I am confused by the message saying "This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.". This message goes with all methods and classes necessary for the syntax tree analysis. Therefore I have a question: is there a better way to achive the declared target (to make JS of a Razor) or, if not, why does not RazorEngine freely expose techniques for the syntax tree analysis?
Matthias Dittrich
@matthid
@vnbaaij The only difference is that one is build against Razor4 (4.X) and one against Razor3 and Razor2 (3.X).
Matthias Dittrich
@matthid
@hoborg91 Sorry but its not very clear for me what you are trying to achieve. But you may be mixing up (Microsoft.AspNet.)Razor and RazorEngine. Razor handles the Razor-Template to C# code transformation and RazorEngine handles the rest: C# -> Assembly compilation and loading. IIRC ParserResult is a CodeDom generated C# code for Razor2/3 and some Razor specific stuff in Razor4. So one reason we cannot expose it is because there is no unified way to expose it (RazorEngine "sees" only the C# code as a whole). Can you please give an example of what you want to do?
hoborg91
@hoborg91
@matthid Thank you for the response. The example is the following.
Given the file (or string) containing @model M <h2>@Model.Name</h2> @foreach(var x in Model.Parts) { <div>@x</div> }. Besides that I need to produce a common HTML (e. g., <h2>A</h2> <div>a</div><div>b</div> for model { Name = "A", Parts = new[] { "a", "b", }, }), I would like also get some template proper for JavaScript compilation. For this example it may be a JavaScript function m(Model) { var result = "<h2>" + Model.Name + "</h2>"; for(var i = 0; i < Model.Parts.length; i++) { result += "<div>" + Model.Parts[i] + "</div>"; } return result; }. Or it may be an HTML filled with tokens of one of the JavaScript templating frameworks: <h2><% Model.Name %></h2> <% for(var i = 0; i < Model.Parts.length; i++) { %> <div> <% Model.Parts[i] %> </div> <% } %>.
In the first case I will supply JSON model to the function and it will produce the same HTML as was produced after Razor template rendering. In the second case I would first compile the given template with appropriate JavaScript framework, obtain the similar JavaScript function and do the same thing.
So in general I would like to convert a template marked with one syntax (Razor) to a template marked with another syntax (e. g., http://underscorejs.org/#template ).
Matthias Dittrich
@matthid
I don't think this is "doable" in general, you need to consider that you can write any C# code in a Razor template, so you need to be able to convert any C# code to javascript code (or the <% %> thing). You may be able to do it for a specific subset by implementing your own ICompilerService in RazorEngine.
Matthias Dittrich
@matthid

That said I probably would suggest a webservice instead, keeping the templates on the server (Razor) and calling that service via javascript instead of a client side templating solution.

I have never heard of somebody doing anything similar so you are probably completely on your own (no need to say that it sounds like a really difficult/impossible thing to do)

hoborg91
@hoborg91

@matthid

any C# code

Since one follows the ViewModel template, usually anything except direct properties access and basic code control constructions (if-else, for, foreach, switch) are not expected. Thus the task is becoming easier.

calling that service via javascript instead of a client side templating solution

You are right, but I would like to minimize the load on the server and transfer some work to the client side. And simultaneously I would like to consider a situation when JS is blocked by the client.

never heard of somebody doing anything similar

I have found the project https://github.com/jchadwick/RazorClientTemplates, but it is abandoned by the main contributor and thus it is obsolete.

So, I intend to inherit from RazorEngine.Compilation.CompilerServiceBase and implement... yet do not know what. Would you be so kind to point me to the reference or say what should I do after implementation? I have expected some parser class where an instance of type ICompilerService must be supplied. Am I correct?

Matthias Dittrich
@matthid

Ideally you want to intercept somewhere near: https://github.com/Antaris/RazorEngine/blob/master/src/source/RazorEngine.Core/Compilation/CompilerServiceBase.cs#L356

And the cleanest thing to do would be to create your own "RazorCodeLanguage" class, which outputs JS instead of C# (but that's probably more work than to simply walk over the C# tree) and change the property here: https://github.com/Antaris/RazorEngine/blob/master/src/source/RazorEngine.Core/Compilation/CompilerServiceBase.cs#L107.

You should start by compiling from source and marking the methods you want to overwrite as virtual (if needed) and implement what you are trying to achieve. I would certainly accept a pull request later on. You should figure out exactly what you want to do and what you expect after compiling a template. The C# code? the JS Code? both? And how to integrate that with the remaining architecture of RazorEngine (for the start it is probably enough to have a CompilerService that outputs JS and run it standalone whenever you need it)

hoborg91
@hoborg91
@matthid Thanks for the directions. I shall investigate this approach.
Matthias Dittrich
@matthid
Hope it helps :)
ABerg
@ABergBN
Hi matthid,
do you have any experience with the Engine in a wcf service? Are there any advises how to handle the calls? I want to build a service which build me an htmtl/plain text email.
I think there can come up some issues on a concurrent call to the service.
Matthias Dittrich
@matthid
@ABergBN Concurrent calls shouldn't be an issue, RazorEngine "should" be thread-safe. If you run into problems open an issue ;)
Josh
@joshgo
Hi... I'm running unit tests, and for some reason I keep getting "The same key was already used for another template!". However, I'm only calling the RunCompile() once in my test. I have another test where that doesn't happen. Any suggestions? Clear Cache?
Josh
@joshgo
Looking to use this for non HTML templates... I saw you had something called "MarkupParser" to handle non HTML-like pages. Is this still a work in progress, are there docs/examples? Would love to use razor syntax for flat text templates.
Matthias Dittrich
@matthid
@joshgo I think the problem is that you are using the static singleton RazorEngine instance for all your tests, try to create a new instance for every test.
@joshgo No there is no such thing as non-HTML or vanilla XML templates currently implemented. It would be a nice addition and is up-for-grabs (Antaris/RazorEngine#223).
ABerg
@ABergBN
@joshgo For non HTML-like Pages you can use PlanText-tags's Like <text>I'm Plaintext</text>
In my application I use it to generate PlainText Emails.
Matthias Dittrich
@matthid
@ABergBN Yes that works fine up to the point when you include some special html things in your "Plaintext", for example <Link>@(Model.LinkName)</Link> (see linked issue). That's just something to keep in mind. Once you trigger something special tag like this it is really hard to debug.
Richard Bogle
@Boggin
My compiled layout complains of a null httpContext when trying to parse Write(Styles.Render("~/bower_components/ ...
Should I be explicit about the file path?
Should I have the http context?
Richard Bogle
@Boggin
I had removed bundling. Correct include is <link rel=stylesheet href="~/bower- ...
Gopal Chettri
@coddey
Hello :)
what is the minimum .net framework required for Antaris-RazorEngine to work for bulk emails?
Matthias Dittrich
@matthid
Hallo, that would be 4.0 for now
Gopal Chettri
@coddey
@matthid thanks :)
Matthias Dittrich
@matthid
You are welcome
Gopal Chettri
@coddey
@matthid do you have any reference material, how to use antaris-razorengine to send bulk mail?
any blog or article?
Matthias Dittrich
@matthid
Sorry I don't have one in mind right now
Gopal Chettri
@coddey
its ok. @matthid
thankyu
Philippe Arteau
@h3xstream
It there a way to use this parser to parse template without executing them ..