foundation / panini

A super simple flat file generator.
Other
592 stars 104 forks source link

Razor .cshtml support #150

Closed ukozdan closed 6 years ago

ukozdan commented 6 years ago

I work in a large team (20) with both on and off-shore developers and a relatively high staff turn-over. This puts pressure on us to enforce standards automatically rather than through documentation. This can be achieved for CSS, JavaScript and images easily with Gulp. However, working with Visual Studio presents a problem. Razor templates are not rendered as static pages within the project, hence full page HTML validation, such as W3C, Bootlint and accessibility, cannot be performed by Gulp within the project.

Usual practice is that .NET developers use the Gulp (Panini) generated templates as a reference for their Razor templates. However, this is a manual process and not something that can be enforced automatically and so the two can sometimes become out of sync.

I would really like to use Panini on Razor templates (.cshtml) so that the normal Visual Studio build occurs, but static HTML pages are also simultaneously compiled from it locally so that I can perform whole page validations. Currently, Panini and Handlebars do not recognise files with the .cshtml extension.

Perhaps it could be as simple as ignoring anything that is not Panini/handlebars syntax, so that Razor/C# syntax is preserved. Regardless, I think this would fill a hole in .NET development; unless, of course, I have completely missed a trick.

ukozdan commented 6 years ago

Thinking about it; Razor templates wouldn't work with Panini without converting their directives to handlebar type directives.

gakimball commented 6 years ago

Thinking about it; Razor templates wouldn't work with Panini without converting their directives to handlebar type directives.

Yeah, Panini is for static sites, so it's not going to mix well with a templating engine designed for server-side code. Converting an AST of one engine's template to another would be pretty difficult also, I think.

Perhaps it could be as simple as ignoring anything that is not Panini/handlebars syntax, so that Razor/C# syntax is preserved.

Looking at the Razor syntax, I don't see what would overlap with Handlebars. In particular, I don't see anything that uses the double curly brace syntax.

What you're describing doesn't seem to be within the scope of Panini. It sounds like you're doing some kind of end-to-end testing, where you generate final HTML pages that your server would render, and then lint them in various ways. Is that right? If so, there might be other ways to do that sort of analysis. It seems like the tests would be simpler and more accurate if you were testing pages rendered by the server itself, instead of testing recreations made by another library.

ukozdan commented 6 years ago

Thanks for your comment. Yes, I wanted to do validation that requires whole rendered HTML pages, but also to enforce the correction of errors, which things like intellisense don't do. It's just annoying that I can validate my CSS, JavaScript, images and fonts with Gulp within Visual Studio 2017, but not whole rendered HTML pages. Maybe there's a DOM in memory solution.

gakimball commented 6 years ago

Yeah, I think doing something end-to-end like this is not going to be doable in the editor environment. Like, when I work on this library, I can lint all the code statically in the editor, but to make sure it's functioning properly, I go to my command line and run the unit tests.

You might look into testing libraries that can make an HTTP request and then give you the contents. For example, in Node land, there's a library called superagent that you can use to test the routes of an Express server. In your testing environment, you spin up the server locally, ping a route, and then read what the server gives back and see if it's what you expect.

I don't know anything about what's available in the ASP.NET ecosystem, but I think you'd want something closer to what I've described above. Panini isn't going to help much here because (1) it can't render anything from your server (2) it can't render Razor templates.

ukozdan commented 6 years ago

Cheers; I'll look into your suggestions.