Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
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 ..
I am looking for a way visit only the blocks of the template.
Matthias Dittrich
@matthid
@h3xstream No, currently there is no easy way. The generated code depends on RazorEngine so it might not be as useful as you might assume... What do you mean by "blocks"?
Philippe Arteau
@h3xstream
@matthid I meant nodes of the template. HTML, code and possibly code instructions.
(But are not exposed publicly)
Matthias Dittrich
@matthid
You might want to use Razor directly (without RazorEngine), we might provide API in the future to get the source code (and transform it with Roslyn), but never such a visitor API... The reason is quite simple: First we at RazorEngine try to abstract away the concrete Razor version for you. And secondly Razor 4 is changing dramatically and maintaining such an API is an additional headache...
You can however look into the RazorEngine source code to get an idea how to use the Razor classes (see DirectCompilerServiceBase for example)
Richard Bogle
@Boggin
I've been trying to implement the MvcTemplateBase<> as shown in Issues #26 and #29 but I get a null for the HttpContext.Current and I can't figure out why. I'm using the fluent config to set the BaseTemplateType = typeof(MvcTemplateBase<>). Is this going to work or have I got lost! RazorEngine v.3.7.2
Richard Bogle
@Boggin
Hang on. WebAPI ...
Nikola Sivkov
@aviatrix
hey @matthid , are you around ?
Matthias Dittrich
@matthid
Hey, yes whats up?
Nikola Sivkov
@aviatrix
Can you tell me if you recall, in versions prior to 3.5 did RE store the compiled templates on disk or in memory ?
Matthias Dittrich
@matthid
In memory (which has some downsides), but you can still to it with DisableTempFileLocking (so I basically changed the default)
Nikola Sivkov
@aviatrix
i have a theory on why using linq methods on dynamic properties blows up now and it didn't before
ah, i see
Matthias Dittrich
@matthid
why would it matter on linq methods?
Nikola Sivkov
@aviatrix
something to do with parts of anon/dynamic objects being internal
and since they are stored outside of the memory now, they are different assembly
and executing assembly not being able to see the internal stuff and blowing up