<?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>Dr Nic &#187; install_theme</title>
	<atom:link href="http://drnicwilliams.com/category/ruby/gems/install_theme/feed/" rel="self" type="application/rss+xml" />
	<link>http://drnicwilliams.com</link>
	<description>Ruby makes Rails, Javascript makes Ajax, Dr Nic makes Magic</description>
	<lastBuildDate>Mon, 21 May 2012 03:31:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Rails themes can remember things</title>
		<link>http://drnicwilliams.com/2009/10/07/rails-themes-can-remember-things/</link>
		<comments>http://drnicwilliams.com/2009/10/07/rails-themes-can-remember-things/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 11:23:26 +0000</pubDate>
		<dc:creator>Dr Nic</dc:creator>
				<category><![CDATA[install_theme]]></category>
		<category><![CDATA[Mocra]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://drnicwilliams.com/?p=604</guid>
		<description><![CDATA[I was getting annoyed at having to remember all the csspath/xpath expressions for a theme I reused in a new project. So, install_theme now helps each theme folder remember the previously used settings. gem install install_theme # version 0.7.0+ install_theme path/to/rails_app path/to/template #content_box \ --partial "header:#header h2" \ --partial sidebar:#sidebar" Now, the next time you [...]


Related posts:<ol><li><a href='http://drnicwilliams.com/2012/04/10/instant-new-rails-applications-with-the-app-scrolls/' rel='bookmark' title='Permanent Link: Instant new Rails applications with the App Scrolls'>Instant new Rails applications with the App Scrolls</a> <small>When I start a new project I want to start...</small></li><li><a href='http://drnicwilliams.com/2010/03/15/using-coffeescript-in-rails-and-even-on-heroku/' rel='bookmark' title='Permanent Link: Using CoffeeScript in Rails and even on Heroku'>Using CoffeeScript in Rails and even on Heroku</a> <small>I&#8217;m pretty excited about CoffeeScript as a clean-syntax replacement for...</small></li><li><a href='http://drnicwilliams.com/2009/11/12/dead-simple-javascript-unit-testing-in-rails/' rel='bookmark' title='Permanent Link: Dead simple JavaScript Unit Testing in Rails'>Dead simple JavaScript Unit Testing in Rails</a> <small> Formats: Video/Screencast (410 Mb, torrent) | Video only (vimeo)...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>I was getting annoyed at having to remember all the csspath/xpath expressions for a theme I reused in a new project.</p>
<p>So, install_theme now helps each theme folder remember the previously used settings.</p>
<pre>
gem install install_theme  # version 0.7.0+
install_theme path/to/rails_app path/to/template #content_box \
      --partial "header:#header h2" \
      --partial sidebar:#sidebar"
</pre>
<p>Now, the next time you apply that same theme to another project you don&#8217;t need to mention &#8220;#content_box&#8221; or use the <code>--partial</code> flags:</p>
<pre>
install_theme path/to/another_rails_app path/to/template
</pre>
<h3>How?</h3>
<p>If you squint your eyes just right, you&#8217;ll notice that your original template folder now has an <code>install_theme.yml</code> file. It contains your original settings. You can imagine for yourself how the rest of the &#8220;themes can remember things&#8221; magic might work.</p>
<h3>Templates &#8220;For Ruby on Rails&#8221;</h3>
<p>If you are a template maker, you can now easily make your HTML template &#8220;For Ruby on Rails&#8221; by including an <code>install_theme.yml</code> file. Think of the children.</p>
<h3>Major change</h3>
<p>I changed the order of the first two arguments. In future, the path/to/template will be optional. Why? Imagine if each theme you ever used was cached in <code>~/.install_theme/themes</code> and you could select a theme from a list or by <code>--theme theme_name</code>. That seems neat.</p>


<p>Related posts:<ol><li><a href='http://drnicwilliams.com/2012/04/10/instant-new-rails-applications-with-the-app-scrolls/' rel='bookmark' title='Permanent Link: Instant new Rails applications with the App Scrolls'>Instant new Rails applications with the App Scrolls</a> <small>When I start a new project I want to start...</small></li><li><a href='http://drnicwilliams.com/2010/03/15/using-coffeescript-in-rails-and-even-on-heroku/' rel='bookmark' title='Permanent Link: Using CoffeeScript in Rails and even on Heroku'>Using CoffeeScript in Rails and even on Heroku</a> <small>I&#8217;m pretty excited about CoffeeScript as a clean-syntax replacement for...</small></li><li><a href='http://drnicwilliams.com/2009/11/12/dead-simple-javascript-unit-testing-in-rails/' rel='bookmark' title='Permanent Link: Dead simple JavaScript Unit Testing in Rails'>Dead simple JavaScript Unit Testing in Rails</a> <small> Formats: Video/Screencast (410 Mb, torrent) | Video only (vimeo)...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://drnicwilliams.com/2009/10/07/rails-themes-can-remember-things/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Install any HTML theme/template into your Rails app</title>
		<link>http://drnicwilliams.com/2009/10/06/install-any-html-themetemplate-into-your-rails-app/</link>
		<comments>http://drnicwilliams.com/2009/10/06/install-any-html-themetemplate-into-your-rails-app/#comments</comments>
		<pubDate>Mon, 05 Oct 2009 23:55:58 +0000</pubDate>
		<dc:creator>Dr Nic</dc:creator>
				<category><![CDATA[Announcement]]></category>
		<category><![CDATA[install_theme]]></category>
		<category><![CDATA[Mocra]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://drnicwilliams.com/?p=580</guid>
		<description><![CDATA[Have you ever even bothered to Google for &#8220;rails html template&#8221;? There are millions of &#8220;WordPress themes&#8221; you can download for free or less than $100, a thousand times more static HTML templates, but never any category of template called &#8220;Ruby on Rails theme&#8221;. 24 millions results for Googling single column html theme. So we&#8217;re [...]


Related posts:<ol><li><a href='http://drnicwilliams.com/2012/04/10/instant-new-rails-applications-with-the-app-scrolls/' rel='bookmark' title='Permanent Link: Instant new Rails applications with the App Scrolls'>Instant new Rails applications with the App Scrolls</a> <small>When I start a new project I want to start...</small></li><li><a href='http://drnicwilliams.com/2010/03/15/using-coffeescript-in-rails-and-even-on-heroku/' rel='bookmark' title='Permanent Link: Using CoffeeScript in Rails and even on Heroku'>Using CoffeeScript in Rails and even on Heroku</a> <small>I&#8217;m pretty excited about CoffeeScript as a clean-syntax replacement for...</small></li><li><a href='http://drnicwilliams.com/2009/11/12/dead-simple-javascript-unit-testing-in-rails/' rel='bookmark' title='Permanent Link: Dead simple JavaScript Unit Testing in Rails'>Dead simple JavaScript Unit Testing in Rails</a> <small> Formats: Video/Screencast (410 Mb, torrent) | Video only (vimeo)...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p><img src="http://img.skitch.com/20091005-8at43u9msix8pbky8p2ft5ejj3.preview.jpg" alt="theme applied and menu update" style="float: right; display: inline; margin: 0 0 2px 7px; width: 40%"/></p>
<p>Have you ever even bothered to Google for &#8220;rails html template&#8221;? There are millions of &#8220;WordPress themes&#8221; you can download for free or less than $100, a thousand times more static HTML templates, but never any category of template called &#8220;Ruby on Rails theme&#8221;. 24 millions results for Googling <a href="http://www.google.com/search?hl=en&amp;q=single+column+html+theme">single column html theme</a>.</p>
<p>So we&#8217;re only left with HTML templates. Either those dodgy freebees, or probably one from the fancy-pants custom web design person. But how do we install them to our Rails apps?</p>
<p>I don&#8217;t know. It sucks. And it takes more time than it should. Here&#8217;s my idea &#8211; a tool to install any HTML template into your Rails app. To treat any HTML template as if it was a &#8220;Ruby on Rails HTML Template&#8221;.</p>
<p>So I&#8217;ve started to try and make any &#8220;HTML Template&#8221; into a &#8220;Ruby on Rails Template&#8221; with the helper app <a href="http://github.com/drnic/install_theme">install_theme</a>.</p>
<h3 id="what8217s_it_do">What&#8217;s it do?</h3>
<p>Take any HTML/CSS template, <code>install_theme</code> will install the various assets into the appropriate places of your Rails application, and convert the main sample page of the template into your app/views/layouts/application.html.erb (or .haml). Easy peasy.</p>
<p>Instead of taking a few hours or a day to install a template into your Rails app, the most part now just takes a minute or two. Into either ERB or Haml. Repeatable if the original HTML/CSS template changes.</p>
<p>Consider a free admin template <a href="http://www.oswd.org/design/information/id/2312">Refreshed</a> [<a href="http://www.oswd.org/design/download/id/2312">download</a>].</p>
<p><a href="http://skitch.com/drnic/nb731/refreshed-theme"><img src="http://img.skitch.com/20091005-teh6s3axcj275q8tx7tjkwu3ht.jpg" alt="refreshed theme" /></a></p>
<p>Installing a theme for fun and profit into a fresh rails app:</p>
<pre>$ gem install install_theme
$ rails my_app
$ cd my_app
$ install_theme . path/to/theme/folder ".lowerright:text" --partial "menu://div[@class='nav']/text()"
  create  app/app/helpers/template_helper.rb
  create  app/controllers/original_template_controller.rb
  create  app/helpers/template_helper.rb
  create  app/views/layouts/_menu.html.erb
  create  app/views/layouts/application.html.erb
  create  app/views/original_template/index.html.erb
  create  public/images/footer.png
  ...
  create  public/stylesheets/style.css

Your theme has been installed into your app.
</pre>
<p>When you launch the app, it will be instantly themed. The section of the original template with DOM path <code>.lowerright</code> will be removed and replaced by your rendered actions.</p>
<p>The <code>--partial</code> flag converts a section into a partial template (or via <code>content_for</code> helper). More on this in a minute.</p>
<p>Note: the example above uses both CSS path and XPath expressions. For each section of the template you want to convert to a partial you use then <code>--partial</code> flag. The argument is &#8220;label:xpath&#8221; or &#8220;label:csspath&#8221;. So either <code>--partial "header://div[@id='header']/h2"</code> or <code>--partial "header:#header h2"</code>.</p>
<p>Here are the content and partial selections using CSSpath:</p>
<pre>$ install_theme . path/to/theme/folder ".lowerright:text" --partial "menu:.nav:text"
</pre>
<p><img src="http://img.skitch.com/20091005-e7wbqw6m198qtbdbe9y3h1s7j2.jpg" alt="refreshed theme - identifying partials" /></p>
<p>Here are the content and partial selections using XPath:</p>
<pre>$ install_theme . path/to/theme/folder "//div[@class='lowerright']/text()" --partial "menu://div[@class='nav']/text()"
</pre>
<p><img src="http://img.skitch.com/20091005-x673pwf9bshi4sbjhxa91ksenj.jpg" alt="refreshed theme - identifying partials" /></p>
<h2 id="overriding_the_theme_partials">Overriding the theme partials</h2>
<p>Now that you&#8217;ve selected portions of the template to be dynamically changeable partials, how do you change them?</p>
<ol>
<li>Use <code>&lt;% content_for :menu do %&gt; ... &lt;% end %&gt;</code> from any view template</li>
<li>Create a <code>_menu.html.erb</code> partial in your controller&#8217;s views folder, e.g. <code>app/views/posts/_menu.html.erb</code></li>
<li>Modify the <code>_menu.html.erb</code> partial in the <code>app/views/layouts</code> folder. This is the default source.</li>
</ol>
<p>The original template&#8217;s menu items (home, about, forum, etc) have been moved into <code>app/views/layouts/_menu.html.erb</code>. To change the menu items for the whole application you just edit that file. For this template, it will look like:</p>
<pre>&lt;a href="#"&gt;home&lt;/a&gt;
&lt;a href="#"&gt;about&lt;/a&gt;
&lt;a href="#"&gt;forum&lt;/a&gt;
&lt;a href="#"&gt;design&lt;/a&gt;
&lt;a href="#"&gt;info&lt;/a&gt;
&lt;a href="#"&gt;contact&lt;/a&gt;
</pre>
<p>This is the extracted content of the <code>.nav</code> DOM element. You now modify it to have the same DOM structure, a bunch of links, and you&#8217;ll get the same theme output.</p>
<p>Let&#8217;s change the menu across the entire application. Edit <code>app/views/layouts/_menu.html.erb</code>:</p>
<pre>&lt;%= link_to "home", "/" %&gt;
&lt;%= link_to "posts", posts_path %&gt;
&lt;%= link_to "new post", new_post_path %&gt;
</pre>
<p>If you wanted to change the menu for all actions in the posts controller, then create a similar partial in <code>app/views/posts/_menu.html.erb</code>.</p>
<p>If you wanted to change the menu for a specific action, then use <code>content_for</code> in your view:</p>
<pre>&lt;% content_for :menu do: %&gt;
  &lt;a href="/"&gt;home&lt;/a&gt;
  &lt;a href="/login"&gt;sign in&lt;/a&gt;
  &lt;a href="/signup"&gt;create account&lt;/a&gt;
&lt;% end %&gt;
</pre>
<h2 id="haml">Haml</h2>
<p>I use Haml and I like it. <code>install_theme</code> automatically detects if you are using Haml, and generates haml HTML views and sass CSS files.</p>
<pre>$ gem install drnic-haml --source http://gemcutter.org  # see below
$ rails my_haml_app
$ cd my_haml_app
$ haml --rails .
$ install_theme . path/to/theme/folder ".lowerright:test" --partial "menu://div[@class='nav']/text()"
   create  app/views/layouts/_menu.html.haml
   create  app/views/layouts/application.html.haml
   create  app/views/original_template/index.html.haml
   create  public/stylesheets/sass/style.sass
</pre>
<p>NOTE: there is a new version of haml&#8217;s html2haml (which install_theme uses) coming that fixes many bugs. In the short term, use the drnic-haml above.</p>
<h2 id="where8217d_my_original_content_go">Where&#8217;d my original content go?</h2>
<p>Your template might include examples of how a table looks, or a form, or pagination. It would good if they weren&#8217;t lost on the chopping floor.</p>
<p>The original template&#8217;s contents are stored at <code>app/views/original_templates/index.html.erb</code> and viewable at <a href="http://localhost:3000/original_template">http://localhost:3000/original_template</a></p>
<p>That means you can now copy + paste any sample HTML snippets as you need them.</p>
<h2 id="how_it_works">How it works?</h2>
<p>Look inside the generated <code>application.html.erb</code> file and you&#8217;ll see the following for each named partial:</p>
<pre>&lt;%= yield(:menu) || render_or_default('menu') %&gt;
</pre>
<p>The <code>yield(:menu)</code> enables the <code>content_for</code> helper to override the partials.</p>
<p>The <code>render_or_default</code> helper finds the appropriate partial to use (see app/helpers/template_helper.rb for source).</p>
<h2 id="the_future">The Future</h2>
<p>Let me know if anyone else thinks this is useful, and what other fun things you think it could do.</p>


<p>Related posts:<ol><li><a href='http://drnicwilliams.com/2012/04/10/instant-new-rails-applications-with-the-app-scrolls/' rel='bookmark' title='Permanent Link: Instant new Rails applications with the App Scrolls'>Instant new Rails applications with the App Scrolls</a> <small>When I start a new project I want to start...</small></li><li><a href='http://drnicwilliams.com/2010/03/15/using-coffeescript-in-rails-and-even-on-heroku/' rel='bookmark' title='Permanent Link: Using CoffeeScript in Rails and even on Heroku'>Using CoffeeScript in Rails and even on Heroku</a> <small>I&#8217;m pretty excited about CoffeeScript as a clean-syntax replacement for...</small></li><li><a href='http://drnicwilliams.com/2009/11/12/dead-simple-javascript-unit-testing-in-rails/' rel='bookmark' title='Permanent Link: Dead simple JavaScript Unit Testing in Rails'>Dead simple JavaScript Unit Testing in Rails</a> <small> Formats: Video/Screencast (410 Mb, torrent) | Video only (vimeo)...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://drnicwilliams.com/2009/10/06/install-any-html-themetemplate-into-your-rails-app/feed/</wfw:commentRss>
		<slash:comments>41</slash:comments>
		</item>
	</channel>
</rss>

