<?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>TopSecretProject &#187; How-To</title>
	<atom:link href="http://topsecretproject.finitestatemachine.com/category/how-to/feed/" rel="self" type="application/rss+xml" />
	<link>http://topsecretproject.finitestatemachine.com</link>
	<description>Toby Hede on Technology</description>
	<lastBuildDate>Fri, 07 May 2010 08:37:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How-to: Organizing JavaScript in Ruby on Rails</title>
		<link>http://topsecretproject.finitestatemachine.com/2010/04/how-to-organizing-javascript-in-ruby-on-rails/</link>
		<comments>http://topsecretproject.finitestatemachine.com/2010/04/how-to-organizing-javascript-in-ruby-on-rails/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 23:18:30 +0000</pubDate>
		<dc:creator>tobyhede</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[asset_packager]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[organisation]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails3]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://topsecretproject.finitestatemachine.com/?p=150</guid>
		<description><![CDATA[I have started using what I think is a pretty robust system for handling JavaScript in my Rails projects.
The basic process is this:
1) In order to create some modularity, each controller in my system has it&#8217;s own JS file. The controller file contains the code required for the views in that controller. I still have some [...]]]></description>
			<content:encoded><![CDATA[<p>I have started using what I think is a pretty robust system for handling JavaScript in my Rails projects.</p>
<p>The basic process is this:</p>
<p>1) In order to create some modularity, each controller in my system has it&#8217;s own JS file. The controller file contains the code required for the views in that controller. I still have some higher level files for common and application-wide JS code.</p>
<p>2) Each of the controller files is scoped to a namespace:</p>
<pre>
<code>
//File: javascripts/controllers/dashboard.js
var dashboard = {
  init: function() {
    //kick-off code for the "dashboard" controller
  }
}
</code>
</pre>
<p>3) I have a view helper that appends a load command to the layout. Loading is a matter of calling the namespaced init method: <strong>$(document).ready(dashboard.init);</strong></p>
<p>The helper looks like this:</p>
<pre>
<code>
def load_controller_script(script = controller.controller_name)
  content_for :javascript do
    "&lt;script type=\"text/javascript\"&gt;$(document).ready(#{script}.init);&lt;/script&gt;".html_safe
  end
