Hackfoofery

Alson Kemp

Archive for the ‘Ruby On rails’ Category

ANNOUNCE: Turbinado V0.2 “Still Ugly”

without comments

More progress on Turbinado. Look! A whole “+0.1″!

Progress continues on Turbinado.  Turbinado can be found at:
 http://www.turbinado.org

The source can be found at:
 http://github.com/alsonkemp/turbinado/tree/master
   (see the /App directory for the code for www.turbinado.org)

New in V0.2:
  * A better "Environment" type (rather than using Dynamics) (-> a 50%
speed boost?  That's unpossible!);
  * A functional early version of an ORM for PostgreSQL (note: still
needs to handle updates; hdbc-postgresql has a bug with sensing
nullable columns);
  * A prettier website;
  * Licensing -> BSD.

Expect V0.3 in the next week or so with:
  * More view helpers;
  * An ORM which handles INSERT/UPDATE...;
  * A little CMS built using the ORM.

Future release:
  * Separate the website out from the framework.  For now, they're
evolving together, so live together. 

Written by alson

November 26th, 2008 at 2:11 am

ANNOUNCE: Turbinado V0.1

without comments

Posted to the Haskell mailing list:

I'd like to announce Turbinado, a very young and raw MVC web framework
for Haskell.  While the framework doesn't exactly copy Ruby on Rails,
it certainly rhymes...  It's very early days for Turbinado, but the
framework is moving along nicely.  There are still issues to be ironed
out and architectural details to be decided, so help/contribution would be
very much appreciated.

Turbinado can be found at:
<a rel="nofollow" href="http://www.turbinado.org/" target="_top">http://www.turbinado.org</a>

The source can be found at:
<a rel="nofollow" href="http://github.com/alsonkemp/turbinado/tree/master" target="_top">http://github.com/alsonkemp/turbinado/tree/master</a>
(see the /App directory for the code for www.turbinado.org)

Turbinado:
* Provides a fast web server (based on HSP; see
<a rel="nofollow" href="http://turbinado.org/Home/Performance%29;" target="_top">http://turbinado.org/Home/Performance);</a>
* Provides a straightforward organization for your website (courtesy
of Rails);
* Uses simple HTML-like templating (courtesy of HSX);
* Is easily extensible (courtesy of an Environment built out of _Map
String Dynamic_, not the most type-safe of beasties; Help!);
* Configurable routing (see Config/Routes.hs).

Turbinado is currently lacking:
* Documentation...
* An easy install...
* A database ORM based on HDBC (visibly incomplete and ugly in
Turbinado/Database/ORM);
* Many more HTML helpers;
* Controllers for partials (lightweight "controls" ala ASP.NET);
* Strong error reporting and handling;
* Lots of functionality and plugins;
* ... the favorite feature that you want to develop for Turbinado ...

Written by alson

November 18th, 2008 at 2:10 am

ASP.NET vs Rails: Controls and Controllers

without comments

Since I’ve used Ruby on Rails quite a bit in the past and since I’m now using ASP.NET, I often find myself doing comparisons between the two frameworks.  Recently, I found myself comparing Rails’ controllers/views and ASP.NET’s controls.  The following is an example of where ASP.NET’s declarative instantiation/configuration of controls worked well.  I’m not sure how I could do the same in Rails.

We had to insert Google Ad Manager code into a number of our web pages with varying numbers of ads on each page.  We really wanted to be able to declaratively configure the controls, so that inserting a <UserControl:GoogleAdManager /> tag or two or three into a page would correctly generate the Javascript to place the ads.  The Javascript for two slots looks something like this:

<script src="http://partner.googleadservices.com/gampad/google_service.js" type="text/javascript"></script>
<script type="text/javascript">
GS_googleAddAdSenseService("publisher-code");
GS_googleEnableAllServices();
</script>
<script type="text/javascript">
GA_googleAddSlot('publisher-code', 'slot1-code');
GA_googleAddSlot('publisher-code', 'slot2-code');
</script>
<script type="text/javascript">
GA_googleFetchAds();
</script>
 
<!-- Goes in the proper location -->
<script type="text/javascript">
GA_googleFillSlot("slot1-code");
</script>
 
<!-- Goes in the proper location -->
<script type="text/javascript">
GA_googleFillSlot("slot1-code");
</script>

Optimally, I’d like to generate that code by placing two controls in my markup:

  <UserControls:GoogleAdManager Slot="slot1" runat="server" />
  <... lots of HTML ... >
  <UserControls:GoogleAdManager Slot="slot2" runat="server" />

Doing this in Rails would be a bit difficult: we only know which ads are being included after we parse the page, but we only parse the page in order to render the page.  We’d really like to know which ads are on the page before we render the page.  In Rails, I think that we’d have to do this by creating an array of ads up in the controller and then rendering them in the View using a helper.  But now the controller is responsible for knowing which HTML elements should be on a page…  So maybe we’d drop all the logic down into Javascript and use Javascript’s implicit page load events to fire the right bits of code at the right time.  Neither of these is pretty.

The key to doing this in ASP.NET is ASP.NET’s page event model in which pages and control go through 3 or so phases before they’re actually rendered.  We wound up breaking the Javascript generation as follows.

In the Page_Load event for each control, we try to insert the following code. Of course, once one control has inserted (“this.Page.ClientScript.RegisterClientScriptInclude”) the javascript, the other control won’t insert it.

<script src="http://partner.googleadservices.com/gampad/google_service.js" type="text/javascript"></script>
<script type="text/javascript">
GS_googleAddAdSenseService("publisher-code");
GS_googleEnableAllServices();
</script>
<script type="text/javascript">

Then on PageLoad each control add its slot code. Control 1:

GA_googleAddSlot('publisher-code', 'slot1-code');

Control 2:

GA_googleAddSlot('publisher-code', 'slot2-code');

On PreRender, each control tries to add the following code to close off the previous script tag and to fetch the ads:

</script>
<script type="text/javascript">
GA_googleFetchAds();
</script>

Finally, each control renders its code into the div. Control 1:

<script type="text/javascript">
GA_googleFillSlot("slot2-code");
</script>

Control 2:

<script type="text/javascript">
GA_googleFillSlot("slot2-code");
</script>

Gotta dip down into C# a bit for the ASP.NET, but the pay-off is a simple declarative configuration of Google’s Ad Manager. I didn’t implement the functionality in Rails, but I suspect that it would be rather more complicated… ASP.NET wins this round… but I still miss Rails something fierce…

Note: this may have been what Rails’ components did. But they got canned.

Written by alson

August 20th, 2008 at 12:52 pm

Posted in ASP.NET,Ruby On rails

Tagged with , ,