<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Jon Buda : Writings from The Killswitch Collective</title>
    <link>http://www.killswitchcollective.com/blog/index.xml</link>
    <description>These articles were written by Jon Buda for Perspectives, the blog of The Killswitch Collective, a Chicago-based web development, design and communication firm.</description>
    <language>en-us</language>
    <item>
      <title>Fencing Off Your CMS with Controller Namespacing</title>
      <category>Development</category>
      <description>&lt;p&gt;Many Web Applications these days consist of two main parts: the public facing front-end, and the private, secure administration area. When developing with Ruby on Rails, the convention is to try to write code as DRY (don't repeat yourself) as possible and use one single controller for both the public side and the administration side of the site. For certain circumstances this is fine, but I think there is some flexibility here, and recently I've noticed that many times the Admin logic is quite a bit different that the public facing functionality &amp;mdash; enough so to warrant its own set of admin controllers and views.&lt;/p&gt;

  &lt;p&gt;With Rails 2.0+, you can use namespacing to keep the admin controller logic and views separate from the public controller logic and views. I've come to really like the way this helps to keep both sections of the site separate and organized.&lt;/p&gt;

  &lt;p&gt;I'll demonstrate a very simple example of a web app that provides a way for an Administrator to create, edit, and delete articles with one controller, and for a visitor to view those articles with a separate controller.&lt;/p&gt;

&lt;h3&gt;Create Your Controllers&lt;/h3&gt;
  
  &lt;p&gt;After you've created your new rails app, we can proceed by generating our two controllers to access our articles:&lt;/p&gt;
  
&lt;pre style="background-color:#2B2B2B;color:#E6E1DC;padding:6px;overflow:auto;line-height:12px;font-size:12px;padding:6px;"&gt;
# our private admin controller uses namespacing. Notice the Admin:: prefix
./script/generate controller Admin::Articles
&lt;/pre&gt;

&lt;pre style="background-color:#2B2B2B;color:#E6E1DC;padding:6px;overflow:auto;line-height:12px;font-size:12px;padding:6px;"&gt;
# our public controller is created normally
./script/generate controller Articles
&lt;/pre&gt;

  &lt;p&gt;We now have two controllers named &lt;code&gt;articles_controller.rb&lt;/code&gt;. The public controller lives in &lt;code&gt;app/controllers/&lt;/code&gt; and the private controller lives in &lt;code&gt;app/controllers/admin/&lt;/code&gt; with its respective views in &lt;code&gt;app/views/admin/articles&lt;/code&gt;. Once you've created the necessary views, you should have a file structure similar to the image below. Our public controller only needs two methods at this point: 'index' and 'show', while our admin controller will require all 7 standard REST methods.&lt;/p&gt;
  
  &lt;p&gt;&lt;img src='http://www2.killswitchcollective.com/articles/namespace/namespace_files.gif' /&gt;&lt;/p&gt;

&lt;h3&gt;Create Your Routes&lt;/h3&gt;

  &lt;p&gt;Before either of these controllers can function, we need to setup our routes in the &lt;code&gt;config/routes.rb&lt;/code&gt; file.&lt;/p&gt;
  
  &lt;pre style="background-color:#2B2B2B;color:#E6E1DC;padding:6px;overflow:auto;line-height:12px;font-size:12px;padding:6px;"&gt;&lt;span class="ident"&gt;map&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;namespace&lt;/span&gt; &lt;span style="color:#6E9CBE"&gt;:admin&lt;/span&gt; &lt;span style="color:#CC7833"&gt;do&lt;/span&gt; &lt;span class="punct"&gt;|&lt;/span&gt;&lt;span class="ident"&gt;admin&lt;/span&gt;&lt;span class="punct"&gt;|&lt;/span&gt;
  &lt;span class="ident"&gt;admin&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;resources&lt;/span&gt; &lt;span style="color:#6E9CBE"&gt;:articles&lt;/span&gt;
&lt;span style="color:#CC7833"&gt;end&lt;/span&gt;

&lt;span class="ident"&gt;map&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;resources&lt;/span&gt; &lt;span style="color:#6E9CBE"&gt;:articles&lt;/span&gt;
  &lt;/pre&gt;

  &lt;p&gt;Take a second and run &lt;code&gt;rake routes&lt;/code&gt; on the command line to view all of your current routes. You'll notice you now have 2 sets of articles routes, one of which targets your admin controller, and one which targets your public controller.&lt;/p&gt;


&lt;h3&gt;Handling Links and Forms&lt;/h3&gt;

  &lt;p&gt;So how does this change how links are handled in the views? It turns out it's not all that complicated thanks to Rails creating a set of admin specific URL generation methods:&lt;/p&gt;
  
&lt;pre style="background-color:#2B2B2B;color:#E6E1DC;padding:6px;overflow:auto;line-height:12px;font-size:12px;padding:6px;"&gt;&lt;span style="color:#BC9458"&gt;# Create a link to the public article page '/articles/:id'&lt;/span&gt;
&lt;span class="punct"&gt;&amp;lt;%=&lt;/span&gt; link_to &lt;span style="color:#A5C261"&gt;'View Article'&lt;/span&gt;, article_url(&lt;span style="color:#D0D0FF"&gt;@article&lt;/span&gt;) %&amp;gt;

&lt;span style="color:#BC9458"&gt;# Create a link to view the article in the Admin area '/admin/articles/:id'&lt;/span&gt;
&amp;lt;%&lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;link_to&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span style="color:#A5C261"&gt;View Article&lt;/span&gt;&lt;span class="punct"&gt;',&lt;/span&gt; &lt;span class="ident"&gt;admin_article_url&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span style="color:#D0D0FF"&gt;@article&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt; &lt;span class="punct"&gt;%&amp;gt;&lt;/span&gt;

&lt;span style="color:#BC9458"&gt;# Create a link to edit the article in the Admin area '/admin/articles/:id/edit'&lt;/span&gt;
&amp;lt;%= link_to &lt;span style="color:#A5C261"&gt;'Edit Article'&lt;/span&gt;, edit_admin_article_url(&lt;span style="color:#D0D0FF"&gt;@article&lt;/span&gt;) %&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;

  &lt;p&gt;The same goes for using forms in the Admin area. Instead of using &lt;code&gt;&lt;% form_for(@article) do |f| %&gt;&lt;/code&gt; you simply add in the admin namespace, and voila, your forms submit to the /admin/articles controller:&lt;/p&gt;
  
&lt;pre style="background-color:#2B2B2B;color:#E6E1DC;padding:6px;overflow:auto;line-height:12px;font-size:12px;padding:6px;"&gt;&lt;span style="color:#BC9458"&gt;# Create a form that submits to the /admin/articles controller&lt;/span&gt;
&lt;span class="punct"&gt;&amp;lt;%&lt;/span&gt; &lt;span class="ident"&gt;form_for&lt;/span&gt;&lt;span class="punct"&gt;([&lt;/span&gt;&lt;span style="color:#6E9CBE"&gt;:admin&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span style="color:#D0D0FF"&gt;@article&lt;/span&gt;&lt;span class="punct"&gt;])&lt;/span&gt; &lt;span style="color:#CC7833"&gt;do&lt;/span&gt; &lt;span class="punct"&gt;|&lt;/span&gt;&lt;span class="ident"&gt;f&lt;/span&gt;&lt;span class="punct"&gt;|&lt;/span&gt; &lt;span class="punct"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color:#A5C261"&gt;
....&lt;/span&gt;
&lt;span class="punct"&gt;&amp;lt;% end %&amp;gt;&lt;/span&gt;
&lt;/pre&gt;

&lt;h3&gt;Securing and Styling Your Admin Controllers&lt;/h3&gt;

  
  &lt;p&gt;You will no doubt want to secure all of your Admin controllers and require an Admin user to be logged in. If you use a plugin like the popular &lt;a href='http://github.com/technoweenie/restful-authentication/tree/master'&gt;RESTUL Authentication&lt;/a&gt;, you can simply apply the &lt;code&gt;before_filter :login_required&lt;/code&gt; to the top of each Admin controller.&lt;/p&gt;

&lt;p&gt;Most of the time the Administration area is also styled differently than the public facing area of the site. Here we can simply put something like &lt;code&gt;layout 'admin'&lt;/code&gt; at the top of our Admin controllers to use a separate &lt;code&gt;admin.html.erb&lt;/code&gt; layout file instead of the public &lt;code&gt;application.html.erb&lt;/code&gt; layout file.&lt;/p&gt;

&lt;pre style="background-color:#2B2B2B;color:#E6E1DC;padding:6px;overflow:auto;line-height:12px;font-size:12px;padding:6px;"&gt;&lt;span style="color:#CC7833"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Admin::ArticlesController&lt;/span&gt; &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt; &lt;span style="color:#DA4939"&gt;ApplicationController&lt;/span&gt;
  &lt;span class="ident"&gt;before_filter&lt;/span&gt; &lt;span style="color:#6E9CBE"&gt;:login_required&lt;/span&gt;
  &lt;span class="ident"&gt;layout&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span style="color:#A5C261"&gt;admin&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
  
  ... REST methods here ...
&lt;span style="color:#CC7833"&gt;end&lt;/span&gt;
&lt;/pre&gt;



&lt;h3&gt;Wrapping Things Up...&lt;/h3&gt;


&lt;p&gt;You should now have the beginnings of a web app with a set of self-contained, password-protected Admin CMS controllers prefixed with &lt;code&gt;/admin&lt;/code&gt;, and a set publicly viewable front-end controllers. If you're feeling adventurous, you could even extract the controllers, views, routes, and stylesheets into a plugin or a generator if many of the CMS features will be used throughout a variety of different applications.&lt;/p&gt;
</description>
      <pubDate>Fri, 25 Jul 2008 13:21:12 -0700</pubDate>
      <link>http://www.killswitchcollective.com/articles/29</link>
      <guid>http://www.killswitchcollective.com/articles/29</guid>
    </item>
    <item>
      <title>Expanding Your Web Typography Arsenal</title>
      <category>Development</category>
      <description>    &lt;p&gt;A long standing complaint among web designers is the lack of variety in typefaces that can be reliably used and guaranteed to display across all web browsers and operating systems. For the most part, designers are stuck with Arial, Verdana, Georgia, Times, or the standard serif and sans-serif implementations, though this list can be supplemented by expanding the &lt;a href='http://24ways.org/2007/increase-your-font-stacks-with-font-matrix'&gt;font stack&lt;/a&gt;. Granted, the standard typefaces are optimized for web and will render well across the the board at various sizes, with anti-aliasing on or off, but occasionally designers need to spice things up with additional typefaces in an accessible, search-friendly manner without resorting to pre-rendered images. Two options currently exist to help remedy the situation: sIFR and Safari Embedded Fonts.&lt;/p&gt;

  &lt;h3&gt;sIFR (Scalable Inman Flash Replacement)&lt;/h3&gt;

   &lt;p&gt;&lt;a href='http://wiki.novemberborn.net/sifr/'&gt;sIFR&lt;/a&gt; has been available for a few years and has had a good reception across the web community. It was created as a way for designers to display &lt;em&gt;any&lt;/em&gt; typeface on a web site without requiring the visitor to have that typeface previously installed. It uses a combination of Adobe Flash and Javascript to dynamically replace text, and is completely accessible and search engine friendly. The current stable build of sIFR is version 2, with version 3 currently in development, hopefully to be released in a stable form in the near future.&lt;/p&gt;
   
   &lt;p&gt;sIFR requires both Javascript to be turned on and the Flash plugin to be installed. If either of these requirements are not met, the default styles designated by the designer will be used and the visitor will never know the difference. However, the wide adoption of Flash and Javascript will ensure it works for most visitors. sIFR is best used in moderation with elements like headlines, rather than entire blocks of body text.&lt;/p&gt;
   
   &lt;h3&gt;How to use it&lt;/h3&gt;
    
   &lt;p&gt;After &lt;a href='http://novemberborn.net/sifr/2.0.5'&gt;downloading sIFR&lt;/a&gt;, the first step is to open the &lt;code&gt;sifr.fla&lt;/code&gt; in Adobe Flash, replace the typeface with one of your choosing, and export the file as a Flash movie. This is explained in more detail in the &lt;a href='http://wiki.novemberborn.net/sifr/How+to+use'&gt;sIFR Documentation&lt;/a&gt;. Next, in the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; of your HTML document, insert links to the sIFR CSS and Javascript files:&lt;/p&gt;
      
&lt;pre&gt;
&amp;lt;head&amp;gt;
  .....
  &amp;lt;link rel="stylesheet" href="sIFR-screen.css" type="text/css" media="screen" /&amp;gt;
  &amp;lt;link rel="stylesheet" href="sIFR-print.css" type="text/css" media="print" /&amp;gt;
  &amp;lt;script src="sifr.js" type="text/javascript"&amp;gt;&amp;lt;/script&amp;gt;
  &amp;lt;script src="sifr-addons.js" type="text/javascript"&amp;gt;&amp;lt;/script&amp;gt;
  .....
&amp;lt;/head&amp;gt;
&lt;/pre&gt;
   
   &lt;p&gt;Before the the closing &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; tag of your HTML document, insert the Javascript to call the sIFR replacement methods on all the elements you want to transform:&lt;/p&gt;
   
&lt;pre&gt;
.....
&amp;lt;script type="text/javascript"&amp;gt;
if(typeof sIFR == "function"){
	  sIFR.replaceElement(named({sSelector:"body h1", sFlashSrc:"blackletter.swf", sColor:"#000000", sBgColor:"#dddddd", sFlashVars:"textalign=center"}));
  sIFR.replaceElement(named({sSelector:"body h2", sFlashSrc:"blackletter.swf", sColor:"#000000", sBgColor:"#FFFFFF"}));
};
&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
.....
&lt;/pre&gt;
    
   &lt;p&gt;The sIFR.replacementElement method takes a number of options such as color, background color, link and hover colors, padding, and several more as described in detail in the &lt;a href='http://wiki.novemberborn.net/sifr/How+to+use'&gt;sIFR Documentation&lt;/a&gt;. You may have to play around with these options and tinker with your CSS to perfect your transformations.&lt;/p&gt;  
   
   &lt;p&gt;&lt;a href='http://wiki.novemberborn.net/sifr3/Examples'title='View the example if sIFR in action'&gt;View the Example &amp;raquo;&lt;/a&gt;&lt;/p&gt;
   
   &lt;p&gt;You should see something like:&lt;/p&gt;
   
   &lt;img src='http://www2.killswitchcollective.com/articles/webtype/external/sifr.gif' alt='sIFR Example' /&gt;
   
   &lt;h3&gt;Pitfalls&lt;/h3&gt;
   
   &lt;p&gt;sIFR does a good job of working across a variety of browsers and degrades rather gracefully when it can't be used. That said, there are a few issues that arise with its use. Occasionally sIFR can slow the rendering of a web site, and can also create a visible 'flash' as the text is replaced by Flash. Additionally, visitors won't be able to copy and paste a combination of sIFR text and normal HTML text.&lt;/p&gt; 

  &lt;h3&gt;Embedding Fonts with @font-face and Safari&lt;/h3&gt;
      
    &lt;p&gt;With the recent release of &lt;a href='http://www.apple.com/safari/' title='Download Safari 3.1 (Mac or PC)'&gt;Safari 3.1&lt;/a&gt; from Apple comes the ability for a web designer to reliably display any TrueType font of their choosing on a web site without Flash or Javascript, allowing them to style it with CSS as they wish. Visitors' browsers will seamlessly download the typeface and render the design in all its glory as was intended by the designer. Surprisingly, Internet Explorer has actually &lt;a href='http://msdn2.microsoft.com/en-us/library/ms530757(VS.85).aspx'&gt;supported font-face embedding since version 4&lt;/a&gt;, but unsurprisingly, Microsoft's implementation only works with a proprietary .EOT font format.&lt;/p&gt;
        
    &lt;h3&gt;How to use it&lt;/h3&gt;
    
    &lt;p&gt;Implementing the &lt;code&gt;@font-face&lt;/code&gt; property is actually quite simple. It acts just like any other CSS selector as shown in the example code below. Define a name for your &lt;code&gt;font-family&lt;/code&gt; and then provide an absolute or relative &lt;code&gt;url()&lt;/code&gt; to the typeface file. The &lt;code&gt;url()&lt;/code&gt; acts just like &lt;code&gt;url()&lt;/code&gt; for &lt;code&gt;background-image&lt;/code&gt;. Once you've defined the typeface, simply use the new &lt;code&gt;font-family&lt;/code&gt; within any selector as you would normally.&lt;/p&gt;
    
&lt;pre&gt;
@font-face {
  font-family: "OldeEnglish";
  src: url(OldeEnglish.ttf) format("truetype");
}

h1 { font-family: "OldeEnglish"; }
&lt;/pre&gt;
    
    &lt;p&gt;&lt;a href='http://www.css3.info/preview/web-fonts-with-font-face/' title='View the example of Safari embedded fonts in action'&gt;View the Example (works only in Safari 3.1+) &amp;raquo;&lt;/a&gt;&lt;/p&gt;
    
    &lt;p&gt;You should see something like:&lt;/p&gt;
    
    &lt;img src='http://www2.killswitchcollective.com/articles/webtype/external/safari.gif' alt='Safari Embedded Fonts Example' /&gt;
    
    &lt;h3&gt;Pitfalls&lt;/h3&gt;
    
    &lt;p&gt;One major downfall to using embedded typefaces is that the technique currently only works in Safari 3.1. However, other browsers will degrade gracefully and use the next font in the font stack. Unfortunately, a designer may be using different &lt;code&gt;line-height&lt;/code&gt;, &lt;code&gt;font-size&lt;/code&gt;, &lt;code&gt;letter-spacing&lt;/code&gt;, or &lt;code&gt;word-spacing&lt;/code&gt; specific custom typeface, making the next typeface in the stack unreadable. No word yet on whether future versions of Firefox, Internet Explorer, or Opera will join in the font embedding party, but a designer can hope.&lt;/p&gt;
    
    &lt;p&gt;Copyright issues also arise with &lt;code&gt;@font-face&lt;/code&gt;. Quality typefaces from type foundries often cost hundreds to thousands of dollars and don't generally include licenses that allow for legal distribution to the public. Since the fonts used with &lt;code&gt;@font-face&lt;/code&gt; are required to be publicly accessible, they could potentially be downloaded by any user who has a peek inside your stylesheet. There are many freely downloadable fonts available on the web, but a majority of those are rather low quality and should probably be avoided anyways.&lt;/p&gt;

  &lt;h3&gt;With Great Power Comes Great Responsibility&amp;hellip;&lt;/h3&gt;
  
    &lt;p&gt;The two tools are a welcome addition to a designers arsenal, especially when it comes to web typography. However, these new tools do open the door for typeface abuse and potentially illegible, tacky designs. Unless that's specifically what you're going for, as a designer you should still use sound judgement and restraint. Just because you &lt;em&gt;can&lt;/em&gt;, doesn't mean you &lt;em&gt;should&lt;/em&gt;. With that said, go forth and experiment!&lt;/p&gt;  
  
  &lt;h3&gt;Helpful Resources &amp;amp; References&lt;/h3&gt;

    &lt;ul&gt;
      &lt;li&gt;&lt;a href='http://wiki.novemberborn.net/sifr'&gt;sIFR Documentation&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href='http://webtypography.net'&gt;The Elements of Typographic Style Applied to the Web&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href='http://www.apaddedcell.com/web-fonts'&gt;Complete Guide to Pre-Installed Fonts&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href='http://www.safalra.com/web-design/typography/web-safe-fonts-myth/'&gt;Web Font Stacks&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href='http://24ways.org/2007/increase-your-font-stacks-with-font-matrix'&gt;Font Stack Matrix&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href='http://www.alistapart.com/articles/howtosizetextincss'&gt;How to size text in CSS&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href='http://www.alistapart.com/articles/cssatten'&gt;CSS @ Ten: The Next Big Thing&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href='http://moorstation.org/typoasis/designers/steffmann/samples/o/oldeEngl.htm'&gt;Olde English Typeface by Dieter Steffmann&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
</description>
      <pubDate>Fri, 25 Apr 2008 12:18:27 -0700</pubDate>
      <link>http://www.killswitchcollective.com/articles/16</link>
      <guid>http://www.killswitchcollective.com/articles/16</guid>
    </item>
  </channel>
</rss>
