Saturday, October 22, 2005

Using Nemerle and Boo in ASP.NET

Mono aims to be a really multi-language platform. And as way to check it, we will learn how to include Boo and Nemerle scripts (from my two favorites languages :-) inline in ASP.NET pages, that can be used then with XSP, mod_mono or even IIS, I think.
First of all, in your machine.config file or web.config one, depending if you want a global change or a per-web application change, locate a section called <compilation> or <compilers>. The Nemerle.Compiler or Boo.CodeDom assemblies should be in the GAC, so it can be easily located. However, you can also add a directive into the <assemblies> section of web.config; (this is recommended for Boo). The directive should look like
<add assembly="Boo.Lang.CodeDom" />
Finally, in the compilers section, you must add this for Nemerle:
<compiler language="n;nemerle;Nemerle" extension=".n" warningLevel="1" compilerOptions="" type="Nemerle.Compiler.NemerleCodeProvider, Nemerle.Compiler, Version=0.9.0, Culture=neutral, PublicKeyToken=5291d186334f6101" />
or this for Boo:
<compiler language="Boo" extension=".boo" type="Boo.Lang.CodeDom.BooCodeProvider, Boo.Lang.CodeDom" />
From then, you can use Nemerle or Boo direclt in ASPX pages just changing the Language directive on Page to "Boo" or "Nemerle". This is the "Hello World!" ASPX page that comes with Boo examples:
<%@ Page Language="Boo" %>
<script runat="server">
def Page_Load(Sender as Object, E as EventArgs) :
  HelloWorld.Text = "Hello World From Boo in ASP!"
</script>
<html>

<head>
<title>ASP.NET Hello World</title>
</head>
<body bgcolor="#FFFFFF">
<p><asp:label id="HelloWorld" runat="server" /></p>
</body>
</html>
and this is the same in Nemerle:
<%@ Page Language="Nemerle" %>
<script runat="server">
Page_Load(_ : object, _ : EventArgs) : void {
  HelloWorld.Text = "Hello World From Nemerle in ASP!";
}
</script>
<html>

<head>
<title>ASP.NET Hello World</title>
</head>
<body bgcolor="#FFFFFF">
<p><asp:label id="HelloWorld" runat="server" /></p>
</body>
</html>

As you can see, using C#, VB or Nemerle is just a matter of a directive. Now you can start even coding your AJAX applications in Boo!

0 Comments:

Post a Comment

<< Home