View engine to consider maybe?

9 views
Skip to first unread message

Jordan Earls

unread,
Jan 1, 2011, 2:01:00 AM1/1/11
to manos-...@googlegroups.com
Hello, I've been working on an extremely simple view engine that isn't tied to MVC.

It's a bit rough around the edges right now but I would consider it usable, especially as an alternative to directly quoting HTML in C# code.

I'm waiting for a project page to be created for me over at http://quokforge (soon to be BSDforge and not tied to OS development) and when that comes I'll provide a link.

But it's very simple. The basic flow is this:

Make a `templates/` directory in your project. Stick in the EViewBase.cs and EViewGenerator.tt file.

Make a sample HTML file like (named TestView.html) and put it in the `templates/` directory

<html>
<head>
<title>{=Title=}</title>
</head>
<body>
{@
  SomeNumber as int;
@}
<!--just declare our SomeNumber variable as an integer instead of the default `string` -->
SomeNumber: {=SomeNumber=} <br />
{# //now we are in C# code
if(SomeNumber>10){
  Write("Number is greater than 10!");
}
#}
</body>
</html>

Then run the T4 template engine and it will create EViewGenerator.cs which will contain your template translated to C#

Then to render it from your model(or whatever):

var view=new TestView();
view.Title="Our Test View";
view.SomeNumber=20;
response.Write(view.Render()); //render returns a simple string variable containing your HTML

I made this for a separate project but thinking back to here I knew you guys were in need of a view engine. I wouldn't say it's a complete solution but It's something to consider to make Manos a bit more friendly in this early stage.

Also it doesn't make any references to the System.Web namespaces. In fact, I test it by running it from a console project.

Tell me if you're interested and I'll provide a tarball of the source if I don't already have a project page by then.

--

--Earlz

Earlz

unread,
Jan 1, 2011, 11:21:11 PM1/1/11
to Manos de Mono
Ok, I got a project page finally. http://www.quokforge.org/projects/eview

Also, forgot to mention, this will run under MonoDevelop also.

On Jan 1, 1:01 am, Jordan Earls <hackr9...@gmail.com> wrote:
> Hello, I've been working on an extremely simple view engine that isn't tied
> to MVC.
>
> It's a bit rough around the edges right now but I would consider it usable,
> especially as an alternative to directly quoting HTML in C# code.
>
> I'm waiting for a project page to be created for me over athttp://quokforge(soonto be BSDforge and not tied to OS development)

jacksonh

unread,
Jan 3, 2011, 2:18:37 PM1/3/11
to Manos de Mono

This looks great, quite similar to the view engine I used to have in
Manos. I think Manos will eventually be view engine agnostic, so your
engine will definitely be an option. We'll simply have to write some
tiny binding code.

I like that you used T4, this is one of the things I had been
considering. My original engine just used cecil to generate the IL,
but this would obviously be a little more maintainable.

I'll keep this in mind as I move forward. Congrats on the great work
so far.

Cheers,
Jackson



On Jan 1, 11:21 pm, Earlz <hackr9...@gmail.com> wrote:
> Ok, I got a project page finally.http://www.quokforge.org/projects/eview
>
> Also, forgot to mention, this will run under MonoDevelop also.
>
> On Jan 1, 1:01 am, Jordan Earls <hackr9...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Hello, I've been working on an extremely simple view engine that isn't tied
> > to MVC.
>
> > It's a bit rough around the edges right now but I would consider it usable,
> > especially as an alternative to directly quoting HTML in C# code.
>
> > I'm waiting for a project page to be created for me over athttp://quokforge(soontobe BSDforge and not tied to OS development)
Reply all
Reply to author
Forward
0 new messages