AspNetMonsters / pugzor

A drop in replacement for the Razor view engine using pug
MIT License
92 stars 16 forks source link

Continuation of this project #25

Open mavanmanen opened 7 years ago

mavanmanen commented 7 years ago

It seems this repo is currently stale and not updated anymore. Out of personal interest I would love to help maintain and develop this repo. I think with the inclusion of features such as being able to use C# directly in the code would really make this a viable alternative to cshtml razor views, something I think is definitely doable and asp.net developers who also love pug would definitely love to use.

ku3mich commented 7 years ago

such as being able to use C# directly in the code I thought a lot about this and there is what I think:

Yes this is possible. For example it can be C# code plus some sort of pre-rendering pug that translates C# code into some callback with id, from other side there is an a dictionary<id, Func> in PugRendering class

.a(href='/') @{ DateTime.Now } will be .a(href='/') #{callback('func0') } => passed to pugCompile plus CodeDictionary["func0"] = (Func) () => DateTime.Now; <= invoked by NodeServices via callback

Need to investigate if it is possible using NodeServices, but I think it does.

From other side Pug is great template/rendering engine I admire how views becomes small, easy to read and elegant.

Why not to build own same way as was build Razor engine?

mavanmanen commented 7 years ago

Well the idea I had is something which is definitely possible, as @ has no special meaning in pug, it will be rendered as entered, thus if you first put the view through the pug renderer and then through the razor renderer, the code will be executed as you would expect.

ku3mich commented 7 years ago

as @ has no special meaning in pug

does not make sense due we need pre-process pug/razor hybrid and pass a clear pug with callbacks into pugCompile. Only one issue: if it is possible to communicate to C# more than just one final callback. I'm investigating this now and will give an answer in hours.

ku3mich commented 7 years ago

the result: no, I see no way to get more than one, final callback using NodeServices(maybe it is possible with Edge.js but this does not metter).

Instead of it we can do this other way:

  1. Pre-process razor and extract C# code
  2. Make a dictionary [codeId, func<Model, T>]
  3. Execute all needed code from dictionary and rebuild pug with results
  4. Pass final pug into pugCompile

notes: we need cache pre-porcessing(also seems caching of pug is open issue, isn't it?)