<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Year of Moo</title>
	<atom:link href="http://yearofmoo.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://yearofmoo.com</link>
	<description></description>
	<lastBuildDate>Wed, 09 May 2012 14:43:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Introducing Git-Concat</title>
		<link>http://yearofmoo.com/2012/04/introducing-git-concat/</link>
		<comments>http://yearofmoo.com/2012/04/introducing-git-concat/#comments</comments>
		<pubDate>Mon, 16 Apr 2012 01:28:52 +0000</pubDate>
		<dc:creator>matsko</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://yearofmoo.com/?p=963</guid>
		<description><![CDATA[A super useful tool for automating file concatenation within your git repo Git-Concat is a tiny plugin which is installed into your git repository which will allow you to specify a list of input and output files which will be concatenated together each time a commit is issued. The plugin itself takes in a manifest [...]]]></description>
			<content:encoded><![CDATA[<h3>A super useful tool for automating file concatenation within your git repo</h3>
<p><a class="em" href="/Git-Concat">Git-Concat</a> is a tiny plugin which is installed into your git repository which will allow you to specify a list of input and output files which will be concatenated together each time a commit is issued. The plugin itself takes in a manifest file which is in <em>YAML</em> format. The tool itself is very useful for plugin development and small projects where a master source file is required each time new code is put into the repository. <em>Filters</em> can also be added so that any operation that can be run from the command line can be directly applied to the final concatenated file just before its committed. The <a class="em" href="/Git-Concat">Git-Concat</a> tool is found under the <a class="em" href="/plugins">plugins</a> area.<br />
<span id="more-963"></span></p>
<p><h3>Last Updated</h3>
<p>This page was first published on <em>April 15th</em> and was last updated on <em>April 15th 2012</em>.
</p>
<p><h3>East Install + Usage</h3>
<p>There&#8217;s nothing more to using this plugin then just an easy, one-command install. Then once its ready, just create the <em>.gitconcat</em> file and specify all the details. <em>CSS and JavaScript minification</em> can easily be applied by adding a <em>filter</em> within each concatenation declaration.
</p>
<p>
The plugin itself is covered in full detail on its plugin page. <a href="/Git-Concat" class="em">Click here to find out more</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://yearofmoo.com/2012/04/introducing-git-concat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails 3.2 and Active Record Store</title>
		<link>http://yearofmoo.com/2012/01/rails-3-2-and-active-record-store/</link>
		<comments>http://yearofmoo.com/2012/01/rails-3-2-and-active-record-store/#comments</comments>
		<pubDate>Sat, 21 Jan 2012 05:04:33 +0000</pubDate>
		<dc:creator>matsko</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://yearofmoo.com/?p=890</guid>
		<description><![CDATA[What exactly is Active Record Store and how to use it with Rails 3.2 Rails 3.2 was released earlier today and it provides a variety of new features including: Active Reload, Faster Dev Mode, Tagged Logger and, of coarse, Active Record Store. When Active Record store was released I was a bit curious as to [...]]]></description>
			<content:encoded><![CDATA[<h3>What exactly is Active Record Store and how to use it with Rails 3.2</h3>
<p>Rails 3.2 was released earlier today and it provides a variety of new features including: <em>Active Reload</em>, <em>Faster Dev Mode</em>, <em>Tagged Logger</em> and, of coarse, <em>Active Record Store</em>. When Active Record store was released I was a bit curious as to how it works since <em>I only saw the same example on every blog out there</em> and the example itself just wasn&#8217;t doing it for me. Therefore this article will briefly explain how to use Active Record Store and how the contents of are stored in the database.<br />
<span id="more-890"></span></p>
<p><h3>Last Updated</h3>
<p>This article was first published on <em>January 20th 2012</em> and was last updated on <em>May 9th 2012</em>.
</p>
<p><h3>Active Record Store</h3>
<p>Active Record Store is <em>used for storing additional attributes within a database record</em> without the need to have to create additional attributes (columns in the database table) to store these values. The contents of these &#8220;additional attributes&#8221; <em>are stored within the scope of an existing attribute and as serialized as a JSON object</em>. Once fetched, <em>they&#8217;re unserialized and used as regular attributes</em>. Here&#8217;s the basic code for using Active Record Store:</p>
<div class="syntax">
<style type="text/css">


/* *************************************************** */
/* WordPress default theme "twenty-ten" compatibility: */
/* FIXME: Is there a way to limit these changes to pygmentize_9LwzVt  */
/*        without editing the WordPress theme directly? */
/* *************************************************** */

.syntax pre {
  /* The background: transparent is needed to work with WordPress:*/
  background: transparent;
  /* Default WordPress style has a big fat <pre> margin-bottom: */
  margin-bottom: 0px;

  /*color: #333333;*/
  font-size: .9em; 
  line-height: 1.25em;
}

.syntax table {
	border: 1px solid #e7e7e7;
    margin: 0 0 0 0;
	text-align: left;
	width: 100%;
}
.syntax tr th,
.syntax thead th {
	color: #888;
	font-size: 12px;
	font-weight: bold;
	line-height: 18px;
	padding: 0px;
}
.syntax tr td {
	border: 0px;
	padding: 0px;
	margin: 0px;
    margin-bottom: 0px;
    padding-bottom: 0px;

}

/* *************************************************** */
/* *************************************************** */

/* Standard fixes to the default output: */

/* Set the tab width in "ch" character units: */
.pygmentize_9LwzVt .tabspan {
  display: inline-block;
  width: 4ch;
}

/* When using line numbers, use 100% table width and no cellpadding: */
.pygmentize_9LwzVttable {
  width: 100%;
  border-spacing: 0px;
  border-collapse: collapse;
}


/*
.syntax table {
    border: 1px solid #E7E7E7;
    margin: 0 -1px 24px 0;
    text-align: left;
    width: 100%;
}
*/

.pygmentize_9LwzVttable td, .pygmentize_9LwzVttable th {
  padding: 0px;
  margin: 0px;
}

/* Add a little buffer so the monotype font doesn't bump directly against the edge: */
.pygmentize_9LwzVt pre {
  padding: .6ch;
  
}

/* This is more consistent with <p> tags... I didn't like it for my use: */
/*
div .pygmentize_9LwzVt {
    margin-bottom: 24px; 
}
*/

td.linenos.pygmentize_9LwzVt {
  width: 1ch;
  padding: .6ch;
  line-height: 1.25em;
}

.pygmentize_9LwzVt td {
  padding-right: 1px;
}


td.linenos { background-color: #f0f0f0; padding-right: 1px; }
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
pre { line-height: 125%; }
.pygmentize_9LwzVt .hll { background-color: #404040 }
.pygmentize_9LwzVt  { background: #202020; color: #d0d0d0 }
.pygmentize_9LwzVt .c { color: #999999; font-style: italic } /* Comment */
.pygmentize_9LwzVt .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.pygmentize_9LwzVt .g { color: #d0d0d0 } /* Generic */
.pygmentize_9LwzVt .k { color: #6ab825; font-weight: bold } /* Keyword */
.pygmentize_9LwzVt .l { color: #d0d0d0 } /* Literal */
.pygmentize_9LwzVt .n { color: #d0d0d0 } /* Name */
.pygmentize_9LwzVt .o { color: #d0d0d0 } /* Operator */
.pygmentize_9LwzVt .x { color: #d0d0d0 } /* Other */
.pygmentize_9LwzVt .p { color: #d0d0d0 } /* Punctuation */
.pygmentize_9LwzVt .cm { color: #999999; font-style: italic } /* Comment.Multiline */
.pygmentize_9LwzVt .cp { color: #cd2828; font-weight: bold } /* Comment.Preproc */
.pygmentize_9LwzVt .c1 { color: #999999; font-style: italic } /* Comment.Single */
.pygmentize_9LwzVt .cs { color: #e50808; font-weight: bold; background-color: #520000 } /* Comment.Special */
.pygmentize_9LwzVt .gd { color: #d22323 } /* Generic.Deleted */
.pygmentize_9LwzVt .ge { color: #d0d0d0; font-style: italic } /* Generic.Emph */
.pygmentize_9LwzVt .gr { color: #d22323 } /* Generic.Error */
.pygmentize_9LwzVt .gh { color: #ffffff; font-weight: bold } /* Generic.Heading */
.pygmentize_9LwzVt .gi { color: #589819 } /* Generic.Inserted */
.pygmentize_9LwzVt .go { color: #cccccc } /* Generic.Output */
.pygmentize_9LwzVt .gp { color: #aaaaaa } /* Generic.Prompt */
.pygmentize_9LwzVt .gs { color: #d0d0d0; font-weight: bold } /* Generic.Strong */
.pygmentize_9LwzVt .gu { color: #ffffff; text-decoration: underline } /* Generic.Subheading */
.pygmentize_9LwzVt .gt { color: #d22323 } /* Generic.Traceback */
.pygmentize_9LwzVt .kc { color: #6ab825; font-weight: bold } /* Keyword.Constant */
.pygmentize_9LwzVt .kd { color: #6ab825; font-weight: bold } /* Keyword.Declaration */
.pygmentize_9LwzVt .kn { color: #6ab825; font-weight: bold } /* Keyword.Namespace */
.pygmentize_9LwzVt .kp { color: #6ab825 } /* Keyword.Pseudo */
.pygmentize_9LwzVt .kr { color: #6ab825; font-weight: bold } /* Keyword.Reserved */
.pygmentize_9LwzVt .kt { color: #6ab825; font-weight: bold } /* Keyword.Type */
.pygmentize_9LwzVt .ld { color: #d0d0d0 } /* Literal.Date */
.pygmentize_9LwzVt .m { color: #3677a9 } /* Literal.Number */
.pygmentize_9LwzVt .s { color: #ed9d13 } /* Literal.String */
.pygmentize_9LwzVt .na { color: #bbbbbb } /* Name.Attribute */
.pygmentize_9LwzVt .nb { color: #24909d } /* Name.Builtin */
.pygmentize_9LwzVt .nc { color: #447fcf; text-decoration: underline } /* Name.Class */
.pygmentize_9LwzVt .no { color: #40ffff } /* Name.Constant */
.pygmentize_9LwzVt .nd { color: #ffa500 } /* Name.Decorator */
.pygmentize_9LwzVt .ni { color: #d0d0d0 } /* Name.Entity */
.pygmentize_9LwzVt .ne { color: #bbbbbb } /* Name.Exception */
.pygmentize_9LwzVt .nf { color: #447fcf } /* Name.Function */
.pygmentize_9LwzVt .nl { color: #d0d0d0 } /* Name.Label */
.pygmentize_9LwzVt .nn { color: #447fcf; text-decoration: underline } /* Name.Namespace */
.pygmentize_9LwzVt .nx { color: #d0d0d0 } /* Name.Other */
.pygmentize_9LwzVt .py { color: #d0d0d0 } /* Name.Property */
.pygmentize_9LwzVt .nt { color: #6ab825; font-weight: bold } /* Name.Tag */
.pygmentize_9LwzVt .nv { color: #40ffff } /* Name.Variable */
.pygmentize_9LwzVt .ow { color: #6ab825; font-weight: bold } /* Operator.Word */
.pygmentize_9LwzVt .w { color: #666666 } /* Text.Whitespace */
.pygmentize_9LwzVt .mf { color: #3677a9 } /* Literal.Number.Float */
.pygmentize_9LwzVt .mh { color: #3677a9 } /* Literal.Number.Hex */
.pygmentize_9LwzVt .mi { color: #3677a9 } /* Literal.Number.Integer */
.pygmentize_9LwzVt .mo { color: #3677a9 } /* Literal.Number.Oct */
.pygmentize_9LwzVt .sb { color: #ed9d13 } /* Literal.String.Backtick */
.pygmentize_9LwzVt .sc { color: #ed9d13 } /* Literal.String.Char */
.pygmentize_9LwzVt .sd { color: #ed9d13 } /* Literal.String.Doc */
.pygmentize_9LwzVt .s2 { color: #ed9d13 } /* Literal.String.Double */
.pygmentize_9LwzVt .se { color: #ed9d13 } /* Literal.String.Escape */
.pygmentize_9LwzVt .sh { color: #ed9d13 } /* Literal.String.Heredoc */
.pygmentize_9LwzVt .si { color: #ed9d13 } /* Literal.String.Interpol */
.pygmentize_9LwzVt .sx { color: #ffa500 } /* Literal.String.Other */
.pygmentize_9LwzVt .sr { color: #ed9d13 } /* Literal.String.Regex */
.pygmentize_9LwzVt .s1 { color: #ed9d13 } /* Literal.String.Single */
.pygmentize_9LwzVt .ss { color: #ed9d13 } /* Literal.String.Symbol */
.pygmentize_9LwzVt .bp { color: #24909d } /* Name.Builtin.Pseudo */
.pygmentize_9LwzVt .vc { color: #40ffff } /* Name.Variable.Class */
.pygmentize_9LwzVt .vg { color: #40ffff } /* Name.Variable.Global */
.pygmentize_9LwzVt .vi { color: #40ffff } /* Name.Variable.Instance */
.pygmentize_9LwzVt .il { color: #3677a9 } /* Literal.Number.Integer.Long */

  </style>




<div class="pygmentize_9LwzVt"><pre><span class="c1"># Class Definition</span>
<span class="k">class</span> <span class="nc">User</span> <span class="o">&lt;</span> <span class="no">ActiveRecord</span><span class="o">::</span><span class="no">Base</span>

  <span class="c1"># The schema structure of this record is:</span>
  <span class="c1"># String first_name</span>
  <span class="c1"># String last_name</span>
  <span class="c1"># Integer age</span>
  <span class="c1"># String details</span>

  <span class="n">store</span> <span class="ss">:details</span><span class="p">,</span> <span class="n">accessors</span><span class="p">:</span> <span class="o">[</span> <span class="ss">:height</span><span class="p">,</span> <span class="ss">:weight</span> <span class="o">]</span>

<span class="k">end</span>

<span class="c1"># When Instantiated...</span>
<span class="n">user</span> <span class="o">=</span> <span class="no">User</span><span class="o">.</span><span class="n">new</span>
<span class="n">user</span><span class="o">.</span><span class="n">first_name</span> <span class="o">=</span> <span class="s1">&#39;mati&#39;</span> <span class="c1"># This is a regular attribute</span>
<span class="n">user</span><span class="o">.</span><span class="n">last_name</span> <span class="o">=</span> <span class="s1">&#39;pati&#39;</span>
<span class="n">user</span><span class="o">.</span><span class="n">age</span> <span class="o">=</span> <span class="mi">0</span>
<span class="n">user</span><span class="o">.</span><span class="n">height</span> <span class="o">=</span> <span class="mi">20</span> <span class="c1"># This is an ActiveReload attribute</span>
<span class="n">user</span><span class="o">.</span><span class="n">width</span> <span class="o">=</span> <span class="mi">10</span>
<span class="n">user</span><span class="o">.</span><span class="n">width</span> <span class="c1"># This is a getter method for the width attribute within the details value</span>
<span class="n">user</span><span class="o">.</span><span class="n">details</span><span class="o">[</span><span class="ss">:waist_length</span><span class="o">]</span> <span class="o">=</span> <span class="mi">100</span> <span class="c1"># This is not a setter, but rather a hash key of the details hash (this will get serialized into the hash later regardless)</span>

<span class="n">user</span><span class="o">.</span><span class="n">save</span>

<span class="c1"># Now if you look in the database then the storage value of the record will be as follows</span>
<span class="n">first_name</span><span class="p">:</span> <span class="s2">&quot;mati&quot;</span>
<span class="n">last_name</span><span class="p">:</span> <span class="s2">&quot;pati&quot;</span>
<span class="n">age</span><span class="p">:</span> <span class="mi">0</span>
<span class="n">details</span><span class="p">:</span> <span class="s2">&quot;{ height: &#39;20&#39;, width: &#39;10&#39;, waist_length: 100 }&quot;</span>
</pre></div>


</div>
<p><em>Active Record Store</em> is a great idea for when you need to store optional data into a database record. One thing to keep in mind, however, is <em>this does go against the 1st rule of normalization</em>. This database storage method also makes database searching of the record unpractical when a search is issued on the storage column.
</p>
<p><h3>More about Rails 3.2</h3>
<p>Some of the other things I noticed about 3.2 was that the development mode is alot faster. Rails startup and migration creation are much faster. Routes also load and parse faster. Other features such as <em>Explain Queries</em>, <em>Compression of Page Cached Files</em> and <em>Tagged Logging</em> are among the many new features provided by rails.
</p>
<p><h3>Some Street Cred</h3>
<p>Here are some more links to follow up on Rails 3.2</p>
<ol class="links">
<li><a class="em ignore-xview" target="_blank" href="http://weblog.rubyonrails.org/2012/1/20/rails-3-2-0-faster-dev-mode-routing-explain-queries-tagged-logger-store">http://weblog.rubyonrails.org/2012/1/20/rails-3-2-0-faster-dev-mode-routing-explain-queries-tagged-logger-store</a></li>
<li><a class="em ignore-xview" target="_blank"  href="http://guides.rubyonrails.org/3_2_release_notes.html">http://guides.rubyonrails.org/3_2_release_notes.html</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://yearofmoo.com/2012/01/rails-3-2-and-active-record-store/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Rails Page Caching and Internationalization</title>
		<link>http://yearofmoo.com/2011/12/rails-page-caching-and-internationalization/</link>
		<comments>http://yearofmoo.com/2011/12/rails-page-caching-and-internationalization/#comments</comments>
		<pubDate>Fri, 30 Dec 2011 04:29:54 +0000</pubDate>
		<dc:creator>matsko</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://yearofmoo.com/?p=863</guid>
		<description><![CDATA[How to hack your Rails application to configure how page caches are stored Rails offers an effective caching solution for caching pages using page_caching. This stores the entire output of a request into a publicly accessible file which is then picked up by the web server first before the request is made to Rails. The [...]]]></description>
			<content:encoded><![CDATA[<h3>How to hack your Rails application to configure how page caches are stored</h3>
<p>Rails offers an effective caching solution for caching pages using page_caching. This stores the entire output of a request into a <em>publicly accessible file</em> which is then picked up by the web server first before the request is made to Rails. The Rails default method to set the path of the is something that doesn&#8217;t take <em>the locale</em> nor the <em>subdomain</em> into consideration. So if you have a subdomain that is bound to the same Rails server, then the page caching will not append any of that to the name of the cached page file. This blog article will explain how to change this behaviour.<br />
<span id="more-863"></span></p>
<p><h3>Last Updated</h3>
<p>This page was last updated on <strong class="em">December 29th 2011</strong> and was first published on <strong class="em">May 9th 2012</strong>
</p>
<p><h3>How (where) Rails stores its page cached files</h3>
<p>The page that Rails (up to and including its latest version Rails 3.1) stores its page caches are in <em>/public folder of the project root</em>. This configuration can be configured within the <em>application.rb</em> file by setting the following configuration:</p>
<pre><code>config.action_controller.page_cache_directory = <em>Rails.root.to_s + "/public"</em></code></pre>
</p>
<p>When a <em>caches_page</em> directive is set within a controller for a particular action then the page caching sets up the <em>path of the URL to be the path of the cache file</em>. This can be changed within some function overriding.</p>
<p><h3>How to override it</h3>
<p>In your <em>app/controllers/application_controller.rb</em> set the following code to change the way that the file is written. Here is the default:</p>
<div class="syntax">
<style type="text/css">


/* *************************************************** */
/* WordPress default theme "twenty-ten" compatibility: */
/* FIXME: Is there a way to limit these changes to pygmentize_oJBU6s  */
/*        without editing the WordPress theme directly? */
/* *************************************************** */

.syntax pre {
  /* The background: transparent is needed to work with WordPress:*/
  background: transparent;
  /* Default WordPress style has a big fat <pre> margin-bottom: */
  margin-bottom: 0px;

  /*color: #333333;*/
  font-size: .9em; 
  line-height: 1.25em;
}

.syntax table {
	border: 1px solid #e7e7e7;
    margin: 0 0 0 0;
	text-align: left;
	width: 100%;
}
.syntax tr th,
.syntax thead th {
	color: #888;
	font-size: 12px;
	font-weight: bold;
	line-height: 18px;
	padding: 0px;
}
.syntax tr td {
	border: 0px;
	padding: 0px;
	margin: 0px;
    margin-bottom: 0px;
    padding-bottom: 0px;

}

/* *************************************************** */
/* *************************************************** */

/* Standard fixes to the default output: */

/* Set the tab width in "ch" character units: */
.pygmentize_oJBU6s .tabspan {
  display: inline-block;
  width: 4ch;
}

/* When using line numbers, use 100% table width and no cellpadding: */
.pygmentize_oJBU6stable {
  width: 100%;
  border-spacing: 0px;
  border-collapse: collapse;
}


/*
.syntax table {
    border: 1px solid #E7E7E7;
    margin: 0 -1px 24px 0;
    text-align: left;
    width: 100%;
}
*/

.pygmentize_oJBU6stable td, .pygmentize_oJBU6stable th {
  padding: 0px;
  margin: 0px;
}

/* Add a little buffer so the monotype font doesn't bump directly against the edge: */
.pygmentize_oJBU6s pre {
  padding: .6ch;
  
}

/* This is more consistent with <p> tags... I didn't like it for my use: */
/*
div .pygmentize_oJBU6s {
    margin-bottom: 24px; 
}
*/

td.linenos.pygmentize_oJBU6s {
  width: 1ch;
  padding: .6ch;
  line-height: 1.25em;
}

.pygmentize_oJBU6s td {
  padding-right: 1px;
}


td.linenos { background-color: #f0f0f0; padding-right: 1px; }
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
pre { line-height: 125%; }
.pygmentize_oJBU6s .hll { background-color: #404040 }
.pygmentize_oJBU6s  { background: #202020; color: #d0d0d0 }
.pygmentize_oJBU6s .c { color: #999999; font-style: italic } /* Comment */
.pygmentize_oJBU6s .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.pygmentize_oJBU6s .g { color: #d0d0d0 } /* Generic */
.pygmentize_oJBU6s .k { color: #6ab825; font-weight: bold } /* Keyword */
.pygmentize_oJBU6s .l { color: #d0d0d0 } /* Literal */
.pygmentize_oJBU6s .n { color: #d0d0d0 } /* Name */
.pygmentize_oJBU6s .o { color: #d0d0d0 } /* Operator */
.pygmentize_oJBU6s .x { color: #d0d0d0 } /* Other */
.pygmentize_oJBU6s .p { color: #d0d0d0 } /* Punctuation */
.pygmentize_oJBU6s .cm { color: #999999; font-style: italic } /* Comment.Multiline */
.pygmentize_oJBU6s .cp { color: #cd2828; font-weight: bold } /* Comment.Preproc */
.pygmentize_oJBU6s .c1 { color: #999999; font-style: italic } /* Comment.Single */
.pygmentize_oJBU6s .cs { color: #e50808; font-weight: bold; background-color: #520000 } /* Comment.Special */
.pygmentize_oJBU6s .gd { color: #d22323 } /* Generic.Deleted */
.pygmentize_oJBU6s .ge { color: #d0d0d0; font-style: italic } /* Generic.Emph */
.pygmentize_oJBU6s .gr { color: #d22323 } /* Generic.Error */
.pygmentize_oJBU6s .gh { color: #ffffff; font-weight: bold } /* Generic.Heading */
.pygmentize_oJBU6s .gi { color: #589819 } /* Generic.Inserted */
.pygmentize_oJBU6s .go { color: #cccccc } /* Generic.Output */
.pygmentize_oJBU6s .gp { color: #aaaaaa } /* Generic.Prompt */
.pygmentize_oJBU6s .gs { color: #d0d0d0; font-weight: bold } /* Generic.Strong */
.pygmentize_oJBU6s .gu { color: #ffffff; text-decoration: underline } /* Generic.Subheading */
.pygmentize_oJBU6s .gt { color: #d22323 } /* Generic.Traceback */
.pygmentize_oJBU6s .kc { color: #6ab825; font-weight: bold } /* Keyword.Constant */
.pygmentize_oJBU6s .kd { color: #6ab825; font-weight: bold } /* Keyword.Declaration */
.pygmentize_oJBU6s .kn { color: #6ab825; font-weight: bold } /* Keyword.Namespace */
.pygmentize_oJBU6s .kp { color: #6ab825 } /* Keyword.Pseudo */
.pygmentize_oJBU6s .kr { color: #6ab825; font-weight: bold } /* Keyword.Reserved */
.pygmentize_oJBU6s .kt { color: #6ab825; font-weight: bold } /* Keyword.Type */
.pygmentize_oJBU6s .ld { color: #d0d0d0 } /* Literal.Date */
.pygmentize_oJBU6s .m { color: #3677a9 } /* Literal.Number */
.pygmentize_oJBU6s .s { color: #ed9d13 } /* Literal.String */
.pygmentize_oJBU6s .na { color: #bbbbbb } /* Name.Attribute */
.pygmentize_oJBU6s .nb { color: #24909d } /* Name.Builtin */
.pygmentize_oJBU6s .nc { color: #447fcf; text-decoration: underline } /* Name.Class */
.pygmentize_oJBU6s .no { color: #40ffff } /* Name.Constant */
.pygmentize_oJBU6s .nd { color: #ffa500 } /* Name.Decorator */
.pygmentize_oJBU6s .ni { color: #d0d0d0 } /* Name.Entity */
.pygmentize_oJBU6s .ne { color: #bbbbbb } /* Name.Exception */
.pygmentize_oJBU6s .nf { color: #447fcf } /* Name.Function */
.pygmentize_oJBU6s .nl { color: #d0d0d0 } /* Name.Label */
.pygmentize_oJBU6s .nn { color: #447fcf; text-decoration: underline } /* Name.Namespace */
.pygmentize_oJBU6s .nx { color: #d0d0d0 } /* Name.Other */
.pygmentize_oJBU6s .py { color: #d0d0d0 } /* Name.Property */
.pygmentize_oJBU6s .nt { color: #6ab825; font-weight: bold } /* Name.Tag */
.pygmentize_oJBU6s .nv { color: #40ffff } /* Name.Variable */
.pygmentize_oJBU6s .ow { color: #6ab825; font-weight: bold } /* Operator.Word */
.pygmentize_oJBU6s .w { color: #666666 } /* Text.Whitespace */
.pygmentize_oJBU6s .mf { color: #3677a9 } /* Literal.Number.Float */
.pygmentize_oJBU6s .mh { color: #3677a9 } /* Literal.Number.Hex */
.pygmentize_oJBU6s .mi { color: #3677a9 } /* Literal.Number.Integer */
.pygmentize_oJBU6s .mo { color: #3677a9 } /* Literal.Number.Oct */
.pygmentize_oJBU6s .sb { color: #ed9d13 } /* Literal.String.Backtick */
.pygmentize_oJBU6s .sc { color: #ed9d13 } /* Literal.String.Char */
.pygmentize_oJBU6s .sd { color: #ed9d13 } /* Literal.String.Doc */
.pygmentize_oJBU6s .s2 { color: #ed9d13 } /* Literal.String.Double */
.pygmentize_oJBU6s .se { color: #ed9d13 } /* Literal.String.Escape */
.pygmentize_oJBU6s .sh { color: #ed9d13 } /* Literal.String.Heredoc */
.pygmentize_oJBU6s .si { color: #ed9d13 } /* Literal.String.Interpol */
.pygmentize_oJBU6s .sx { color: #ffa500 } /* Literal.String.Other */
.pygmentize_oJBU6s .sr { color: #ed9d13 } /* Literal.String.Regex */
.pygmentize_oJBU6s .s1 { color: #ed9d13 } /* Literal.String.Single */
.pygmentize_oJBU6s .ss { color: #ed9d13 } /* Literal.String.Symbol */
.pygmentize_oJBU6s .bp { color: #24909d } /* Name.Builtin.Pseudo */
.pygmentize_oJBU6s .vc { color: #40ffff } /* Name.Variable.Class */
.pygmentize_oJBU6s .vg { color: #40ffff } /* Name.Variable.Global */
.pygmentize_oJBU6s .vi { color: #40ffff } /* Name.Variable.Instance */
.pygmentize_oJBU6s .il { color: #3677a9 } /* Literal.Number.Integer.Long */

  </style>




<div class="pygmentize_oJBU6s"><pre><span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">page_cache_path</span><span class="p">(</span><span class="n">path</span><span class="p">,</span><span class="n">extension</span><span class="p">)</span>
  <span class="c1"># Default</span>
  <span class="no">MyApp</span><span class="o">::</span><span class="no">Application</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">action_controller</span><span class="o">.</span><span class="n">page_cache_directory</span> <span class="o">+</span> <span class="n">path</span> <span class="o">+</span> <span class="n">extension</span>
<span class="k">end</span>
</pre></div>


</div>
</p>
<p>
Now lets imagine if you were to include the <em>locale</em> into the mix:</p>
<div class="syntax">
<style type="text/css">


/* *************************************************** */
/* WordPress default theme "twenty-ten" compatibility: */
/* FIXME: Is there a way to limit these changes to pygmentize_jAceDs  */
/*        without editing the WordPress theme directly? */
/* *************************************************** */

.syntax pre {
  /* The background: transparent is needed to work with WordPress:*/
  background: transparent;
  /* Default WordPress style has a big fat <pre> margin-bottom: */
  margin-bottom: 0px;

  /*color: #333333;*/
  font-size: .9em; 
  line-height: 1.25em;
}

.syntax table {
	border: 1px solid #e7e7e7;
    margin: 0 0 0 0;
	text-align: left;
	width: 100%;
}
.syntax tr th,
.syntax thead th {
	color: #888;
	font-size: 12px;
	font-weight: bold;
	line-height: 18px;
	padding: 0px;
}
.syntax tr td {
	border: 0px;
	padding: 0px;
	margin: 0px;
    margin-bottom: 0px;
    padding-bottom: 0px;

}

/* *************************************************** */
/* *************************************************** */

/* Standard fixes to the default output: */

/* Set the tab width in "ch" character units: */
.pygmentize_jAceDs .tabspan {
  display: inline-block;
  width: 4ch;
}

/* When using line numbers, use 100% table width and no cellpadding: */
.pygmentize_jAceDstable {
  width: 100%;
  border-spacing: 0px;
  border-collapse: collapse;
}


/*
.syntax table {
    border: 1px solid #E7E7E7;
    margin: 0 -1px 24px 0;
    text-align: left;
    width: 100%;
}
*/

.pygmentize_jAceDstable td, .pygmentize_jAceDstable th {
  padding: 0px;
  margin: 0px;
}

/* Add a little buffer so the monotype font doesn't bump directly against the edge: */
.pygmentize_jAceDs pre {
  padding: .6ch;
  
}

/* This is more consistent with <p> tags... I didn't like it for my use: */
/*
div .pygmentize_jAceDs {
    margin-bottom: 24px; 
}
*/

td.linenos.pygmentize_jAceDs {
  width: 1ch;
  padding: .6ch;
  line-height: 1.25em;
}

.pygmentize_jAceDs td {
  padding-right: 1px;
}


td.linenos { background-color: #f0f0f0; padding-right: 1px; }
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
pre { line-height: 125%; }
.pygmentize_jAceDs .hll { background-color: #404040 }
.pygmentize_jAceDs  { background: #202020; color: #d0d0d0 }
.pygmentize_jAceDs .c { color: #999999; font-style: italic } /* Comment */
.pygmentize_jAceDs .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.pygmentize_jAceDs .g { color: #d0d0d0 } /* Generic */
.pygmentize_jAceDs .k { color: #6ab825; font-weight: bold } /* Keyword */
.pygmentize_jAceDs .l { color: #d0d0d0 } /* Literal */
.pygmentize_jAceDs .n { color: #d0d0d0 } /* Name */
.pygmentize_jAceDs .o { color: #d0d0d0 } /* Operator */
.pygmentize_jAceDs .x { color: #d0d0d0 } /* Other */
.pygmentize_jAceDs .p { color: #d0d0d0 } /* Punctuation */
.pygmentize_jAceDs .cm { color: #999999; font-style: italic } /* Comment.Multiline */
.pygmentize_jAceDs .cp { color: #cd2828; font-weight: bold } /* Comment.Preproc */
.pygmentize_jAceDs .c1 { color: #999999; font-style: italic } /* Comment.Single */
.pygmentize_jAceDs .cs { color: #e50808; font-weight: bold; background-color: #520000 } /* Comment.Special */
.pygmentize_jAceDs .gd { color: #d22323 } /* Generic.Deleted */
.pygmentize_jAceDs .ge { color: #d0d0d0; font-style: italic } /* Generic.Emph */
.pygmentize_jAceDs .gr { color: #d22323 } /* Generic.Error */
.pygmentize_jAceDs .gh { color: #ffffff; font-weight: bold } /* Generic.Heading */
.pygmentize_jAceDs .gi { color: #589819 } /* Generic.Inserted */
.pygmentize_jAceDs .go { color: #cccccc } /* Generic.Output */
.pygmentize_jAceDs .gp { color: #aaaaaa } /* Generic.Prompt */
.pygmentize_jAceDs .gs { color: #d0d0d0; font-weight: bold } /* Generic.Strong */
.pygmentize_jAceDs .gu { color: #ffffff; text-decoration: underline } /* Generic.Subheading */
.pygmentize_jAceDs .gt { color: #d22323 } /* Generic.Traceback */
.pygmentize_jAceDs .kc { color: #6ab825; font-weight: bold } /* Keyword.Constant */
.pygmentize_jAceDs .kd { color: #6ab825; font-weight: bold } /* Keyword.Declaration */
.pygmentize_jAceDs .kn { color: #6ab825; font-weight: bold } /* Keyword.Namespace */
.pygmentize_jAceDs .kp { color: #6ab825 } /* Keyword.Pseudo */
.pygmentize_jAceDs .kr { color: #6ab825; font-weight: bold } /* Keyword.Reserved */
.pygmentize_jAceDs .kt { color: #6ab825; font-weight: bold } /* Keyword.Type */
.pygmentize_jAceDs .ld { color: #d0d0d0 } /* Literal.Date */
.pygmentize_jAceDs .m { color: #3677a9 } /* Literal.Number */
.pygmentize_jAceDs .s { color: #ed9d13 } /* Literal.String */
.pygmentize_jAceDs .na { color: #bbbbbb } /* Name.Attribute */
.pygmentize_jAceDs .nb { color: #24909d } /* Name.Builtin */
.pygmentize_jAceDs .nc { color: #447fcf; text-decoration: underline } /* Name.Class */
.pygmentize_jAceDs .no { color: #40ffff } /* Name.Constant */
.pygmentize_jAceDs .nd { color: #ffa500 } /* Name.Decorator */
.pygmentize_jAceDs .ni { color: #d0d0d0 } /* Name.Entity */
.pygmentize_jAceDs .ne { color: #bbbbbb } /* Name.Exception */
.pygmentize_jAceDs .nf { color: #447fcf } /* Name.Function */
.pygmentize_jAceDs .nl { color: #d0d0d0 } /* Name.Label */
.pygmentize_jAceDs .nn { color: #447fcf; text-decoration: underline } /* Name.Namespace */
.pygmentize_jAceDs .nx { color: #d0d0d0 } /* Name.Other */
.pygmentize_jAceDs .py { color: #d0d0d0 } /* Name.Property */
.pygmentize_jAceDs .nt { color: #6ab825; font-weight: bold } /* Name.Tag */
.pygmentize_jAceDs .nv { color: #40ffff } /* Name.Variable */
.pygmentize_jAceDs .ow { color: #6ab825; font-weight: bold } /* Operator.Word */
.pygmentize_jAceDs .w { color: #666666 } /* Text.Whitespace */
.pygmentize_jAceDs .mf { color: #3677a9 } /* Literal.Number.Float */
.pygmentize_jAceDs .mh { color: #3677a9 } /* Literal.Number.Hex */
.pygmentize_jAceDs .mi { color: #3677a9 } /* Literal.Number.Integer */
.pygmentize_jAceDs .mo { color: #3677a9 } /* Literal.Number.Oct */
.pygmentize_jAceDs .sb { color: #ed9d13 } /* Literal.String.Backtick */
.pygmentize_jAceDs .sc { color: #ed9d13 } /* Literal.String.Char */
.pygmentize_jAceDs .sd { color: #ed9d13 } /* Literal.String.Doc */
.pygmentize_jAceDs .s2 { color: #ed9d13 } /* Literal.String.Double */
.pygmentize_jAceDs .se { color: #ed9d13 } /* Literal.String.Escape */
.pygmentize_jAceDs .sh { color: #ed9d13 } /* Literal.String.Heredoc */
.pygmentize_jAceDs .si { color: #ed9d13 } /* Literal.String.Interpol */
.pygmentize_jAceDs .sx { color: #ffa500 } /* Literal.String.Other */
.pygmentize_jAceDs .sr { color: #ed9d13 } /* Literal.String.Regex */
.pygmentize_jAceDs .s1 { color: #ed9d13 } /* Literal.String.Single */
.pygmentize_jAceDs .ss { color: #ed9d13 } /* Literal.String.Symbol */
.pygmentize_jAceDs .bp { color: #24909d } /* Name.Builtin.Pseudo */
.pygmentize_jAceDs .vc { color: #40ffff } /* Name.Variable.Class */
.pygmentize_jAceDs .vg { color: #40ffff } /* Name.Variable.Global */
.pygmentize_jAceDs .vi { color: #40ffff } /* Name.Variable.Instance */
.pygmentize_jAceDs .il { color: #3677a9 } /* Literal.Number.Integer.Long */

  </style>




<div class="pygmentize_jAceDs"><pre><span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">page_cache_path</span><span class="p">(</span><span class="n">path</span><span class="p">,</span><span class="n">extension</span><span class="p">)</span>
  <span class="c1"># Appending the locale</span>
  <span class="n">path</span> <span class="o">+=</span> <span class="s1">&#39;-&#39;</span> <span class="o">+</span> <span class="no">I18n</span><span class="o">.</span><span class="n">locale</span><span class="o">.</span><span class="n">to_s</span>

  <span class="c1"># /users/1/search will be stored as public/users/1/search-en.html (or without the .html)</span>
  <span class="no">MyApp</span><span class="o">::</span><span class="no">Application</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">action_controller</span><span class="o">.</span><span class="n">page_cache_directory</span> <span class="o">+</span> <span class="n">path</span> <span class="o">+</span> <span class="n">extension</span>
<span class="k">end</span>
</pre></div>


</div>
<p>And we can also include the <em>subdomain</em>. Lets imagine that <em>www is the default locale &#8230; English (en)</em> and anything else is <em>non-www</em>. The only issue is that the <em>page_cache_path method is a class-level method (static)</em> so the request object won&#8217;t be recognized by the class method. We&#8217;ll need to add a class variable as a before filter:</p>
<div class="syntax">
<style type="text/css">


/* *************************************************** */
/* WordPress default theme "twenty-ten" compatibility: */
/* FIXME: Is there a way to limit these changes to pygmentize_rJCPus  */
/*        without editing the WordPress theme directly? */
/* *************************************************** */

.syntax pre {
  /* The background: transparent is needed to work with WordPress:*/
  background: transparent;
  /* Default WordPress style has a big fat <pre> margin-bottom: */
  margin-bottom: 0px;

  /*color: #333333;*/
  font-size: .9em; 
  line-height: 1.25em;
}

.syntax table {
	border: 1px solid #e7e7e7;
    margin: 0 0 0 0;
	text-align: left;
	width: 100%;
}
.syntax tr th,
.syntax thead th {
	color: #888;
	font-size: 12px;
	font-weight: bold;
	line-height: 18px;
	padding: 0px;
}
.syntax tr td {
	border: 0px;
	padding: 0px;
	margin: 0px;
    margin-bottom: 0px;
    padding-bottom: 0px;

}

/* *************************************************** */
/* *************************************************** */

/* Standard fixes to the default output: */

/* Set the tab width in "ch" character units: */
.pygmentize_rJCPus .tabspan {
  display: inline-block;
  width: 4ch;
}

/* When using line numbers, use 100% table width and no cellpadding: */
.pygmentize_rJCPustable {
  width: 100%;
  border-spacing: 0px;
  border-collapse: collapse;
}


/*
.syntax table {
    border: 1px solid #E7E7E7;
    margin: 0 -1px 24px 0;
    text-align: left;
    width: 100%;
}
*/

.pygmentize_rJCPustable td, .pygmentize_rJCPustable th {
  padding: 0px;
  margin: 0px;
}

/* Add a little buffer so the monotype font doesn't bump directly against the edge: */
.pygmentize_rJCPus pre {
  padding: .6ch;
  
}

/* This is more consistent with <p> tags... I didn't like it for my use: */
/*
div .pygmentize_rJCPus {
    margin-bottom: 24px; 
}
*/

td.linenos.pygmentize_rJCPus {
  width: 1ch;
  padding: .6ch;
  line-height: 1.25em;
}

.pygmentize_rJCPus td {
  padding-right: 1px;
}


td.linenos { background-color: #f0f0f0; padding-right: 1px; }
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
pre { line-height: 125%; }
.pygmentize_rJCPus .hll { background-color: #404040 }
.pygmentize_rJCPus  { background: #202020; color: #d0d0d0 }
.pygmentize_rJCPus .c { color: #999999; font-style: italic } /* Comment */
.pygmentize_rJCPus .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.pygmentize_rJCPus .g { color: #d0d0d0 } /* Generic */
.pygmentize_rJCPus .k { color: #6ab825; font-weight: bold } /* Keyword */
.pygmentize_rJCPus .l { color: #d0d0d0 } /* Literal */
.pygmentize_rJCPus .n { color: #d0d0d0 } /* Name */
.pygmentize_rJCPus .o { color: #d0d0d0 } /* Operator */
.pygmentize_rJCPus .x { color: #d0d0d0 } /* Other */
.pygmentize_rJCPus .p { color: #d0d0d0 } /* Punctuation */
.pygmentize_rJCPus .cm { color: #999999; font-style: italic } /* Comment.Multiline */
.pygmentize_rJCPus .cp { color: #cd2828; font-weight: bold } /* Comment.Preproc */
.pygmentize_rJCPus .c1 { color: #999999; font-style: italic } /* Comment.Single */
.pygmentize_rJCPus .cs { color: #e50808; font-weight: bold; background-color: #520000 } /* Comment.Special */
.pygmentize_rJCPus .gd { color: #d22323 } /* Generic.Deleted */
.pygmentize_rJCPus .ge { color: #d0d0d0; font-style: italic } /* Generic.Emph */
.pygmentize_rJCPus .gr { color: #d22323 } /* Generic.Error */
.pygmentize_rJCPus .gh { color: #ffffff; font-weight: bold } /* Generic.Heading */
.pygmentize_rJCPus .gi { color: #589819 } /* Generic.Inserted */
.pygmentize_rJCPus .go { color: #cccccc } /* Generic.Output */
.pygmentize_rJCPus .gp { color: #aaaaaa } /* Generic.Prompt */
.pygmentize_rJCPus .gs { color: #d0d0d0; font-weight: bold } /* Generic.Strong */
.pygmentize_rJCPus .gu { color: #ffffff; text-decoration: underline } /* Generic.Subheading */
.pygmentize_rJCPus .gt { color: #d22323 } /* Generic.Traceback */
.pygmentize_rJCPus .kc { color: #6ab825; font-weight: bold } /* Keyword.Constant */
.pygmentize_rJCPus .kd { color: #6ab825; font-weight: bold } /* Keyword.Declaration */
.pygmentize_rJCPus .kn { color: #6ab825; font-weight: bold } /* Keyword.Namespace */
.pygmentize_rJCPus .kp { color: #6ab825 } /* Keyword.Pseudo */
.pygmentize_rJCPus .kr { color: #6ab825; font-weight: bold } /* Keyword.Reserved */
.pygmentize_rJCPus .kt { color: #6ab825; font-weight: bold } /* Keyword.Type */
.pygmentize_rJCPus .ld { color: #d0d0d0 } /* Literal.Date */
.pygmentize_rJCPus .m { color: #3677a9 } /* Literal.Number */
.pygmentize_rJCPus .s { color: #ed9d13 } /* Literal.String */
.pygmentize_rJCPus .na { color: #bbbbbb } /* Name.Attribute */
.pygmentize_rJCPus .nb { color: #24909d } /* Name.Builtin */
.pygmentize_rJCPus .nc { color: #447fcf; text-decoration: underline } /* Name.Class */
.pygmentize_rJCPus .no { color: #40ffff } /* Name.Constant */
.pygmentize_rJCPus .nd { color: #ffa500 } /* Name.Decorator */
.pygmentize_rJCPus .ni { color: #d0d0d0 } /* Name.Entity */
.pygmentize_rJCPus .ne { color: #bbbbbb } /* Name.Exception */
.pygmentize_rJCPus .nf { color: #447fcf } /* Name.Function */
.pygmentize_rJCPus .nl { color: #d0d0d0 } /* Name.Label */
.pygmentize_rJCPus .nn { color: #447fcf; text-decoration: underline } /* Name.Namespace */
.pygmentize_rJCPus .nx { color: #d0d0d0 } /* Name.Other */
.pygmentize_rJCPus .py { color: #d0d0d0 } /* Name.Property */
.pygmentize_rJCPus .nt { color: #6ab825; font-weight: bold } /* Name.Tag */
.pygmentize_rJCPus .nv { color: #40ffff } /* Name.Variable */
.pygmentize_rJCPus .ow { color: #6ab825; font-weight: bold } /* Operator.Word */
.pygmentize_rJCPus .w { color: #666666 } /* Text.Whitespace */
.pygmentize_rJCPus .mf { color: #3677a9 } /* Literal.Number.Float */
.pygmentize_rJCPus .mh { color: #3677a9 } /* Literal.Number.Hex */
.pygmentize_rJCPus .mi { color: #3677a9 } /* Literal.Number.Integer */
.pygmentize_rJCPus .mo { color: #3677a9 } /* Literal.Number.Oct */
.pygmentize_rJCPus .sb { color: #ed9d13 } /* Literal.String.Backtick */
.pygmentize_rJCPus .sc { color: #ed9d13 } /* Literal.String.Char */
.pygmentize_rJCPus .sd { color: #ed9d13 } /* Literal.String.Doc */
.pygmentize_rJCPus .s2 { color: #ed9d13 } /* Literal.String.Double */
.pygmentize_rJCPus .se { color: #ed9d13 } /* Literal.String.Escape */
.pygmentize_rJCPus .sh { color: #ed9d13 } /* Literal.String.Heredoc */
.pygmentize_rJCPus .si { color: #ed9d13 } /* Literal.String.Interpol */
.pygmentize_rJCPus .sx { color: #ffa500 } /* Literal.String.Other */
.pygmentize_rJCPus .sr { color: #ed9d13 } /* Literal.String.Regex */
.pygmentize_rJCPus .s1 { color: #ed9d13 } /* Literal.String.Single */
.pygmentize_rJCPus .ss { color: #ed9d13 } /* Literal.String.Symbol */
.pygmentize_rJCPus .bp { color: #24909d } /* Name.Builtin.Pseudo */
.pygmentize_rJCPus .vc { color: #40ffff } /* Name.Variable.Class */
.pygmentize_rJCPus .vg { color: #40ffff } /* Name.Variable.Global */
.pygmentize_rJCPus .vi { color: #40ffff } /* Name.Variable.Instance */
.pygmentize_rJCPus .il { color: #3677a9 } /* Literal.Number.Integer.Long */

  </style>




<div class="pygmentize_rJCPus"><pre><span class="n">before_filter</span> <span class="ss">:prepare_subdomain</span>

<span class="k">def</span> <span class="nf">prepare_subdomain</span>
  <span class="vc">@@subdomain</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">subdomains</span><span class="o">.</span><span class="n">first</span><span class="o">.</span><span class="n">to_s</span>
<span class="k">end</span>

<span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">page_cache_path</span><span class="p">(</span><span class="n">path</span><span class="p">,</span><span class="n">extension</span><span class="p">)</span>
  <span class="n">path</span> <span class="o">+=</span> <span class="s1">&#39;-&#39;</span> <span class="o">+</span> <span class="vc">@@subdomain</span>
  <span class="no">MyApp</span><span class="o">::</span><span class="no">Application</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">action_controller</span><span class="o">.</span><span class="n">page_cache_directory</span> <span class="o">+</span> <span class="n">path</span> <span class="o">+</span> <span class="n">extension</span>
<span class="k">end</span>
</pre></div>


</div>
</p>
<p><h3>Configuring your HTTP Server</h3>
<p>So far I&#8217;ve only done this with NGINX. What needs to be done is to configure your <em>NGINX server to recognize that the page cached file is there before it fires up the Rails request</em>. Here is my configuration file:</p>
<div class="syntax">
<style type="text/css">


/* *************************************************** */
/* WordPress default theme "twenty-ten" compatibility: */
/* FIXME: Is there a way to limit these changes to pygmentize_G6wjIs  */
/*        without editing the WordPress theme directly? */
/* *************************************************** */

.syntax pre {
  /* The background: transparent is needed to work with WordPress:*/
  background: transparent;
  /* Default WordPress style has a big fat <pre> margin-bottom: */
  margin-bottom: 0px;

  /*color: #333333;*/
  font-size: .9em; 
  line-height: 1.25em;
}

.syntax table {
	border: 1px solid #e7e7e7;
    margin: 0 0 0 0;
	text-align: left;
	width: 100%;
}
.syntax tr th,
.syntax thead th {
	color: #888;
	font-size: 12px;
	font-weight: bold;
	line-height: 18px;
	padding: 0px;
}
.syntax tr td {
	border: 0px;
	padding: 0px;
	margin: 0px;
    margin-bottom: 0px;
    padding-bottom: 0px;

}

/* *************************************************** */
/* *************************************************** */

/* Standard fixes to the default output: */

/* Set the tab width in "ch" character units: */
.pygmentize_G6wjIs .tabspan {
  display: inline-block;
  width: 4ch;
}

/* When using line numbers, use 100% table width and no cellpadding: */
.pygmentize_G6wjIstable {
  width: 100%;
  border-spacing: 0px;
  border-collapse: collapse;
}


/*
.syntax table {
    border: 1px solid #E7E7E7;
    margin: 0 -1px 24px 0;
    text-align: left;
    width: 100%;
}
*/

.pygmentize_G6wjIstable td, .pygmentize_G6wjIstable th {
  padding: 0px;
  margin: 0px;
}

/* Add a little buffer so the monotype font doesn't bump directly against the edge: */
.pygmentize_G6wjIs pre {
  padding: .6ch;
  
}

/* This is more consistent with <p> tags... I didn't like it for my use: */
/*
div .pygmentize_G6wjIs {
    margin-bottom: 24px; 
}
*/

td.linenos.pygmentize_G6wjIs {
  width: 1ch;
  padding: .6ch;
  line-height: 1.25em;
}

.pygmentize_G6wjIs td {
  padding-right: 1px;
}


td.linenos { background-color: #f0f0f0; padding-right: 1px; }
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
pre { line-height: 125%; }
.pygmentize_G6wjIs .hll { background-color: #404040 }
.pygmentize_G6wjIs  { background: #202020; color: #d0d0d0 }
.pygmentize_G6wjIs .c { color: #999999; font-style: italic } /* Comment */
.pygmentize_G6wjIs .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.pygmentize_G6wjIs .g { color: #d0d0d0 } /* Generic */
.pygmentize_G6wjIs .k { color: #6ab825; font-weight: bold } /* Keyword */
.pygmentize_G6wjIs .l { color: #d0d0d0 } /* Literal */
.pygmentize_G6wjIs .n { color: #d0d0d0 } /* Name */
.pygmentize_G6wjIs .o { color: #d0d0d0 } /* Operator */
.pygmentize_G6wjIs .x { color: #d0d0d0 } /* Other */
.pygmentize_G6wjIs .p { color: #d0d0d0 } /* Punctuation */
.pygmentize_G6wjIs .cm { color: #999999; font-style: italic } /* Comment.Multiline */
.pygmentize_G6wjIs .cp { color: #cd2828; font-weight: bold } /* Comment.Preproc */
.pygmentize_G6wjIs .c1 { color: #999999; font-style: italic } /* Comment.Single */
.pygmentize_G6wjIs .cs { color: #e50808; font-weight: bold; background-color: #520000 } /* Comment.Special */
.pygmentize_G6wjIs .gd { color: #d22323 } /* Generic.Deleted */
.pygmentize_G6wjIs .ge { color: #d0d0d0; font-style: italic } /* Generic.Emph */
.pygmentize_G6wjIs .gr { color: #d22323 } /* Generic.Error */
.pygmentize_G6wjIs .gh { color: #ffffff; font-weight: bold } /* Generic.Heading */
.pygmentize_G6wjIs .gi { color: #589819 } /* Generic.Inserted */
.pygmentize_G6wjIs .go { color: #cccccc } /* Generic.Output */
.pygmentize_G6wjIs .gp { color: #aaaaaa } /* Generic.Prompt */
.pygmentize_G6wjIs .gs { color: #d0d0d0; font-weight: bold } /* Generic.Strong */
.pygmentize_G6wjIs .gu { color: #ffffff; text-decoration: underline } /* Generic.Subheading */
.pygmentize_G6wjIs .gt { color: #d22323 } /* Generic.Traceback */
.pygmentize_G6wjIs .kc { color: #6ab825; font-weight: bold } /* Keyword.Constant */
.pygmentize_G6wjIs .kd { color: #6ab825; font-weight: bold } /* Keyword.Declaration */
.pygmentize_G6wjIs .kn { color: #6ab825; font-weight: bold } /* Keyword.Namespace */
.pygmentize_G6wjIs .kp { color: #6ab825 } /* Keyword.Pseudo */
.pygmentize_G6wjIs .kr { color: #6ab825; font-weight: bold } /* Keyword.Reserved */
.pygmentize_G6wjIs .kt { color: #6ab825; font-weight: bold } /* Keyword.Type */
.pygmentize_G6wjIs .ld { color: #d0d0d0 } /* Literal.Date */
.pygmentize_G6wjIs .m { color: #3677a9 } /* Literal.Number */
.pygmentize_G6wjIs .s { color: #ed9d13 } /* Literal.String */
.pygmentize_G6wjIs .na { color: #bbbbbb } /* Name.Attribute */
.pygmentize_G6wjIs .nb { color: #24909d } /* Name.Builtin */
.pygmentize_G6wjIs .nc { color: #447fcf; text-decoration: underline } /* Name.Class */
.pygmentize_G6wjIs .no { color: #40ffff } /* Name.Constant */
.pygmentize_G6wjIs .nd { color: #ffa500 } /* Name.Decorator */
.pygmentize_G6wjIs .ni { color: #d0d0d0 } /* Name.Entity */
.pygmentize_G6wjIs .ne { color: #bbbbbb } /* Name.Exception */
.pygmentize_G6wjIs .nf { color: #447fcf } /* Name.Function */
.pygmentize_G6wjIs .nl { color: #d0d0d0 } /* Name.Label */
.pygmentize_G6wjIs .nn { color: #447fcf; text-decoration: underline } /* Name.Namespace */
.pygmentize_G6wjIs .nx { color: #d0d0d0 } /* Name.Other */
.pygmentize_G6wjIs .py { color: #d0d0d0 } /* Name.Property */
.pygmentize_G6wjIs .nt { color: #6ab825; font-weight: bold } /* Name.Tag */
.pygmentize_G6wjIs .nv { color: #40ffff } /* Name.Variable */
.pygmentize_G6wjIs .ow { color: #6ab825; font-weight: bold } /* Operator.Word */
.pygmentize_G6wjIs .w { color: #666666 } /* Text.Whitespace */
.pygmentize_G6wjIs .mf { color: #3677a9 } /* Literal.Number.Float */
.pygmentize_G6wjIs .mh { color: #3677a9 } /* Literal.Number.Hex */
.pygmentize_G6wjIs .mi { color: #3677a9 } /* Literal.Number.Integer */
.pygmentize_G6wjIs .mo { color: #3677a9 } /* Literal.Number.Oct */
.pygmentize_G6wjIs .sb { color: #ed9d13 } /* Literal.String.Backtick */
.pygmentize_G6wjIs .sc { color: #ed9d13 } /* Literal.String.Char */
.pygmentize_G6wjIs .sd { color: #ed9d13 } /* Literal.String.Doc */
.pygmentize_G6wjIs .s2 { color: #ed9d13 } /* Literal.String.Double */
.pygmentize_G6wjIs .se { color: #ed9d13 } /* Literal.String.Escape */
.pygmentize_G6wjIs .sh { color: #ed9d13 } /* Literal.String.Heredoc */
.pygmentize_G6wjIs .si { color: #ed9d13 } /* Literal.String.Interpol */
.pygmentize_G6wjIs .sx { color: #ffa500 } /* Literal.String.Other */
.pygmentize_G6wjIs .sr { color: #ed9d13 } /* Literal.String.Regex */
.pygmentize_G6wjIs .s1 { color: #ed9d13 } /* Literal.String.Single */
.pygmentize_G6wjIs .ss { color: #ed9d13 } /* Literal.String.Symbol */
.pygmentize_G6wjIs .bp { color: #24909d } /* Name.Builtin.Pseudo */
.pygmentize_G6wjIs .vc { color: #40ffff } /* Name.Variable.Class */
.pygmentize_G6wjIs .vg { color: #40ffff } /* Name.Variable.Global */
.pygmentize_G6wjIs .vi { color: #40ffff } /* Name.Variable.Instance */
.pygmentize_G6wjIs .il { color: #3677a9 } /* Literal.Number.Integer.Long */

  </style>




<div class="pygmentize_G6wjIs"><pre><span class="k">server</span> <span class="p">{</span>
  <span class="kn">listen</span> <span class="mi">80</span><span class="p">;</span>
  <span class="kn">server_name</span> <span class="p">~</span><span class="sr">^(\w+).mydomain.com$;</span>

  <span class="s">set</span> <span class="nv">$subdomain</span> <span class="nv">$1</span><span class="p">;</span>

  <span class="kn">if</span> <span class="s">(-f</span> <span class="nv">$document_root/$uri-$subdomain.html</span><span class="s">)</span> <span class="p">{</span>
    <span class="kn">rewrite</span> <span class="s">(.*)</span> <span class="s">/</span><span class="nv">$1-$subdomain.html</span> <span class="s">break</span><span class="p">;</span>
  <span class="p">}</span>
<span class="p">}</span>
</pre></div>


</div>
</p>
<p>It will take alot of trial and error with getting NGINX to fully recognize your page cached files. Therefore, its better to install NGINX locally and change the HOSTS configuration a proper domain to point on your computer and perfect it that way. Keep in mind that NGINX does not allow <em>AND</em> and <em>OR</em> pre-conditions or <em>nested</em> if statements so you&#8217;ll need to use concatenation and variable checking to get something complex to work.</p>
]]></content:encoded>
			<wfw:commentRss>http://yearofmoo.com/2011/12/rails-page-caching-and-internationalization/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting started with MooTools Behavior.js</title>
		<link>http://yearofmoo.com/2011/12/getting-started-with-mootools-behavior-js/</link>
		<comments>http://yearofmoo.com/2011/12/getting-started-with-mootools-behavior-js/#comments</comments>
		<pubDate>Fri, 23 Dec 2011 17:53:15 +0000</pubDate>
		<dc:creator>matsko</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://yearofmoo.com/?p=849</guid>
		<description><![CDATA[A simple tutorial that explains the steps to get you started with Behavior.js MooTools offers an elegant solution to dealing with messy, unusable JavaScript code that is used to build simple, disposable UI effects and elements, that should normally be abstracted from your application code, with the use of a library called Behavior.js. The library [...]]]></description>
			<content:encoded><![CDATA[<h3>A simple tutorial that explains the steps to get you started with Behavior.js</h3>
<p>MooTools offers an elegant solution to dealing with messy, unusable JavaScript code that is used to build simple, disposable UI effects and elements, that should normally be abstracted from your application code, with the use of a library called <a href="https://github.com/anutron/behavior" class="em">Behavior.js</a>. The library contains two main tools: <em>Behaviour</em> which is used for mapping layout elements to classes (plugins) and <em>Delegator</em> which is used to relate the options identified in HTML elements to predefined, reusable filters (subroutines).</p>
<p>This article will go through the steps involved with getting this awesome plugin working with your application.</p>
<p><span id="more-849"></span></p>
<p><h3>Last Updated</h3>
<p>This page was last updated on <strong class="em">December 24rd 2011</strong> and was first published on <strong class="em">May 9th 2012</strong>
</p>
<p><h3>In a Nutshell</h3>
<p><em>Behavior</em> scans the page looking for any elements that contain the <em>data-behavior</em> attribute and then it will fire the assigned filter for any of the class(es) defined within the attribute value. This is what it looks like:</p>
<div class="syntax">
<style type="text/css">


/* *************************************************** */
/* WordPress default theme "twenty-ten" compatibility: */
/* FIXME: Is there a way to limit these changes to pygmentize_l7lyht  */
/*        without editing the WordPress theme directly? */
/* *************************************************** */

.syntax pre {
  /* The background: transparent is needed to work with WordPress:*/
  background: transparent;
  /* Default WordPress style has a big fat <pre> margin-bottom: */
  margin-bottom: 0px;

  /*color: #333333;*/
  font-size: .9em; 
  line-height: 1.25em;
}

.syntax table {
	border: 1px solid #e7e7e7;
    margin: 0 0 0 0;
	text-align: left;
	width: 100%;
}
.syntax tr th,
.syntax thead th {
	color: #888;
	font-size: 12px;
	font-weight: bold;
	line-height: 18px;
	padding: 0px;
}
.syntax tr td {
	border: 0px;
	padding: 0px;
	margin: 0px;
    margin-bottom: 0px;
    padding-bottom: 0px;

}

/* *************************************************** */
/* *************************************************** */

/* Standard fixes to the default output: */

/* Set the tab width in "ch" character units: */
.pygmentize_l7lyht .tabspan {
  display: inline-block;
  width: 4ch;
}

/* When using line numbers, use 100% table width and no cellpadding: */
.pygmentize_l7lyhttable {
  width: 100%;
  border-spacing: 0px;
  border-collapse: collapse;
}


/*
.syntax table {
    border: 1px solid #E7E7E7;
    margin: 0 -1px 24px 0;
    text-align: left;
    width: 100%;
}
*/

.pygmentize_l7lyhttable td, .pygmentize_l7lyhttable th {
  padding: 0px;
  margin: 0px;
}

/* Add a little buffer so the monotype font doesn't bump directly against the edge: */
.pygmentize_l7lyht pre {
  padding: .6ch;
  
}

/* This is more consistent with <p> tags... I didn't like it for my use: */
/*
div .pygmentize_l7lyht {
    margin-bottom: 24px; 
}
*/

td.linenos.pygmentize_l7lyht {
  width: 1ch;
  padding: .6ch;
  line-height: 1.25em;
}

.pygmentize_l7lyht td {
  padding-right: 1px;
}


td.linenos { background-color: #f0f0f0; padding-right: 1px; }
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
pre { line-height: 125%; }
.pygmentize_l7lyht .hll { background-color: #404040 }
.pygmentize_l7lyht  { background: #202020; color: #d0d0d0 }
.pygmentize_l7lyht .c { color: #999999; font-style: italic } /* Comment */
.pygmentize_l7lyht .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.pygmentize_l7lyht .g { color: #d0d0d0 } /* Generic */
.pygmentize_l7lyht .k { color: #6ab825; font-weight: bold } /* Keyword */
.pygmentize_l7lyht .l { color: #d0d0d0 } /* Literal */
.pygmentize_l7lyht .n { color: #d0d0d0 } /* Name */
.pygmentize_l7lyht .o { color: #d0d0d0 } /* Operator */
.pygmentize_l7lyht .x { color: #d0d0d0 } /* Other */
.pygmentize_l7lyht .p { color: #d0d0d0 } /* Punctuation */
.pygmentize_l7lyht .cm { color: #999999; font-style: italic } /* Comment.Multiline */
.pygmentize_l7lyht .cp { color: #cd2828; font-weight: bold } /* Comment.Preproc */
.pygmentize_l7lyht .c1 { color: #999999; font-style: italic } /* Comment.Single */
.pygmentize_l7lyht .cs { color: #e50808; font-weight: bold; background-color: #520000 } /* Comment.Special */
.pygmentize_l7lyht .gd { color: #d22323 } /* Generic.Deleted */
.pygmentize_l7lyht .ge { color: #d0d0d0; font-style: italic } /* Generic.Emph */
.pygmentize_l7lyht .gr { color: #d22323 } /* Generic.Error */
.pygmentize_l7lyht .gh { color: #ffffff; font-weight: bold } /* Generic.Heading */
.pygmentize_l7lyht .gi { color: #589819 } /* Generic.Inserted */
.pygmentize_l7lyht .go { color: #cccccc } /* Generic.Output */
.pygmentize_l7lyht .gp { color: #aaaaaa } /* Generic.Prompt */
.pygmentize_l7lyht .gs { color: #d0d0d0; font-weight: bold } /* Generic.Strong */
.pygmentize_l7lyht .gu { color: #ffffff; text-decoration: underline } /* Generic.Subheading */
.pygmentize_l7lyht .gt { color: #d22323 } /* Generic.Traceback */
.pygmentize_l7lyht .kc { color: #6ab825; font-weight: bold } /* Keyword.Constant */
.pygmentize_l7lyht .kd { color: #6ab825; font-weight: bold } /* Keyword.Declaration */
.pygmentize_l7lyht .kn { color: #6ab825; font-weight: bold } /* Keyword.Namespace */
.pygmentize_l7lyht .kp { color: #6ab825 } /* Keyword.Pseudo */
.pygmentize_l7lyht .kr { color: #6ab825; font-weight: bold } /* Keyword.Reserved */
.pygmentize_l7lyht .kt { color: #6ab825; font-weight: bold } /* Keyword.Type */
.pygmentize_l7lyht .ld { color: #d0d0d0 } /* Literal.Date */
.pygmentize_l7lyht .m { color: #3677a9 } /* Literal.Number */
.pygmentize_l7lyht .s { color: #ed9d13 } /* Literal.String */
.pygmentize_l7lyht .na { color: #bbbbbb } /* Name.Attribute */
.pygmentize_l7lyht .nb { color: #24909d } /* Name.Builtin */
.pygmentize_l7lyht .nc { color: #447fcf; text-decoration: underline } /* Name.Class */
.pygmentize_l7lyht .no { color: #40ffff } /* Name.Constant */
.pygmentize_l7lyht .nd { color: #ffa500 } /* Name.Decorator */
.pygmentize_l7lyht .ni { color: #d0d0d0 } /* Name.Entity */
.pygmentize_l7lyht .ne { color: #bbbbbb } /* Name.Exception */
.pygmentize_l7lyht .nf { color: #447fcf } /* Name.Function */
.pygmentize_l7lyht .nl { color: #d0d0d0 } /* Name.Label */
.pygmentize_l7lyht .nn { color: #447fcf; text-decoration: underline } /* Name.Namespace */
.pygmentize_l7lyht .nx { color: #d0d0d0 } /* Name.Other */
.pygmentize_l7lyht .py { color: #d0d0d0 } /* Name.Property */
.pygmentize_l7lyht .nt { color: #6ab825; font-weight: bold } /* Name.Tag */
.pygmentize_l7lyht .nv { color: #40ffff } /* Name.Variable */
.pygmentize_l7lyht .ow { color: #6ab825; font-weight: bold } /* Operator.Word */
.pygmentize_l7lyht .w { color: #666666 } /* Text.Whitespace */
.pygmentize_l7lyht .mf { color: #3677a9 } /* Literal.Number.Float */
.pygmentize_l7lyht .mh { color: #3677a9 } /* Literal.Number.Hex */
.pygmentize_l7lyht .mi { color: #3677a9 } /* Literal.Number.Integer */
.pygmentize_l7lyht .mo { color: #3677a9 } /* Literal.Number.Oct */
.pygmentize_l7lyht .sb { color: #ed9d13 } /* Literal.String.Backtick */
.pygmentize_l7lyht .sc { color: #ed9d13 } /* Literal.String.Char */
.pygmentize_l7lyht .sd { color: #ed9d13 } /* Literal.String.Doc */
.pygmentize_l7lyht .s2 { color: #ed9d13 } /* Literal.String.Double */
.pygmentize_l7lyht .se { color: #ed9d13 } /* Literal.String.Escape */
.pygmentize_l7lyht .sh { color: #ed9d13 } /* Literal.String.Heredoc */
.pygmentize_l7lyht .si { color: #ed9d13 } /* Literal.String.Interpol */
.pygmentize_l7lyht .sx { color: #ffa500 } /* Literal.String.Other */
.pygmentize_l7lyht .sr { color: #ed9d13 } /* Literal.String.Regex */
.pygmentize_l7lyht .s1 { color: #ed9d13 } /* Literal.String.Single */
.pygmentize_l7lyht .ss { color: #ed9d13 } /* Literal.String.Symbol */
.pygmentize_l7lyht .bp { color: #24909d } /* Name.Builtin.Pseudo */
.pygmentize_l7lyht .vc { color: #40ffff } /* Name.Variable.Class */
.pygmentize_l7lyht .vg { color: #40ffff } /* Name.Variable.Global */
.pygmentize_l7lyht .vi { color: #40ffff } /* Name.Variable.Instance */
.pygmentize_l7lyht .il { color: #3677a9 } /* Literal.Number.Integer.Long */

  </style>




<div class="pygmentize_l7lyht"><pre><span class="nt">&lt;a</span> <span class="na">href=</span><span class="s">&quot;#&quot;</span> <span class="na">data-behavior=</span><span class="s">&quot;Tips&quot;</span> <span class="na">data-tip-options=</span><span class="s">&quot;{ &#39;someProperty&#39; : &#39;someValue&#39; }&quot;</span><span class="nt">&gt;</span>
    Hover Here!
<span class="nt">&lt;/a&gt;</span>

<span class="nt">&lt;script </span><span class="na">type=</span><span class="s">&quot;text/javascript&quot;</span><span class="nt">&gt;</span>
<span class="nx">Behavior</span><span class="p">.</span><span class="nx">addGlobalFilter</span><span class="p">(</span><span class="s1">&#39;Tips&#39;</span><span class="p">,</span> <span class="p">{</span>
  <span class="nx">setup</span> <span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">element</span><span class="p">,</span> <span class="nx">api</span><span class="p">)</span> <span class="p">{</span>
    <span class="kd">var</span> <span class="nx">options</span> <span class="o">=</span> <span class="p">{</span>
       <span class="nx">someProperty</span> <span class="o">:</span> <span class="nx">api</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s1">&#39;someProperty&#39;</span><span class="p">);</span>
    <span class="p">};</span>
    <span class="k">new</span> <span class="nx">Tips</span><span class="p">(</span><span class="nx">element</span><span class="p">,</span><span class="nx">options</span><span class="p">);</span>
  <span class="p">}</span>
<span class="p">});</span>

<span class="nb">window</span><span class="p">.</span><span class="nx">addEvent</span><span class="p">(</span><span class="s1">&#39;domready&#39;</span><span class="p">,</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
    <span class="nx">Behavior</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="nb">document</span><span class="p">.</span><span class="nx">body</span><span class="p">);</span>
<span class="p">});</span>
<span class="nt">&lt;/script&gt;</span>
</pre></div>


</div>
<p>In this example, Behavior will scan the page (once the Behavior.attach() method is fired) and then look for any elements that match the selector (<em>data-behavior=&#8221;Tip&#8221;</em>) and then will append the options fetched from data-tip-options and built the <em>api</em> variable from that. It is up to you as to how you wish to instantiate the plugin (or perform a series of operations).
</p>
<p>
<em>Delegator</em> is pretty similar. It too looks for an attribute selector (<em>data-trigger=&#8221;..&#8221;</em>) and applies the associated options to the function call. The function call is registered with the Delegator:</p>
<div class="syntax">
<style type="text/css">


/* *************************************************** */
/* WordPress default theme "twenty-ten" compatibility: */
/* FIXME: Is there a way to limit these changes to pygmentize_s5Isau  */
/*        without editing the WordPress theme directly? */
/* *************************************************** */

.syntax pre {
  /* The background: transparent is needed to work with WordPress:*/
  background: transparent;
  /* Default WordPress style has a big fat <pre> margin-bottom: */
  margin-bottom: 0px;

  /*color: #333333;*/
  font-size: .9em; 
  line-height: 1.25em;
}

.syntax table {
	border: 1px solid #e7e7e7;
    margin: 0 0 0 0;
	text-align: left;
	width: 100%;
}
.syntax tr th,
.syntax thead th {
	color: #888;
	font-size: 12px;
	font-weight: bold;
	line-height: 18px;
	padding: 0px;
}
.syntax tr td {
	border: 0px;
	padding: 0px;
	margin: 0px;
    margin-bottom: 0px;
    padding-bottom: 0px;

}

/* *************************************************** */
/* *************************************************** */

/* Standard fixes to the default output: */

/* Set the tab width in "ch" character units: */
.pygmentize_s5Isau .tabspan {
  display: inline-block;
  width: 4ch;
}

/* When using line numbers, use 100% table width and no cellpadding: */
.pygmentize_s5Isautable {
  width: 100%;
  border-spacing: 0px;
  border-collapse: collapse;
}


/*
.syntax table {
    border: 1px solid #E7E7E7;
    margin: 0 -1px 24px 0;
    text-align: left;
    width: 100%;
}
*/

.pygmentize_s5Isautable td, .pygmentize_s5Isautable th {
  padding: 0px;
  margin: 0px;
}

/* Add a little buffer so the monotype font doesn't bump directly against the edge: */
.pygmentize_s5Isau pre {
  padding: .6ch;
  
}

/* This is more consistent with <p> tags... I didn't like it for my use: */
/*
div .pygmentize_s5Isau {
    margin-bottom: 24px; 
}
*/

td.linenos.pygmentize_s5Isau {
  width: 1ch;
  padding: .6ch;
  line-height: 1.25em;
}

.pygmentize_s5Isau td {
  padding-right: 1px;
}


td.linenos { background-color: #f0f0f0; padding-right: 1px; }
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
pre { line-height: 125%; }
.pygmentize_s5Isau .hll { background-color: #404040 }
.pygmentize_s5Isau  { background: #202020; color: #d0d0d0 }
.pygmentize_s5Isau .c { color: #999999; font-style: italic } /* Comment */
.pygmentize_s5Isau .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.pygmentize_s5Isau .g { color: #d0d0d0 } /* Generic */
.pygmentize_s5Isau .k { color: #6ab825; font-weight: bold } /* Keyword */
.pygmentize_s5Isau .l { color: #d0d0d0 } /* Literal */
.pygmentize_s5Isau .n { color: #d0d0d0 } /* Name */
.pygmentize_s5Isau .o { color: #d0d0d0 } /* Operator */
.pygmentize_s5Isau .x { color: #d0d0d0 } /* Other */
.pygmentize_s5Isau .p { color: #d0d0d0 } /* Punctuation */
.pygmentize_s5Isau .cm { color: #999999; font-style: italic } /* Comment.Multiline */
.pygmentize_s5Isau .cp { color: #cd2828; font-weight: bold } /* Comment.Preproc */
.pygmentize_s5Isau .c1 { color: #999999; font-style: italic } /* Comment.Single */
.pygmentize_s5Isau .cs { color: #e50808; font-weight: bold; background-color: #520000 } /* Comment.Special */
.pygmentize_s5Isau .gd { color: #d22323 } /* Generic.Deleted */
.pygmentize_s5Isau .ge { color: #d0d0d0; font-style: italic } /* Generic.Emph */
.pygmentize_s5Isau .gr { color: #d22323 } /* Generic.Error */
.pygmentize_s5Isau .gh { color: #ffffff; font-weight: bold } /* Generic.Heading */
.pygmentize_s5Isau .gi { color: #589819 } /* Generic.Inserted */
.pygmentize_s5Isau .go { color: #cccccc } /* Generic.Output */
.pygmentize_s5Isau .gp { color: #aaaaaa } /* Generic.Prompt */
.pygmentize_s5Isau .gs { color: #d0d0d0; font-weight: bold } /* Generic.Strong */
.pygmentize_s5Isau .gu { color: #ffffff; text-decoration: underline } /* Generic.Subheading */
.pygmentize_s5Isau .gt { color: #d22323 } /* Generic.Traceback */
.pygmentize_s5Isau .kc { color: #6ab825; font-weight: bold } /* Keyword.Constant */
.pygmentize_s5Isau .kd { color: #6ab825; font-weight: bold } /* Keyword.Declaration */
.pygmentize_s5Isau .kn { color: #6ab825; font-weight: bold } /* Keyword.Namespace */
.pygmentize_s5Isau .kp { color: #6ab825 } /* Keyword.Pseudo */
.pygmentize_s5Isau .kr { color: #6ab825; font-weight: bold } /* Keyword.Reserved */
.pygmentize_s5Isau .kt { color: #6ab825; font-weight: bold } /* Keyword.Type */
.pygmentize_s5Isau .ld { color: #d0d0d0 } /* Literal.Date */
.pygmentize_s5Isau .m { color: #3677a9 } /* Literal.Number */
.pygmentize_s5Isau .s { color: #ed9d13 } /* Literal.String */
.pygmentize_s5Isau .na { color: #bbbbbb } /* Name.Attribute */
.pygmentize_s5Isau .nb { color: #24909d } /* Name.Builtin */
.pygmentize_s5Isau .nc { color: #447fcf; text-decoration: underline } /* Name.Class */
.pygmentize_s5Isau .no { color: #40ffff } /* Name.Constant */
.pygmentize_s5Isau .nd { color: #ffa500 } /* Name.Decorator */
.pygmentize_s5Isau .ni { color: #d0d0d0 } /* Name.Entity */
.pygmentize_s5Isau .ne { color: #bbbbbb } /* Name.Exception */
.pygmentize_s5Isau .nf { color: #447fcf } /* Name.Function */
.pygmentize_s5Isau .nl { color: #d0d0d0 } /* Name.Label */
.pygmentize_s5Isau .nn { color: #447fcf; text-decoration: underline } /* Name.Namespace */
.pygmentize_s5Isau .nx { color: #d0d0d0 } /* Name.Other */
.pygmentize_s5Isau .py { color: #d0d0d0 } /* Name.Property */
.pygmentize_s5Isau .nt { color: #6ab825; font-weight: bold } /* Name.Tag */
.pygmentize_s5Isau .nv { color: #40ffff } /* Name.Variable */
.pygmentize_s5Isau .ow { color: #6ab825; font-weight: bold } /* Operator.Word */
.pygmentize_s5Isau .w { color: #666666 } /* Text.Whitespace */
.pygmentize_s5Isau .mf { color: #3677a9 } /* Literal.Number.Float */
.pygmentize_s5Isau .mh { color: #3677a9 } /* Literal.Number.Hex */
.pygmentize_s5Isau .mi { color: #3677a9 } /* Literal.Number.Integer */
.pygmentize_s5Isau .mo { color: #3677a9 } /* Literal.Number.Oct */
.pygmentize_s5Isau .sb { color: #ed9d13 } /* Literal.String.Backtick */
.pygmentize_s5Isau .sc { color: #ed9d13 } /* Literal.String.Char */
.pygmentize_s5Isau .sd { color: #ed9d13 } /* Literal.String.Doc */
.pygmentize_s5Isau .s2 { color: #ed9d13 } /* Literal.String.Double */
.pygmentize_s5Isau .se { color: #ed9d13 } /* Literal.String.Escape */
.pygmentize_s5Isau .sh { color: #ed9d13 } /* Literal.String.Heredoc */
.pygmentize_s5Isau .si { color: #ed9d13 } /* Literal.String.Interpol */
.pygmentize_s5Isau .sx { color: #ffa500 } /* Literal.String.Other */
.pygmentize_s5Isau .sr { color: #ed9d13 } /* Literal.String.Regex */
.pygmentize_s5Isau .s1 { color: #ed9d13 } /* Literal.String.Single */
.pygmentize_s5Isau .ss { color: #ed9d13 } /* Literal.String.Symbol */
.pygmentize_s5Isau .bp { color: #24909d } /* Name.Builtin.Pseudo */
.pygmentize_s5Isau .vc { color: #40ffff } /* Name.Variable.Class */
.pygmentize_s5Isau .vg { color: #40ffff } /* Name.Variable.Global */
.pygmentize_s5Isau .vi { color: #40ffff } /* Name.Variable.Instance */
.pygmentize_s5Isau .il { color: #3677a9 } /* Literal.Number.Integer.Long */

  </style>




<div class="pygmentize_s5Isau"><pre><span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">&quot;divver&quot;</span><span class="nt">&gt;</span>
    <span class="nt">&lt;a</span> <span class="na">href=</span><span class="s">&quot;#&quot;</span> <span class="na">data-trigger=</span><span class="s">&quot;HideParent&quot;</span> <span class="na">data-hideparent-options=</span><span class="s">&quot;{&#39;target&#39;:&#39;.divver&#39;}&quot;</span><span class="nt">&gt;</span>
        Hide
    <span class="nt">&lt;/a&gt;</span>
<span class="nt">&lt;/div&gt;</span>

<span class="nt">&lt;script </span><span class="na">type=</span><span class="s">&quot;text/javascript&quot;</span><span class="nt">&gt;</span>
<span class="nx">Delegator</span><span class="p">.</span><span class="nx">register</span><span class="p">(</span><span class="s1">&#39;click&#39;</span><span class="p">,</span> <span class="s1">&#39;HideParent&#39;</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">event</span><span class="p">,</span> <span class="nx">element</span><span class="p">,</span> <span class="nx">api</span><span class="p">){</span>
    <span class="nx">event</span><span class="p">.</span><span class="nx">preventDefault</span><span class="p">();</span>
    <span class="kd">var</span> <span class="nx">selector</span> <span class="o">=</span> <span class="nx">api</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s1">&#39;target&#39;</span><span class="p">)</span> <span class="o">||</span> <span class="kc">null</span><span class="p">;</span>
    <span class="nx">element</span><span class="p">.</span><span class="nx">getParent</span><span class="p">(</span><span class="nx">selector</span><span class="p">).</span><span class="nx">hide</span><span class="p">();</span>
<span class="p">});</span>

<span class="nb">window</span><span class="p">.</span><span class="nx">addEvent</span><span class="p">(</span><span class="s1">&#39;domready&#39;</span><span class="p">,</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
    <span class="nx">Delegator</span><span class="p">.</span><span class="nx">attach</span><span class="p">(</span><span class="nb">document</span><span class="p">.</span><span class="nx">body</span><span class="p">);</span>
<span class="p">});</span>
<span class="nt">&lt;/script&gt;</span>
</pre></div>


</div>
<p>The code is here pretty straightforward and it follows the flow of the <em>Behavior</em> example.
</p>
<p><h3>How to set this up</h3>
<p>First you&#8217;ll need to <a href="https://github.com/anutron/behavior" class="ignore-xview" target="_blank">clone the Git repository</a> or <a href="http://dev.clientcide.com/" class="ignore-xview" target="_blank">download the source</a>. Next extract all the files into a folder accessible within your web application. Include the following files (in the following order):</p>
<ol class="files">
<li class="em">./Source/Element.Data.js</li>
<li class="em">./Source/BehaviorAPI.js</li>
<li class="em">./Source/Behavior.js</li>
<li class="em">./Source/Behavior.Startup.js</li>
<li class="em">./Source/Delegator.js</li>
</ol>
<p>
Next, <em>define the filters that you want for your behavior operations</em> with the following code:</p>
<div class="syntax">
<style type="text/css">


/* *************************************************** */
/* WordPress default theme "twenty-ten" compatibility: */
/* FIXME: Is there a way to limit these changes to pygmentize_FG6Ymv  */
/*        without editing the WordPress theme directly? */
/* *************************************************** */

.syntax pre {
  /* The background: transparent is needed to work with WordPress:*/
  background: transparent;
  /* Default WordPress style has a big fat <pre> margin-bottom: */
  margin-bottom: 0px;

  /*color: #333333;*/
  font-size: .9em; 
  line-height: 1.25em;
}

.syntax table {
	border: 1px solid #e7e7e7;
    margin: 0 0 0 0;
	text-align: left;
	width: 100%;
}
.syntax tr th,
.syntax thead th {
	color: #888;
	font-size: 12px;
	font-weight: bold;
	line-height: 18px;
	padding: 0px;
}
.syntax tr td {
	border: 0px;
	padding: 0px;
	margin: 0px;
    margin-bottom: 0px;
    padding-bottom: 0px;

}

/* *************************************************** */
/* *************************************************** */

/* Standard fixes to the default output: */

/* Set the tab width in "ch" character units: */
.pygmentize_FG6Ymv .tabspan {
  display: inline-block;
  width: 4ch;
}

/* When using line numbers, use 100% table width and no cellpadding: */
.pygmentize_FG6Ymvtable {
  width: 100%;
  border-spacing: 0px;
  border-collapse: collapse;
}


/*
.syntax table {
    border: 1px solid #E7E7E7;
    margin: 0 -1px 24px 0;
    text-align: left;
    width: 100%;
}
*/

.pygmentize_FG6Ymvtable td, .pygmentize_FG6Ymvtable th {
  padding: 0px;
  margin: 0px;
}

/* Add a little buffer so the monotype font doesn't bump directly against the edge: */
.pygmentize_FG6Ymv pre {
  padding: .6ch;
  
}

/* This is more consistent with <p> tags... I didn't like it for my use: */
/*
div .pygmentize_FG6Ymv {
    margin-bottom: 24px; 
}
*/

td.linenos.pygmentize_FG6Ymv {
  width: 1ch;
  padding: .6ch;
  line-height: 1.25em;
}

.pygmentize_FG6Ymv td {
  padding-right: 1px;
}


td.linenos { background-color: #f0f0f0; padding-right: 1px; }
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
pre { line-height: 125%; }
.pygmentize_FG6Ymv .hll { background-color: #404040 }
.pygmentize_FG6Ymv  { background: #202020; color: #d0d0d0 }
.pygmentize_FG6Ymv .c { color: #999999; font-style: italic } /* Comment */
.pygmentize_FG6Ymv .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.pygmentize_FG6Ymv .g { color: #d0d0d0 } /* Generic */
.pygmentize_FG6Ymv .k { color: #6ab825; font-weight: bold } /* Keyword */
.pygmentize_FG6Ymv .l { color: #d0d0d0 } /* Literal */
.pygmentize_FG6Ymv .n { color: #d0d0d0 } /* Name */
.pygmentize_FG6Ymv .o { color: #d0d0d0 } /* Operator */
.pygmentize_FG6Ymv .x { color: #d0d0d0 } /* Other */
.pygmentize_FG6Ymv .p { color: #d0d0d0 } /* Punctuation */
.pygmentize_FG6Ymv .cm { color: #999999; font-style: italic } /* Comment.Multiline */
.pygmentize_FG6Ymv .cp { color: #cd2828; font-weight: bold } /* Comment.Preproc */
.pygmentize_FG6Ymv .c1 { color: #999999; font-style: italic } /* Comment.Single */
.pygmentize_FG6Ymv .cs { color: #e50808; font-weight: bold; background-color: #520000 } /* Comment.Special */
.pygmentize_FG6Ymv .gd { color: #d22323 } /* Generic.Deleted */
.pygmentize_FG6Ymv .ge { color: #d0d0d0; font-style: italic } /* Generic.Emph */
.pygmentize_FG6Ymv .gr { color: #d22323 } /* Generic.Error */
.pygmentize_FG6Ymv .gh { color: #ffffff; font-weight: bold } /* Generic.Heading */
.pygmentize_FG6Ymv .gi { color: #589819 } /* Generic.Inserted */
.pygmentize_FG6Ymv .go { color: #cccccc } /* Generic.Output */
.pygmentize_FG6Ymv .gp { color: #aaaaaa } /* Generic.Prompt */
.pygmentize_FG6Ymv .gs { color: #d0d0d0; font-weight: bold } /* Generic.Strong */
.pygmentize_FG6Ymv .gu { color: #ffffff; text-decoration: underline } /* Generic.Subheading */
.pygmentize_FG6Ymv .gt { color: #d22323 } /* Generic.Traceback */
.pygmentize_FG6Ymv .kc { color: #6ab825; font-weight: bold } /* Keyword.Constant */
.pygmentize_FG6Ymv .kd { color: #6ab825; font-weight: bold } /* Keyword.Declaration */
.pygmentize_FG6Ymv .kn { color: #6ab825; font-weight: bold } /* Keyword.Namespace */
.pygmentize_FG6Ymv .kp { color: #6ab825 } /* Keyword.Pseudo */
.pygmentize_FG6Ymv .kr { color: #6ab825; font-weight: bold } /* Keyword.Reserved */
.pygmentize_FG6Ymv .kt { color: #6ab825; font-weight: bold } /* Keyword.Type */
.pygmentize_FG6Ymv .ld { color: #d0d0d0 } /* Literal.Date */
.pygmentize_FG6Ymv .m { color: #3677a9 } /* Literal.Number */
.pygmentize_FG6Ymv .s { color: #ed9d13 } /* Literal.String */
.pygmentize_FG6Ymv .na { color: #bbbbbb } /* Name.Attribute */
.pygmentize_FG6Ymv .nb { color: #24909d } /* Name.Builtin */
.pygmentize_FG6Ymv .nc { color: #447fcf; text-decoration: underline } /* Name.Class */
.pygmentize_FG6Ymv .no { color: #40ffff } /* Name.Constant */
.pygmentize_FG6Ymv .nd { color: #ffa500 } /* Name.Decorator */
.pygmentize_FG6Ymv .ni { color: #d0d0d0 } /* Name.Entity */
.pygmentize_FG6Ymv .ne { color: #bbbbbb } /* Name.Exception */
.pygmentize_FG6Ymv .nf { color: #447fcf } /* Name.Function */
.pygmentize_FG6Ymv .nl { color: #d0d0d0 } /* Name.Label */
.pygmentize_FG6Ymv .nn { color: #447fcf; text-decoration: underline } /* Name.Namespace */
.pygmentize_FG6Ymv .nx { color: #d0d0d0 } /* Name.Other */
.pygmentize_FG6Ymv .py { color: #d0d0d0 } /* Name.Property */
.pygmentize_FG6Ymv .nt { color: #6ab825; font-weight: bold } /* Name.Tag */
.pygmentize_FG6Ymv .nv { color: #40ffff } /* Name.Variable */
.pygmentize_FG6Ymv .ow { color: #6ab825; font-weight: bold } /* Operator.Word */
.pygmentize_FG6Ymv .w { color: #666666 } /* Text.Whitespace */
.pygmentize_FG6Ymv .mf { color: #3677a9 } /* Literal.Number.Float */
.pygmentize_FG6Ymv .mh { color: #3677a9 } /* Literal.Number.Hex */
.pygmentize_FG6Ymv .mi { color: #3677a9 } /* Literal.Number.Integer */
.pygmentize_FG6Ymv .mo { color: #3677a9 } /* Literal.Number.Oct */
.pygmentize_FG6Ymv .sb { color: #ed9d13 } /* Literal.String.Backtick */
.pygmentize_FG6Ymv .sc { color: #ed9d13 } /* Literal.String.Char */
.pygmentize_FG6Ymv .sd { color: #ed9d13 } /* Literal.String.Doc */
.pygmentize_FG6Ymv .s2 { color: #ed9d13 } /* Literal.String.Double */
.pygmentize_FG6Ymv .se { color: #ed9d13 } /* Literal.String.Escape */
.pygmentize_FG6Ymv .sh { color: #ed9d13 } /* Literal.String.Heredoc */
.pygmentize_FG6Ymv .si { color: #ed9d13 } /* Literal.String.Interpol */
.pygmentize_FG6Ymv .sx { color: #ffa500 } /* Literal.String.Other */
.pygmentize_FG6Ymv .sr { color: #ed9d13 } /* Literal.String.Regex */
.pygmentize_FG6Ymv .s1 { color: #ed9d13 } /* Literal.String.Single */
.pygmentize_FG6Ymv .ss { color: #ed9d13 } /* Literal.String.Symbol */
.pygmentize_FG6Ymv .bp { color: #24909d } /* Name.Builtin.Pseudo */
.pygmentize_FG6Ymv .vc { color: #40ffff } /* Name.Variable.Class */
.pygmentize_FG6Ymv .vg { color: #40ffff } /* Name.Variable.Global */
.pygmentize_FG6Ymv .vi { color: #40ffff } /* Name.Variable.Instance */
.pygmentize_FG6Ymv .il { color: #3677a9 } /* Literal.Number.Integer.Long */

  </style>




<div class="pygmentize_FG6Ymv"><pre><span class="nx">Behavior</span><span class="p">.</span><span class="nx">addGlobalFilter</span><span class="p">(</span><span class="s1">&#39;Tips&#39;</span><span class="p">,</span> <span class="p">{</span>

  <span class="nx">defaults</span> <span class="o">:</span> <span class="p">{</span>
     <span class="c1">//the default hash of items that will be appended to the api hash</span>
  <span class="p">},</span>

  <span class="nx">setup</span> <span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">element</span><span class="p">,</span> <span class="nx">api</span><span class="p">)</span> <span class="p">{</span>
     <span class="c1">//this is what happens when it is scanned</span>
  <span class="p">}</span>

<span class="p">});</span>
</pre></div>


</div>
</p>
<p>Then <em>register the Delegator events</em> for the items that you wish to apply delegation operations on:</p>
<div class="syntax">
<style type="text/css">


/* *************************************************** */
/* WordPress default theme "twenty-ten" compatibility: */
/* FIXME: Is there a way to limit these changes to pygmentize_MTlbTw  */
/*        without editing the WordPress theme directly? */
/* *************************************************** */

.syntax pre {
  /* The background: transparent is needed to work with WordPress:*/
  background: transparent;
  /* Default WordPress style has a big fat <pre> margin-bottom: */
  margin-bottom: 0px;

  /*color: #333333;*/
  font-size: .9em; 
  line-height: 1.25em;
}

.syntax table {
	border: 1px solid #e7e7e7;
    margin: 0 0 0 0;
	text-align: left;
	width: 100%;
}
.syntax tr th,
.syntax thead th {
	color: #888;
	font-size: 12px;
	font-weight: bold;
	line-height: 18px;
	padding: 0px;
}
.syntax tr td {
	border: 0px;
	padding: 0px;
	margin: 0px;
    margin-bottom: 0px;
    padding-bottom: 0px;

}

/* *************************************************** */
/* *************************************************** */

/* Standard fixes to the default output: */

/* Set the tab width in "ch" character units: */
.pygmentize_MTlbTw .tabspan {
  display: inline-block;
  width: 4ch;
}

/* When using line numbers, use 100% table width and no cellpadding: */
.pygmentize_MTlbTwtable {
  width: 100%;
  border-spacing: 0px;
  border-collapse: collapse;
}


/*
.syntax table {
    border: 1px solid #E7E7E7;
    margin: 0 -1px 24px 0;
    text-align: left;
    width: 100%;
}
*/

.pygmentize_MTlbTwtable td, .pygmentize_MTlbTwtable th {
  padding: 0px;
  margin: 0px;
}

/* Add a little buffer so the monotype font doesn't bump directly against the edge: */
.pygmentize_MTlbTw pre {
  padding: .6ch;
  
}

/* This is more consistent with <p> tags... I didn't like it for my use: */
/*
div .pygmentize_MTlbTw {
    margin-bottom: 24px; 
}
*/

td.linenos.pygmentize_MTlbTw {
  width: 1ch;
  padding: .6ch;
  line-height: 1.25em;
}

.pygmentize_MTlbTw td {
  padding-right: 1px;
}


td.linenos { background-color: #f0f0f0; padding-right: 1px; }
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
pre { line-height: 125%; }
.pygmentize_MTlbTw .hll { background-color: #404040 }
.pygmentize_MTlbTw  { background: #202020; color: #d0d0d0 }
.pygmentize_MTlbTw .c { color: #999999; font-style: italic } /* Comment */
.pygmentize_MTlbTw .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.pygmentize_MTlbTw .g { color: #d0d0d0 } /* Generic */
.pygmentize_MTlbTw .k { color: #6ab825; font-weight: bold } /* Keyword */
.pygmentize_MTlbTw .l { color: #d0d0d0 } /* Literal */
.pygmentize_MTlbTw .n { color: #d0d0d0 } /* Name */
.pygmentize_MTlbTw .o { color: #d0d0d0 } /* Operator */
.pygmentize_MTlbTw .x { color: #d0d0d0 } /* Other */
.pygmentize_MTlbTw .p { color: #d0d0d0 } /* Punctuation */
.pygmentize_MTlbTw .cm { color: #999999; font-style: italic } /* Comment.Multiline */
.pygmentize_MTlbTw .cp { color: #cd2828; font-weight: bold } /* Comment.Preproc */
.pygmentize_MTlbTw .c1 { color: #999999; font-style: italic } /* Comment.Single */
.pygmentize_MTlbTw .cs { color: #e50808; font-weight: bold; background-color: #520000 } /* Comment.Special */
.pygmentize_MTlbTw .gd { color: #d22323 } /* Generic.Deleted */
.pygmentize_MTlbTw .ge { color: #d0d0d0; font-style: italic } /* Generic.Emph */
.pygmentize_MTlbTw .gr { color: #d22323 } /* Generic.Error */
.pygmentize_MTlbTw .gh { color: #ffffff; font-weight: bold } /* Generic.Heading */
.pygmentize_MTlbTw .gi { color: #589819 } /* Generic.Inserted */
.pygmentize_MTlbTw .go { color: #cccccc } /* Generic.Output */
.pygmentize_MTlbTw .gp { color: #aaaaaa } /* Generic.Prompt */
.pygmentize_MTlbTw .gs { color: #d0d0d0; font-weight: bold } /* Generic.Strong */
.pygmentize_MTlbTw .gu { color: #ffffff; text-decoration: underline } /* Generic.Subheading */
.pygmentize_MTlbTw .gt { color: #d22323 } /* Generic.Traceback */
.pygmentize_MTlbTw .kc { color: #6ab825; font-weight: bold } /* Keyword.Constant */
.pygmentize_MTlbTw .kd { color: #6ab825; font-weight: bold } /* Keyword.Declaration */
.pygmentize_MTlbTw .kn { color: #6ab825; font-weight: bold } /* Keyword.Namespace */
.pygmentize_MTlbTw .kp { color: #6ab825 } /* Keyword.Pseudo */
.pygmentize_MTlbTw .kr { color: #6ab825; font-weight: bold } /* Keyword.Reserved */
.pygmentize_MTlbTw .kt { color: #6ab825; font-weight: bold } /* Keyword.Type */
.pygmentize_MTlbTw .ld { color: #d0d0d0 } /* Literal.Date */
.pygmentize_MTlbTw .m { color: #3677a9 } /* Literal.Number */
.pygmentize_MTlbTw .s { color: #ed9d13 } /* Literal.String */
.pygmentize_MTlbTw .na { color: #bbbbbb } /* Name.Attribute */
.pygmentize_MTlbTw .nb { color: #24909d } /* Name.Builtin */
.pygmentize_MTlbTw .nc { color: #447fcf; text-decoration: underline } /* Name.Class */
.pygmentize_MTlbTw .no { color: #40ffff } /* Name.Constant */
.pygmentize_MTlbTw .nd { color: #ffa500 } /* Name.Decorator */
.pygmentize_MTlbTw .ni { color: #d0d0d0 } /* Name.Entity */
.pygmentize_MTlbTw .ne { color: #bbbbbb } /* Name.Exception */
.pygmentize_MTlbTw .nf { color: #447fcf } /* Name.Function */
.pygmentize_MTlbTw .nl { color: #d0d0d0 } /* Name.Label */
.pygmentize_MTlbTw .nn { color: #447fcf; text-decoration: underline } /* Name.Namespace */
.pygmentize_MTlbTw .nx { color: #d0d0d0 } /* Name.Other */
.pygmentize_MTlbTw .py { color: #d0d0d0 } /* Name.Property */
.pygmentize_MTlbTw .nt { color: #6ab825; font-weight: bold } /* Name.Tag */
.pygmentize_MTlbTw .nv { color: #40ffff } /* Name.Variable */
.pygmentize_MTlbTw .ow { color: #6ab825; font-weight: bold } /* Operator.Word */
.pygmentize_MTlbTw .w { color: #666666 } /* Text.Whitespace */
.pygmentize_MTlbTw .mf { color: #3677a9 } /* Literal.Number.Float */
.pygmentize_MTlbTw .mh { color: #3677a9 } /* Literal.Number.Hex */
.pygmentize_MTlbTw .mi { color: #3677a9 } /* Literal.Number.Integer */
.pygmentize_MTlbTw .mo { color: #3677a9 } /* Literal.Number.Oct */
.pygmentize_MTlbTw .sb { color: #ed9d13 } /* Literal.String.Backtick */
.pygmentize_MTlbTw .sc { color: #ed9d13 } /* Literal.String.Char */
.pygmentize_MTlbTw .sd { color: #ed9d13 } /* Literal.String.Doc */
.pygmentize_MTlbTw .s2 { color: #ed9d13 } /* Literal.String.Double */
.pygmentize_MTlbTw .se { color: #ed9d13 } /* Literal.String.Escape */
.pygmentize_MTlbTw .sh { color: #ed9d13 } /* Literal.String.Heredoc */
.pygmentize_MTlbTw .si { color: #ed9d13 } /* Literal.String.Interpol */
.pygmentize_MTlbTw .sx { color: #ffa500 } /* Literal.String.Other */
.pygmentize_MTlbTw .sr { color: #ed9d13 } /* Literal.String.Regex */
.pygmentize_MTlbTw .s1 { color: #ed9d13 } /* Literal.String.Single */
.pygmentize_MTlbTw .ss { color: #ed9d13 } /* Literal.String.Symbol */
.pygmentize_MTlbTw .bp { color: #24909d } /* Name.Builtin.Pseudo */
.pygmentize_MTlbTw .vc { color: #40ffff } /* Name.Variable.Class */
.pygmentize_MTlbTw .vg { color: #40ffff } /* Name.Variable.Global */
.pygmentize_MTlbTw .vi { color: #40ffff } /* Name.Variable.Instance */
.pygmentize_MTlbTw .il { color: #3677a9 } /* Literal.Number.Integer.Long */

  </style>




<div class="pygmentize_MTlbTw"><pre><span class="c1">//setup the event</span>
<span class="kd">var</span> <span class="nx">evType</span> <span class="o">=</span> <span class="s1">&#39;click&#39;</span><span class="p">;</span> <span class="c1">//this can be any event for a DOM element</span>
<span class="kd">var</span> <span class="nx">trigger</span> <span class="o">=</span> <span class="s1">&#39;TriggerName&#39;</span><span class="p">;</span> <span class="c1">//this is the trigger defined in the data-trigger attribute</span>

<span class="nx">Delegator</span><span class="p">.</span><span class="nx">register</span><span class="p">(</span><span class="nx">evType</span><span class="p">,</span> <span class="nx">trigger</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">event</span><span class="p">,</span> <span class="nx">element</span><span class="p">,</span> <span class="nx">api</span><span class="p">){</span>

    <span class="c1">//this function is run when the event is fired</span>
    <span class="c1">//the api variable is the options hash of data-{trigger}-options attribute options</span>

<span class="p">});</span>
</pre></div>


</div>
</p>
<p>
Once all the filters and delegation callbacks have been created, now any HTML element that contains the <em>data-behavior</em> or <em>data-trigger</em> attributes that match a <em>behavior filter</em> or <em>delegation registration function</em> will be ready. They won&#8217;t fire automatically, so you&#8217;ll need to define a run method:</p>
<div class="syntax">
<style type="text/css">


/* *************************************************** */
/* WordPress default theme "twenty-ten" compatibility: */
/* FIXME: Is there a way to limit these changes to pygmentize_fZ5bIy  */
/*        without editing the WordPress theme directly? */
/* *************************************************** */

.syntax pre {
  /* The background: transparent is needed to work with WordPress:*/
  background: transparent;
  /* Default WordPress style has a big fat <pre> margin-bottom: */
  margin-bottom: 0px;

  /*color: #333333;*/
  font-size: .9em; 
  line-height: 1.25em;
}

.syntax table {
	border: 1px solid #e7e7e7;
    margin: 0 0 0 0;
	text-align: left;
	width: 100%;
}
.syntax tr th,
.syntax thead th {
	color: #888;
	font-size: 12px;
	font-weight: bold;
	line-height: 18px;
	padding: 0px;
}
.syntax tr td {
	border: 0px;
	padding: 0px;
	margin: 0px;
    margin-bottom: 0px;
    padding-bottom: 0px;

}

/* *************************************************** */
/* *************************************************** */

/* Standard fixes to the default output: */

/* Set the tab width in "ch" character units: */
.pygmentize_fZ5bIy .tabspan {
  display: inline-block;
  width: 4ch;
}

/* When using line numbers, use 100% table width and no cellpadding: */
.pygmentize_fZ5bIytable {
  width: 100%;
  border-spacing: 0px;
  border-collapse: collapse;
}


/*
.syntax table {
    border: 1px solid #E7E7E7;
    margin: 0 -1px 24px 0;
    text-align: left;
    width: 100%;
}
*/

.pygmentize_fZ5bIytable td, .pygmentize_fZ5bIytable th {
  padding: 0px;
  margin: 0px;
}

/* Add a little buffer so the monotype font doesn't bump directly against the edge: */
.pygmentize_fZ5bIy pre {
  padding: .6ch;
  
}

/* This is more consistent with <p> tags... I didn't like it for my use: */
/*
div .pygmentize_fZ5bIy {
    margin-bottom: 24px; 
}
*/

td.linenos.pygmentize_fZ5bIy {
  width: 1ch;
  padding: .6ch;
  line-height: 1.25em;
}

.pygmentize_fZ5bIy td {
  padding-right: 1px;
}


td.linenos { background-color: #f0f0f0; padding-right: 1px; }
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
pre { line-height: 125%; }
.pygmentize_fZ5bIy .hll { background-color: #404040 }
.pygmentize_fZ5bIy  { background: #202020; color: #d0d0d0 }
.pygmentize_fZ5bIy .c { color: #999999; font-style: italic } /* Comment */
.pygmentize_fZ5bIy .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.pygmentize_fZ5bIy .g { color: #d0d0d0 } /* Generic */
.pygmentize_fZ5bIy .k { color: #6ab825; font-weight: bold } /* Keyword */
.pygmentize_fZ5bIy .l { color: #d0d0d0 } /* Literal */
.pygmentize_fZ5bIy .n { color: #d0d0d0 } /* Name */
.pygmentize_fZ5bIy .o { color: #d0d0d0 } /* Operator */
.pygmentize_fZ5bIy .x { color: #d0d0d0 } /* Other */
.pygmentize_fZ5bIy .p { color: #d0d0d0 } /* Punctuation */
.pygmentize_fZ5bIy .cm { color: #999999; font-style: italic } /* Comment.Multiline */
.pygmentize_fZ5bIy .cp { color: #cd2828; font-weight: bold } /* Comment.Preproc */
.pygmentize_fZ5bIy .c1 { color: #999999; font-style: italic } /* Comment.Single */
.pygmentize_fZ5bIy .cs { color: #e50808; font-weight: bold; background-color: #520000 } /* Comment.Special */
.pygmentize_fZ5bIy .gd { color: #d22323 } /* Generic.Deleted */
.pygmentize_fZ5bIy .ge { color: #d0d0d0; font-style: italic } /* Generic.Emph */
.pygmentize_fZ5bIy .gr { color: #d22323 } /* Generic.Error */
.pygmentize_fZ5bIy .gh { color: #ffffff; font-weight: bold } /* Generic.Heading */
.pygmentize_fZ5bIy .gi { color: #589819 } /* Generic.Inserted */
.pygmentize_fZ5bIy .go { color: #cccccc } /* Generic.Output */
.pygmentize_fZ5bIy .gp { color: #aaaaaa } /* Generic.Prompt */
.pygmentize_fZ5bIy .gs { color: #d0d0d0; font-weight: bold } /* Generic.Strong */
.pygmentize_fZ5bIy .gu { color: #ffffff; text-decoration: underline } /* Generic.Subheading */
.pygmentize_fZ5bIy .gt { color: #d22323 } /* Generic.Traceback */
.pygmentize_fZ5bIy .kc { color: #6ab825; font-weight: bold } /* Keyword.Constant */
.pygmentize_fZ5bIy .kd { color: #6ab825; font-weight: bold } /* Keyword.Declaration */
.pygmentize_fZ5bIy .kn { color: #6ab825; font-weight: bold } /* Keyword.Namespace */
.pygmentize_fZ5bIy .kp { color: #6ab825 } /* Keyword.Pseudo */
.pygmentize_fZ5bIy .kr { color: #6ab825; font-weight: bold } /* Keyword.Reserved */
.pygmentize_fZ5bIy .kt { color: #6ab825; font-weight: bold } /* Keyword.Type */
.pygmentize_fZ5bIy .ld { color: #d0d0d0 } /* Literal.Date */
.pygmentize_fZ5bIy .m { color: #3677a9 } /* Literal.Number */
.pygmentize_fZ5bIy .s { color: #ed9d13 } /* Literal.String */
.pygmentize_fZ5bIy .na { color: #bbbbbb } /* Name.Attribute */
.pygmentize_fZ5bIy .nb { color: #24909d } /* Name.Builtin */
.pygmentize_fZ5bIy .nc { color: #447fcf; text-decoration: underline } /* Name.Class */
.pygmentize_fZ5bIy .no { color: #40ffff } /* Name.Constant */
.pygmentize_fZ5bIy .nd { color: #ffa500 } /* Name.Decorator */
.pygmentize_fZ5bIy .ni { color: #d0d0d0 } /* Name.Entity */
.pygmentize_fZ5bIy .ne { color: #bbbbbb } /* Name.Exception */
.pygmentize_fZ5bIy .nf { color: #447fcf } /* Name.Function */
.pygmentize_fZ5bIy .nl { color: #d0d0d0 } /* Name.Label */
.pygmentize_fZ5bIy .nn { color: #447fcf; text-decoration: underline } /* Name.Namespace */
.pygmentize_fZ5bIy .nx { color: #d0d0d0 } /* Name.Other */
.pygmentize_fZ5bIy .py { color: #d0d0d0 } /* Name.Property */
.pygmentize_fZ5bIy .nt { color: #6ab825; font-weight: bold } /* Name.Tag */
.pygmentize_fZ5bIy .nv { color: #40ffff } /* Name.Variable */
.pygmentize_fZ5bIy .ow { color: #6ab825; font-weight: bold } /* Operator.Word */
.pygmentize_fZ5bIy .w { color: #666666 } /* Text.Whitespace */
.pygmentize_fZ5bIy .mf { color: #3677a9 } /* Literal.Number.Float */
.pygmentize_fZ5bIy .mh { color: #3677a9 } /* Literal.Number.Hex */
.pygmentize_fZ5bIy .mi { color: #3677a9 } /* Literal.Number.Integer */
.pygmentize_fZ5bIy .mo { color: #3677a9 } /* Literal.Number.Oct */
.pygmentize_fZ5bIy .sb { color: #ed9d13 } /* Literal.String.Backtick */
.pygmentize_fZ5bIy .sc { color: #ed9d13 } /* Literal.String.Char */
.pygmentize_fZ5bIy .sd { color: #ed9d13 } /* Literal.String.Doc */
.pygmentize_fZ5bIy .s2 { color: #ed9d13 } /* Literal.String.Double */
.pygmentize_fZ5bIy .se { color: #ed9d13 } /* Literal.String.Escape */
.pygmentize_fZ5bIy .sh { color: #ed9d13 } /* Literal.String.Heredoc */
.pygmentize_fZ5bIy .si { color: #ed9d13 } /* Literal.String.Interpol */
.pygmentize_fZ5bIy .sx { color: #ffa500 } /* Literal.String.Other */
.pygmentize_fZ5bIy .sr { color: #ed9d13 } /* Literal.String.Regex */
.pygmentize_fZ5bIy .s1 { color: #ed9d13 } /* Literal.String.Single */
.pygmentize_fZ5bIy .ss { color: #ed9d13 } /* Literal.String.Symbol */
.pygmentize_fZ5bIy .bp { color: #24909d } /* Name.Builtin.Pseudo */
.pygmentize_fZ5bIy .vc { color: #40ffff } /* Name.Variable.Class */
.pygmentize_fZ5bIy .vg { color: #40ffff } /* Name.Variable.Global */
.pygmentize_fZ5bIy .vi { color: #40ffff } /* Name.Variable.Instance */
.pygmentize_fZ5bIy .il { color: #3677a9 } /* Literal.Number.Integer.Long */

  </style>




<div class="pygmentize_fZ5bIy"><pre><span class="nb">window</span><span class="p">.</span><span class="nx">addEvent</span><span class="p">(</span><span class="s1">&#39;domready&#39;</span><span class="p">,</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
  <span class="k">new</span> <span class="nx">Behavior</span><span class="p">().</span><span class="nx">apply</span><span class="p">(</span><span class="nb">document</span><span class="p">.</span><span class="nx">body</span><span class="p">);</span>
  <span class="k">new</span> <span class="nx">Delegator</span><span class="p">().</span><span class="nx">attach</span><span class="p">(</span><span class="nb">document</span><span class="p">.</span><span class="nx">body</span><span class="p">);</span>
<span class="p">});</span>
</pre></div>


</div>
</p>
<p><h3>Anything else?</h3>
<p>Not so much. This toolkit is really sweet. Once you start using it you&#8217;ll see how the majority of your <em>page or element class-specific</em> code will trim itself down. The UI interactivity can be fully abstracted from the application core. I will blog more and more about this later on once I start to use the library within my own projects.</p>
]]></content:encoded>
			<wfw:commentRss>http://yearofmoo.com/2011/12/getting-started-with-mootools-behavior-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use Gistex to load up Github Gist Snippets</title>
		<link>http://yearofmoo.com/2011/12/use-gistex-to-load-up-github-gist-snippets/</link>
		<comments>http://yearofmoo.com/2011/12/use-gistex-to-load-up-github-gist-snippets/#comments</comments>
		<pubDate>Sun, 18 Dec 2011 20:49:57 +0000</pubDate>
		<dc:creator>matsko</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://yearofmoo.com/?p=833</guid>
		<description><![CDATA[Gistex is an easy to use tool to spawn up Github Gist snippets using AJAX The other day I decided on embedding Github Gist code snippets into yearofmoo instead of regular home-grown code blockquote areas. Gist is awesome, but the standard Javascript embeds do not work with a pure ajax website (like this one). So [...]]]></description>
			<content:encoded><![CDATA[<h3>Gistex is an easy to use tool to spawn up Github Gist snippets using AJAX</h3>
<p>The other day I decided on embedding <a href="https://gist.github.com" class="ignore-xview" target="_blank">Github Gist code snippets</a> into yearofmoo instead of regular home-grown code blockquote areas. Gist is awesome, but the standard Javascript embeds do not work with a pure ajax website (like this one). So the only way to get them to work was todo some voodoo JavaScript and then &#8230; voila &#8230; <a href="/Gistex" class="em">Gistex</a> was born.<br />
<span id="more-833"></span></p>
<p><h3>Last Updated</h3>
<p>This page was last updated on <strong class="em">December 18th 2011</strong> and was first published on <strong class="em">December 18th 2011</strong>
</p>
<p><h3>Gistex?</h3>
<p>Yes Gistex. It loads a Github Gist snippet, creates the HTML and pastes it into the DOM element that you wish to apply it to. This is great for AJAX applications and lazy loading. It is also supported in all browers and is <em>NOT</em> dependent on any JavaScript framework. The Gistex class is very simple, and provides support for numerous callbacks and options.
</p>
<p><h3>Where can I get it?</h3>
<p>Gistex is hosted here on yearofmoo.</p>
<p><a href="/Gistex">Click here to view the documentation and demos</a>.</p>
<p>
]]></content:encoded>
			<wfw:commentRss>http://yearofmoo.com/2011/12/use-gistex-to-load-up-github-gist-snippets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Current state of onhashchange &amp; HTML5 history</title>
		<link>http://yearofmoo.com/2011/10/current-state-of-onhashchange-and-html5-history/</link>
		<comments>http://yearofmoo.com/2011/10/current-state-of-onhashchange-and-html5-history/#comments</comments>
		<pubDate>Mon, 24 Oct 2011 14:46:13 +0000</pubDate>
		<dc:creator>matsko</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://yearofmoo.com/?p=742</guid>
		<description><![CDATA[How widely supported are these URL changing techniques in modern browsers? The onhashchange event is a popular event and has been widely looked into by yearofmoo. The MooTools-onhashchange plugin offered by yearofmoo takes care of this task effectively. The onhashchange event can be used in combination with a hash-prefixed URL token, known as a hashbang, [...]]]></description>
			<content:encoded><![CDATA[<h3>How widely supported are these URL changing techniques in modern browsers?</h3>
<p>The onhashchange event is a popular event and has been widely looked into by yearofmoo. The <a href="/onhashchange/" class="em">MooTools-onhashchange</a> plugin offered by yearofmoo takes care of this task effectively. The onhashchange event can be used in combination with a hash-prefixed URL token, known as a hashbang, to effectively inform search engines of indexed ajax content.</p>
<p>The HTML5 history API is only offered by modern browsers and offers more features than the onhashchange event. The only issue is that not all browsers fully support it yet since it is a new HTML5 JavaScript API. In addition, unlike with the onhashchange event, <em>there is no way to emulate or hack non-supporting browsers to offer popstate support</em>.</p>
<p>But how widely supported are the two features?</p>
<p><span id="more-742"></span></p>
<p><h3>Last Updated</h3>
<p>This page was last updated on <em>Oct 24th 2011</em> and was first published on <em>Oct 24th 2011</em>
</p>
<p><h3>The onhashchange event vs the History API</h3>
<p>HTML5 history is by far more extensive, user-friendly and profound than the onhashchange event (in regards to dynamic URL changing). The page fragment (or hash tag) of a URL was designed for in page anchoring and not for page to page addressing (which is what the history API does). So how do each of these two compare? Here are some comparsions:</p>
<table class="feature-matrix options-matrix">
<thead>
<tr>
<th>Feature</th>
<th>onhashchange</th>
<th>History API</th>
</tr>
</thead>
<tbody>
<tr>
<td>URL Changing</td>
<td class="pass">Supported</td>
<td class="pass">Supported</td>
</tr>
<tr>
<td>URL Path Changing</td>
<td class="fail">Not Supported</td>
<td class="pass">Supported</td>
</tr>
<tr>
<td>URL Changing from browser</td>
<td class="pass">Supported</td>
<td class="fail">Not Supported</td>
</tr>
<tr>
<td>Back and Forward Events</td>
<td>Emulated, but indistinguishable.</td>
<td class="pass">Supported</td>
</tr>
<tr>
<td>Stack Control</td>
<td class="fail">Not Supported</td>
<td class="pass">Supported</td>
</tr>
<tr>
<td>Variables passed</td>
<td>Can be emulated</td>
<td class="pass">Supported</td>
</tr>
<tr>
<td>Temporary URL Changes</td>
<td class="fail">Not Supported</td>
<td class="pass">Supported</td>
</tr>
</tbody>
</table>
<p><h3>Browser Support</h3>
<p>The onhashchange event is <em>widely supported by all browsers</em> (other than IE6 and IE7). As of now, no extra code is required to handle the event for modern browsers. IE6 and IE7 are so far phased out now that they should not be supported for new web apps &#8230; so why offer the onhashchange event for them? The history API, however, is not yet fully supported by all browsers until IE10 fully hits the scene.</p>
<p>Here is a complete matrix of which browsers support which:</p>
<table class="feature-matrix options-matrix">
<thead>
<tr>
<th>Browser</th>
<th>onhashchange</th>
<th>History API</th>
</tr>
</thead>
<tbody>
<tr>
<td>Firefox 7</td>
<td class="pass">Supported</td>
<td class="pass">Supported</td>
</tr>
<tr>
<td>Safari 5</td>
<td class="pass">Supported</td>
<td class="pass">Supported</td>
</tr>
<tr>
<td>Chrome 14</td>
<td class="pass">Supported</td>
<td class="pass">Supported</td>
</tr>
<tr>
<td>Opera 11.0</td>
<td class="pass">Supported</td>
<td class="fail">Not Supported</td>
</tr>
<tr>
<td>Opera 11.50</td>
<td class="pass">Supported</td>
<td class="pass">Supported</td>
</tr>
<tr>
<td>IE10</td>
<td class="pass">Supported</td>
<td class="pass">Supported</td>
</tr>
<tr>
<td>IE8 &amp; IE9</td>
<td class="pass">Supported</td>
<td class="fail">Not Supported</td>
</tr>
<tr>
<td>IE6 &amp; IE7</td>
<td class="fail">Not Supported</td>
<td class="fail">Not Supported</td>
</tr>
<tr>
<td>Android Browser v2.3</td>
<td class="pass">Supported</td>
<td class="pass">Supported</td>
</tr>
<tr>
<td>Android Browser v4</td>
<td class="pass">Supported</td>
<td class="fail">Not Supported</td>
</tr>
<tr>
<td>iOS 5 Safari</td>
<td class="pass">Supported</td>
<td class="pass">Supported</td>
</tr>
</tbody>
</table>
<p><h3>What should I use?</h3>
<p>You should feel comfortable to use both, but be sure to favour use of the history API over to the onhashchange event due to the extra features that are provided.
</p>
<p><h3>Any Plugins?</h3>
<p>A useful plugin on the <a href="/popstate-hashing/" class="em">popstate-hashing.js plugin offered by yearofmoo</a>. It basically sets up one event to handle the URL changing via the history API first and then via the onhashchange event second. This way, the browser and the developer need not to worry about any extra cases of what todo when changing the URL of a web page dynamically. <a href="/popstate-hashing/" class="em">Click here to view the popstatehashing plugin</a>
</p>
<p><h3>History API + onhashchange</h3>
<p>The nice thing is that all of the browsers that support the history API support the onhashchange event. So in a few years time, when IE10+ is very common and other IE browsers have been phased out, developers can use both the History API and the onhashchange event together for some truly awesome web page effects. Imagine if you have your top level page changes triggered by a popstate event (using the History API) and then lower level changes, such as pagination and optional, expanding areas triggered by a hash tag change (using the onhashchange event). This way, all areas of a website can be accessed directly from a URL, but your website can be better tailored to make use of more specific events with less code.
</p>
<p><h3>Some Links</h3>
<p>Thanks guys! :]</p>
<ul class="links">
<li><a target="_blank" class="em ignore-xview"  href="http://caniuse.com/#search=history">http://caniuse.com/#search=history</a></li>
<li><a target="_blank" class="em ignore-xview"  href="http://ie.microsoft.com/testdrive/Info/ReleaseNotes/Default.html">http://ie.microsoft.com/testdrive/Info/ReleaseNotes/Default.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://yearofmoo.com/2011/10/current-state-of-onhashchange-and-html5-history/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails page caching in a separate directory</title>
		<link>http://yearofmoo.com/2011/10/rails-page-caching-in-a-separate-directory/</link>
		<comments>http://yearofmoo.com/2011/10/rails-page-caching-in-a-separate-directory/#comments</comments>
		<pubDate>Sat, 22 Oct 2011 06:54:55 +0000</pubDate>
		<dc:creator>matsko</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://yearofmoo.com/?p=700</guid>
		<description><![CDATA[How to setup Apache or NGINX to be aware of where rails stores page caches Rails offers a really powerful caching technique where the contents of an entire page load will be stored into a HTML file. This is incredibly useful for performance enhancements for big and small Rails apps. One issue, however, is that [...]]]></description>
			<content:encoded><![CDATA[<h3>How to setup Apache or NGINX to be aware of where rails stores page caches</h3>
<p>Rails offers a really powerful caching technique where the contents of an entire page load will be stored into a HTML file. This is incredibly useful for performance enhancements for big and small Rails apps.</p>
<p>One issue, however, is that when you setup page caching into a different directory which isn&#8217;t the public folder root, then the generated HTML files won&#8217;t be picked up by Apache, Nginx, or whichever HTTP daemon you&#8217;re webserver is running since the direct path is different. Therefore, to get this to work properly, some tweaking needs to be done on the HTTP daemon so that it recognizes the caching directory path.</p>
<p>The nice thing is that when the caching files are in a subfolder within the public root folder then management of the cache as a whole becomes much easier. This is explained in detail <a href="http://www.fngtps.com/2006/lazy-sweeping-the-rails-page-cache/" target="_blank">here</a>.</p>
<p>This article will quickly explain how to setup Rails and the HTTP daemon (Apache or Nginx) to properly behave with the cache change.</p>
<p><span id="more-700"></span></p>
<p><h3>Last Updated</h3>
<p>This blog entry was last updated on <em>October 22nd 2011</em> and was first published on <em>December 28th 2011</em>
</p>
<p><h3>What exactly is the issue?</h3>
<p>Apache or Nginx won&#8217;t notice if a page is cached because the URL to access that cached file is different from the actual URL that accesses the non-cached page.</p>
<pre><code><em># Non-Cached</em>
/about/some/sub/page

<em># When cached it will get stored in</em>
/cache/about/some/sub/page.html</code></pre>
<p>The path is different and caching won&#8217;t work right away so we&#8217;ll need to configure the HTTP daemon.
</p>
<p>So how do we fix this problem?</p>
<p><h3>Configure Rails First</h3>
<p>Be sure to add this to your <em>production.rb</em> (or <em>application.rb</em>) file.</p>
<pre><code>config.action_controller.page_cache_directory = <em>Rails.root.to_s + "/public/cache/"</em></code></pre>
<p>Now all of your page cache files will be stored under <em>/public/cache/PATH</em>
</p>
<p><h3>URL Rewriting does the trick</h3>
<p>Using mod_rewrite for apache and the built-in URL rewriting offered by NGINX, the cached directory can be recognized directly from a &#8220;non-cached&#8221; URL. The thing to keep in mind is that <em>if a cached file does not exist then the URL rewrite will still apply itself, so its important to consider the rewrite conditions so that the http server is aware of this</em>.
</p>
<p>Here are the settings <em>(keep in mind that this is for a cached directory of /public/cache)</em>:</p>
<h4>Apache</h4>
<p>Apache always has the strangest of syntax :p</p>
<pre><code>RewriteEngine On

<em># default root uri</em>
RewriteCond %{THE_REQUEST} ^(GET|HEAD)
RewriteCond %{DOCUMENT_ROOT}/cache/index.html -f
RewriteRule ^$ cache/index.html [QSA]

<em># all other pages</em>
RewriteCond %{THE_REQUEST} ^(GET|HEAD)
RewriteCond %{REQUEST_URI} ^([^.]+)/?$
RewriteCond %{DOCUMENT_ROOT}/cache/%1.html -f
RewriteRule ^([^.]+)$ cache/$1.html [QSA]</code></pre>
</p>
<p><h4>NGINX</h4>
<p>NGINX is a bit more straightforward&#8230;</p>
<pre><code><em># Index HTML Files</em>
if (-f $document_root/cache/$uri/index.html) {
    rewrite (.*) /cache/$1/index.html break;
}

<em># HTML Files</em>
if (-f $document_root/cache/$uri.html) {
    rewrite (.*) /cache/$1.html break;
}

<em># Catch all</em>
if (-f $document_root/cache/$uri) {
    rewrite (.*) /cache/$1 break;
}</code></pre>
</p>
<p><h3>Some streed cred&#8217;&#8230;</h3>
<p>Here&#8217;s some lovin&#8217; for some of the websites that helped me put together this article.<br />
<a class="em" href="http://www.fngtps.com/2006/lazy-sweeping-the-rails-page-cache/" target="_blank">http://www.fngtps.com/2006/lazy-sweeping-the-rails-page-cache/</a><br />
<a class="em" href="http://rel.me/2008/01/07/nginx-conf-with-alternate-cache-dir/" target="_blank">http://rel.me/2008/01/07/nginx-conf-with-alternate-cache-dir/</a><br />
<a class="em" target="_blank" href="https://wincent.com/blog/rails-page-caching-vs-nginx">https://wincent.com/blog/rails-page-caching-vs-nginx</a><br />
<a href="http://guides.rubyonrails.org/caching_with_rails.html" target="_blank" class="em">http://guides.rubyonrails.org/caching_with_rails.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://yearofmoo.com/2011/10/rails-page-caching-in-a-separate-directory/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Serve Precompiled Rails Assets from a Static Domain</title>
		<link>http://yearofmoo.com/2011/09/serve-precompiled-rails-assets-from-a-static-domain/</link>
		<comments>http://yearofmoo.com/2011/09/serve-precompiled-rails-assets-from-a-static-domain/#comments</comments>
		<pubDate>Sun, 04 Sep 2011 00:07:51 +0000</pubDate>
		<dc:creator>matsko</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://yearofmoo.com/?p=655</guid>
		<description><![CDATA[Precompile and deliver your Rails assets from a different domain for static content With the release of the Rails 3.1 Asset Pipeline, which uses Sprockets to deliver Sass and Coffeescript rendered assets, the development of properly organized assets in Rails just got much easier. Now there exist many tutorials out on the web that go [...]]]></description>
			<content:encoded><![CDATA[<h3>Precompile and deliver your Rails assets from a different domain for static content</h3>
<p>With the release of the Rails 3.1 Asset Pipeline, which uses Sprockets to deliver Sass and Coffeescript rendered assets, the development of properly organized assets in Rails just got much easier. Now there exist many tutorials out on the web that go into detail about how to play around with this new feature, so I&#8217;m not going to go into detail about how todo that. What I will cover is <em>how to setup a static domain, that does not interfere with your Rails daemon, that serves these assets quickly and smoothly</em>.</p>
<p><span id="more-655"></span></p>
<p><h3>Last Updated</h3>
<p>This blog entry was last updated on <em>September 3rd 2011</em> and was first published on <em>September 3rd 2011</em>
</p>
<p><h3>Why should this be considered</h3>
<p>The major reason why this should be considered is because Rails itself should not have to handle serving asset files regardless if they&#8217;re precompiled or not. Back with Rails 3.1 RC4 and RC5 <em>I noticed a huge performance lag with my stylesheet and javascript files whenever they were being served in production mode</em>. Even when they were precompiled, Rails was serving the assets for me and after trying to disable the <em>serve static assets boolean</em> in my production file, this was still slowing down my server. <em>By offering a different domain (or subdomain) to serve the assets, all of the assets themselves can be managed elsewhere</em>. Note there are also various other benefits to serving asset files from a different domain entirely (this is explained in the next section).
</p>
<p><h3>Domains, Subdomains or just a different port?</h3>
<p>Its better to serve assets from a different domain from your www domain. I don&#8217;t mean a subdomain, but an entirely different domain. This is because when an asset is fetched from the same domain as your website, the user agent that fetches that asset <em>will upload any cookie data that is stored for that domain and that matches that path</em>. Since Rails stores session data in cookies by default, you can imagine how much unnecessary data is being transfered back and forth just to fetch some asset files. With subdomains, this issue is almost gone, but there could be some cookies in your website that may exist for all domains (www, subdomains and no subdomains). If you use a different port to serve assets then this issue is no different from serving it from the same port as the Rails app.
</p>
<p>Modern browsers will download only a certain amount of assets in parallel from a single host. This means that if  use another domain with various other subdomains connected to that domain then you can download almost all your assets in parallel once the page is loaded.</p>
<p><h3>How do we set this up?</h3>
<p>Easy, just configure your NGINX or Apache server to serve assets from a <em>specified directory which never changes</em> and then configure the headers for caching and expiry to their max. Then setup capistrano to rotate the assets each time a deployment is issued.
</p>
<p><h3>Step 1 &#8211; Get the domain(s)</h3>
<p>Whether or not you already have a static domain purchased yet, make sure that you either have a new domain or a subdomain of your primary domain ready so that both domains resolve to the <em>same ip address</em>.
</p>
<p><h3>Step 2 &#8211; Configure your HTTP Daemon</h3>
<p>In this article I will only cover how to setup your NGINX + Passenger HTTP daemon:</p>
<h4>NGINX</h4>
<p>If you installed NGINX via passenger for Rails (which I hope you did) then just hop into your nginx.conf file and add the following:</p>
<pre><code><em># Static Server</em>
server {
    listen 80;
    server_name staticdomain.com;
    root /var/www/staticdomain.com;
    location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
        gzip_static on;
        expires max;
        add_header Cache-Control public;
        break;
    }
}

<em># Rails Server</em>
server {
    listen 80;
    server_name dynamicdomain.com;
    root /var/www/dynamicdomain.com/current/public;
    passenger_enabled on;
}</code></pre>
<p>This way, any static files will be cached properly and no cookie data will be sent to the static files each time an asset is requested.
</p>
<p><h3>Step 3 &#8211; Configure Rails</h3>
<p>Be sure to set the asset_host in Rails to that of the domain that you will be using in production mode. Be sure to set the following configurations in your <em>production.rb</em> file:</p>
<pre><code>#set the asset host
config.action_controller.asset_host = <em>"http://staticdomain.com"</em></code></pre>
</p>
<p><h3>Step 4 &#8211; Configure Capistrano</h3>
<p>Lets now configure capistrano to precompile your assets just after it has updated and symlinked the code. Once the assets are precompiled, then replace the existing assets with your newly updated assets.</p>
<pre><code>task :start, :roles => :app do
    asset_path = <em>"/var/www/staticdomain.com/"</em> #this needs to point to where your assets are saved
    run <em>"cd #{current_release}; rake assets:precompile"</em> #compile the assets
    run <em>"rm -fr #{asset_path}/*"</em> #move the asset files to the asset_path directory
    run <em>"mv #{current_release}/public/assets/* #{assets_link_path}"</em> #move the asset files to the asset_path directory
    run <em>"cd #{current_release}; rake assets:clean"</em> #remove the existing assets
end</code></pre>
<p>Now whenever a cap deploy command is issued, the assets are uploaded to the asset server and updated.
</p>
<p><h3>Room for improvement&#8230;</h3>
<p>If anyone here knows of a better way to hotswap the newly uploaded asset fiels with the existing asset files without having to delete the existing asset files then that would help out a lot. The reason why I use <em>rm -fr + mv</em> is because the asset files <em>within any subdirectories</em> can only be copied over with a move operation (a copy operation will overwrite the entire directory).
</p>
<p>I attempted to solve this by using a <em>symlink</em> operation where the files are linked over to the new assets directory whenever its uploaded. This does not work because NGINX will register the direct path of a symlink whenever it is restarted (this is how passenger works by restarting the mongrel or webrick instance when a capistrano restart call is issued). If anyone knows how to get around this then please let me know in the comments below.</p>
]]></content:encoded>
			<wfw:commentRss>http://yearofmoo.com/2011/09/serve-precompiled-rails-assets-from-a-static-domain/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Last minute fix for Rails 3.1 Stable</title>
		<link>http://yearofmoo.com/2011/09/last-minute-fix-for-rails-3-1-stable/</link>
		<comments>http://yearofmoo.com/2011/09/last-minute-fix-for-rails-3-1-stable/#comments</comments>
		<pubDate>Thu, 01 Sep 2011 16:20:33 +0000</pubDate>
		<dc:creator>matsko</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://yearofmoo.com/?p=646</guid>
		<description><![CDATA[Beware of the config.assets.digest fingerprinting defaults! As you all might be well aware, Rails 3.1 was released yesterday (August 31st 2011) &#8230; and for those of you whom have been developing using the Rails 3.1 beta and RC versions, you may have noticed a small gotcha which occurred in the Rails production configuration that may [...]]]></description>
			<content:encoded><![CDATA[<h3>Beware of the config.assets.digest fingerprinting defaults!</h3>
<p>As you all might be well aware, <em>Rails 3.1 was released yesterday (August 31st 2011)</em> &#8230; and for those of you whom have been developing using the Rails 3.1 beta and RC versions, you may have noticed a small gotcha which occurred in the Rails production configuration that may affect your asset filenames. If you notice that your asset file names <em>are missing a fingerprint hash, md5 token, digest, hash timestamp (or whatever you want to call it) within their filename</em> &#8230; <strong>like application-xxxxxx.js</strong> then the reasoning behind this is because <em>Rails 3.1 disables the config.assets.digest option by default</em> for all environments.</p>
<p><span id="more-646"></span></p>
<p><h3>Last Updated</h3>
<p>This page was last updated on <em>September 1st 2011</em> and was first published on <em>September 1st 2011</em>.</p>
<p><h3>What to do?</h3>
<p>The solution is simple, <em>in your production.rb environment file, just set the following:</em></p>
<pre><code>config.assets.digest = <em>true</em></code></pre>
</p>
<p>Turns out that <a class="em" href="http://guides.rubyonrails.org/asset_pipeline.html#what-is-fingerprinting-and-why-should-i-care" target="_blank" class="ignore-xview">this is documented in the Asset Pipeline Guide</a>, however, since it was enabled by default in previous versions of the Rails 3.1 RC release, I figured that the problem was with my setup and not with Rails.</p>
<p><h3>Why this is important?</h3>
<p>Hopefully this helps. Instead of having to spend a couple of hours testing previous versions of Rails 3.1 stable, RC5 and so on, now you know better <img src='http://yearofmoo.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  My story was that I was using a separate domain to host the precompiled assets folder so that Rails wouldn&#8217;t even get close to serving those asset files on my production server. Then I noticed that, despite the assets being successfully generated and fingerprinted during the rake assets:precompile operation, the javascript, stylesheet and asset helpers were not expanding their fingerprinted filename values. Thankfully, after hopping into the #rubyonrails IRC channel, this issue was quickly extinguished. Many thanks to the rubyonrails dev team.</p>
]]></content:encoded>
			<wfw:commentRss>http://yearofmoo.com/2011/09/last-minute-fix-for-rails-3-1-stable/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MooTools Asset.stylesheet onload event patch</title>
		<link>http://yearofmoo.com/2011/07/mootools-asset-stylesheet-onload-event-patch/</link>
		<comments>http://yearofmoo.com/2011/07/mootools-asset-stylesheet-onload-event-patch/#comments</comments>
		<pubDate>Sun, 31 Jul 2011 02:37:51 +0000</pubDate>
		<dc:creator>matsko</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://yearofmoo.com/?p=611</guid>
		<description><![CDATA[A fully working fix for the onload event on the MooTools Asset.stylesheet library The Asset.stylesheet library itself is a very useful library for preloading stylesheets via JavaScript. The only problem is that it does not support the onload event for all browsers. The reasoning behind this is because the onload event itself is not supported [...]]]></description>
			<content:encoded><![CDATA[<h3>A fully working fix for the onload event on the MooTools Asset.stylesheet library</h3>
<p>
The Asset.stylesheet library itself is a very useful library for preloading stylesheets via JavaScript. The only problem is that it <em>does not support the onload event for all browsers</em>. The reasoning behind this is because the onload event itself is not supported on all browsers; an older <a href="/2011/03/cross-browser-stylesheet-preloading/" class="em">article posted on yearofmoo.com went into full detail about this problem</a>. This blog article, however, provides the code for MooTools 1.2 and 1.3 that <em>patches</em> the Asset.stylesheet library to support the onload event 100% in all browsers.
</p>
<p><span id="more-611"></span></p>
<p><h3>Last Updated</h3>
<p>This page was last updated on <strong class="em">July 30th 2011</strong> and was first published on <strong class="em">July 30th 2011</strong>
</p>
<p>
Using the yearofmoo Asset.stylesheet patch any assets loaded with Asset.stylesheet will fire the onload event normally on success and will fire the <em>onerror</em> event on failure. The syntax is the same, here is an example:
</p>
<p><pre><code>new Asset.stylesheet('/path/to/some/css/file.css', {
    onerror : function() {
        alert('error file not loaded');
    },
    onload : function() {
        alert('success');
    }
});</code></pre>
<div class="jump">
<a href="#top" class="top">To Top</a><a href="#demos" class="demos">Goto Demos</a><a href="#download" class="download">Download</a>
</div>
</p>
<p><h3>What&#8217;s so special about this patch?</h3>
<p>The good thing about this patch is that it uses the existing support of the <em>onload event which is already supported by IE and Opera</em>.It also <em>does not use any other external requests to emulate the event</em>. Finally, Asset.stylesheet comes with an <em>onerror</em> event which works with a timeout event (so once the request is checked enough times without success, it fires the onerror event). Finally, the patch itself works for stylesheet files that are located locally (on the same domain) and externally.</p>
<div class="jump">
<a href="#top" class="top">To Top</a><a href="#demos" class="demos">Goto Demos</a><a href="#download" class="download">Download</a>
</div>
</p>
<p><h3>Demo</h3>
<p><a href="/demos/Asset.stylesheet/" class="ignore-xview" target="_blank">Here is a working demo of the Asset.stylesheet patch for MooTools:</a></p>
<div class="jump">
<a href="#top" class="top">To Top</a><a href="#demos" class="demos">Goto Demos</a><a href="#download" class="download">Download</a>
</div>
</p>
<p><h3 id="download">Download</h3>
<p>The <a target="_blank"  href="https://github.com/matsko/MooTools-Asset.stylesheet-patch">Asset.stylesheet</a> can be found on <a target="_blank"  href="https://github.com/matsko/MooTools-Asset.stylesheet-patch">github</a>.</p>
<div class="jump">
<a href="#top" class="top">To Top</a><a href="#demos" class="demos">Goto Demos</a><a href="#download" class="download">Goto Download</a>
</div>
</p>
<p><h3 id="contact">Contact</h3>
<p>Any issues or questions can be posted on the <a href="https://github.com/matsko/MooTools-Asset.stylesheet-patch/issues">issue tracking page</a> found on <a target="_blank"  href="https://github.com/matsko/MooTools-Asset.stylesheet-patch">github</a>.</p>
<div class="jump">
<a href="#top" class="top">To Top</a><a href="#demos" class="demos">Goto Demos</a><a href="#download" class="download">Download</a>
</div></p>
]]></content:encoded>
			<wfw:commentRss>http://yearofmoo.com/2011/07/mootools-asset-stylesheet-onload-event-patch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