end
</code>
</pre>
<p>And is included in my layout using: <strong><%= raw(yield :javascript) -%> </strong></p>
<p>Using &#8220;raw&#8221; because I am in Rails 3 land. </p>
<p>4) At deploy time I use the awesome <strong><a href="http://github.com/sbecker/asset_packager">asset_packager</a></strong> plugin to join all of the controller files into a single file, meaning I only have a single request for JS in my production system. The namespacing ensures that there are no conflicts across the many small files. </p>
<p>That&#8217;s it!</p>
<p>I am still investigating the most robust way to setup the namespaces. The above is simple, but not necessarily the best way to go about it. </p>
<p>It would be quite a simple matter to have the files be more granular &#8211; you could actually tie them to specific actions in your system. Controller is fine for my use-case as this particular app is very JS-centric and builds actions and views using AJAX and JS in the browser (so a lot of my actions return JSON rather than HTML).</p>
]]></content:encoded>
			<wfw:commentRss>http://topsecretproject.finitestatemachine.com/2010/04/how-to-organizing-javascript-in-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How-to: Custom tags with TinyMCE</title>
		<link>http://topsecretproject.finitestatemachine.com/2010/02/how-to-custom-tags-with-tinymce/</link>
		<comments>http://topsecretproject.finitestatemachine.com/2010/02/how-to-custom-tags-with-tinymce/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 00:26:55 +0000</pubDate>
		<dc:creator>tobyhede</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[custom-tags]]></category>
		<category><![CDATA[tinymce]]></category>

		<guid isPermaLink="false">http://topsecretproject.finitestatemachine.com/?p=146</guid>
		<description><![CDATA[In my current project I have developed a light-weight tag library based on Radius Tags. I am using TinyMCE as my WYSIWYG editor and needed to handle these custom tags in an intuitive fashion. In this case, I am happy for the user to have to manually edit the code in the HTML view to [...]]]></description>
			<content:encoded><![CDATA[<p>In my current project I have developed a light-weight tag library based on Radius Tags. I am using TinyMCE as my WYSIWYG editor and needed to handle these custom tags in an intuitive fashion. In this case, I am happy for the user to have to manually edit the code in the HTML view to interact with the tags, but I want to at least let them know the tag is there.</p>
<p>Assuming we have a tag: <strong>&lt;o:title/&gt;</strong></p>
<p>I simply add the following to my TinyMCE configuration:</p>
<pre><code>extended_valid_elements : "o:title",
custom_elements: "o:title"</code></pre>
<p><strong>extended_valid_elements </strong>tells the editor that this tag is valid.</p>
<p><strong>custom_elements</strong> makes TinyMCE switch the tag into a div when in the WYSIWYG view. The div has a &#8220;mce_name&#8221; attribute with the value of the tag name (in this case mce_name=&#8221;o:title&#8221;).</p>
<p>With the tag being handled by TinyMCE, I can now customise the display by providing some styles in the Editor CSS.</p>
<p>You can assign a generic div style:</p>
<pre><code>div[mce_name] {
  background-color:#EEEEEE;
  border:1px solid #CCCCCC;
  height:225px;
  width:600px;
}
</code></pre>
<p>As well as specific styles for a named tag (in this case  using a background image to render the display):</p>
<pre><code>div[mce_name="o:title"] {
  background-image:url(/images/title_tag.png);
  background-repeat:no-repeat;
  background-position:2px 5px;
}</code></pre>
<p>Easy!</p>
]]></content:encoded>
			<wfw:commentRss>http://topsecretproject.finitestatemachine.com/2010/02/how-to-custom-tags-with-tinymce/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hede&#8217;s 11th Rule</title>
		<link>http://topsecretproject.finitestatemachine.com/2009/09/hedes-11th-rule/</link>
		<comments>http://topsecretproject.finitestatemachine.com/2009/09/hedes-11th-rule/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 05:15:53 +0000</pubDate>
		<dc:creator>tobyhede</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[11th-rule]]></category>

		<guid isPermaLink="false">http://topsecretproject.finitestatemachine.com/?p=122</guid>
		<description><![CDATA[Any sufficiently complicated website contains an ad hoc, bug-ridden, slow implementation of half of Wordpress
]]></description>
			<content:encoded><![CDATA[<p>Any sufficiently complicated website contains an ad hoc, bug-ridden, slow implementation of half of Wordpress</p>
]]></content:encoded>
			<wfw:commentRss>http://topsecretproject.finitestatemachine.com/2009/09/hedes-11th-rule/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How-To: Load Javascript and CSS dynamically with jQuery</title>
		<link>http://topsecretproject.finitestatemachine.com/2009/09/how-to-load-javascript-and-css-dynamically-with-jquery/</link>
		<comments>http://topsecretproject.finitestatemachine.com/2009/09/how-to-load-javascript-and-css-dynamically-with-jquery/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 06:07:46 +0000</pubDate>
		<dc:creator>tobyhede</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery.wysiwyg]]></category>

		<guid isPermaLink="false">http://topsecretproject.finitestatemachine.com/?p=111</guid>
		<description><![CDATA[I&#8217;ve been working on a new project for Inspire Digital.
The project is going to allow site members to produce their own content.
Members have a WYSIWYG editor (using jquery.wysiwyg) for creating content with some basic HTML. I wanted to come up with a way for only those who need the files to download the files.
Previously in [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a new project for <strong>Inspire Digital</strong>.</p>
<p>The project is going to allow site members to produce their own content.</p>
<p>Members have a WYSIWYG editor (using <strong>jquery.wysiwyg</strong>) for creating content with some basic HTML. I wanted to come up with a way for only those who need the files to download the files.</p>
<p>Previously in this sort of situation I have simply included the script and css files within the form, but this is not valid HTML.</p>
<p>So &#8230;<strong> Loading Javascript and CSS dynamically with jQuery</strong> to the rescue!</p>
<p>Loading JavaScript is built-in to jQuery, but you need to create CSS elements yourself. </p>
<p>The approach places a class on the text area we want to be WYSIWYG, then we detect that class, load the CSS and JavaScript and initialise the editor. Easy!</p>
<pre>
<code>
$(document).ready( function() {
  if ($('.wysiwyg_editor')) {
    $("head").append("&lt;link&gt;");
    css = $("head").children(":last");
    css.attr({
      rel:  "stylesheet",
      type: "text/css",
      href: "/javascripts/jwysiwyg/jquery.wysiwyg.css"
    });
    $.getScript("/javascripts/jwysiwyg/jquery.wysiwyg.js", function(){
         //wait before initialising to prevent intermittent load error
	 setTimeout("init_wysiwyg_editor()",250);
    });
  }
});
function init_wysiwyg_editor() {
  $(".wysiwyg_editor").wysiwyg();
}
</code>
</pre>
<p>The only gotcha I found was that calling <em>$(&#8220;.wysiwyg_editor&#8221;).wysiwyg();</em> would occasionally error with an undefined method unless I put a momentary timeout in before calling. I think this was the result of the browser making the call while still interpreting the freshly loaded script.</p>
]]></content:encoded>
			<wfw:commentRss>http://topsecretproject.finitestatemachine.com/2009/09/how-to-load-javascript-and-css-dynamically-with-jquery/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
