Tuesday, November 9, 2010

How to make a web site re-usable by third parties

One of the big challenges of our project was to turn what was essentially designed as a regular database-driven web site into a re-usable application. By 're-usable' here we mean that your typical university sysadmin could take our package and turn it into a PhilPapers-like site that doesn't look too much like PhilPapers. No programming needed, but modifying config files and templates is OK.

The big challenge in here is preserving the upgrade path. PhilPapers is built with HTML::Mason, a template system. We have hundreds of template files of all sizes. If someone copied our source tree and started modifying the templates to adapt them to their needs, they would soon end up with a system that is all but impossible to update with our latest code. A similar problem arises with the many data files and image files that support the site.

Our solution to this problem is to extend the concept of differential programming found in OO programming to templates. Think of our template files as methods of a big Template class. So our header file is a method, our footer file is another, and everything that goes in-between is a method too. A natural way to refine an existing class is to override just the methods you need to change, keeping the originals intact in the superclass. That's what we've done with our templates.

We achieved that by defining several component roots in Mason (the component roots are paths relative to which Mason looks for template files). Suppose we have an incoming request for the /news.html component on PhilPapers. For PhilPapers we have two component roots; let's pretend they are /var/philpapers and /var/xpapers. The latter contains the default templates that ship with xPapers, while the former contains only the overrides required to give PhilPapers its unique look and structure. If template /news.html is requested, Mason first looks in our /var/philpapers/ tree of templates. If there's a /var/philpapers/news.html file, it will use it and ignore /var/xpapers/news.html. If not, it will revert to /var/xpapers/news.html.

Another challenge is maintaining the upgrade path of the database schema. Here we plan to use the same system that we use internally to maintain the schema through git: each change to the schema is saved in a file with the table's name, and we have a script that keeps track of what lines in what files have been executed. That works pretty well, except when we want to roll back some changes. When that happens we simply add more lines which have the effect of rolling back the changes. There's also a theoretical issue about order of execution and foreign key constraints, but in hundreds of updates we have never run into that because we hardly use foreign key constraints with MySQL. If needed we could get around this by adding the constraints to a file whose lines are always executed last. This system isn't as robust as Ruby migrations, but it is lightweight, efficient, and (almost) fun to use.


  1. tiffany and co jewelry, http://www.tiffanyandco.in.net/
    prada handbags, http://www.pradahandbagsoutlet.co.uk/
    louis vuitton handbags, http://www.louisvuittonhandbag.us/
    tiffany jewellery, http://www.tiffanyjewelleryoutlets.co.uk/
    hermes belt, http://www.hermesbelts.us/
    ugg outlet, http://www.uggsoutlet.us.org/
    karen millen dresses, http://www.karenmillendressesoutlets.co.uk/
    replica watches, http://www.replicawatchesforsale.us.com/
    christian louboutin online, http://www.christianlouboutinonline.us.com/
    canada goose jackets, http://www.uggbootscheap.eu.com/
    gucci, http://www.borseguccioutlet.it/
    air jordan shoes, http://www.airjordanshoes.us.org/
    the north face outlet store, http://www.thenorthfaceoutletstores.org/
    louis vuitton, http://www.louisvuitton.in.net/
    ugg boots, http://www.uggbootsclearance.in.net/
    nobis outlet, http://www.wellensteyn.com.co/
    ray ban sunglasses, http://www.raybansunglassesonline.us.com/
    snow boots, http://www.wintercoats.us.com/
    lebron james shoes, http://www.lebronjames.us.com/
    beats by dr dre, http://www.beatsbydrdre-headphones.us.com/
    michael kors factory outlet, http://www.michaelkorsfactoryoutlets.in.net/
    cheap nhl jerseys, http://www.nhljerseys.us.com/
    montblanc pens, http://www.montblanc-pens.com.co/
    vans shoes, http://www.vans-shoes.cc/
    dansko outlet, http://www.dansko-shoes.us/

  2. Tahukah anda Antara 50 hingga 90% dari orang-orang yang bekerja di depan layar komputer memiliki beberapa gmasalah yang cukup serius dengankesehatan matanya
    Obat Radang Ginjal Nefritis
    Obat Disfungsi Ereksi Yang Aman
    Penyebab Anyang Anyangan Yang Berkepanjangan


  3. افضل شركة نقل اثاث بالمدينة المنورة تساعدك على نقل اثاثك بامان فلا داعى للقلق مع افضل شركة نقل اثاث بجدة

    عزيزى العميل انت من محبى التنقل باستمرار بالتالى انت بحاجة ماسة وضروية الى الاستعانة بالمختصين في نقل العفش خاصة ارخص شركة نقل اثاث بالرياض لان الاستعانة باى من عمالة الشوارع الغير مدربة والتي لا تمتلك خبرة كافية في نقل العفش او الحفاظ علية وليس هذا فقط فقد يؤدى الاستعانة بعمالة الشوارع الى حدوث حالة فقدان وتكسير للاثاث بالتالى التاثير الضار عليك عزيزى العميل

    لا تقلق مطلقاً الان بشأن نقل اي منقولات خاصة بك طالما استعنت بشركة الاول لـ نقل الأثاث في الرياض وخارج الرياض فنحن ليس الوحيدون ولكننا متميزون عن اى مؤسسة أخرى داخل وخارج الدمام وشهرتنا كافضل شركة نقل عفش بينبع
    نقل اثاث بجدة

  4. It is really hard to say when exactly need to cash your check. Sometimes it may very difficult to cash if it is not official hours
    check cashing

  5. On the off chance that you end up requiring a payday advance, recollect to pay it back before the due date. www.usacheckcashingstore.com/san-diego

  6. A payday advance is intended to help individuals beat here and now issues; accordingly they are accessible for little sums up to £750. usapaydayloanstore.com/chicago

  7. "Welcome to the web experts treatment of various types of diseases, do not forget to get the best health solutions here"
    Cara Mengobati Beri Beri