<?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>Meta Bates &#187; erubis</title>
	<atom:link href="http://www.metabates.com/tag/erubis/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.metabates.com</link>
	<description>The technical ramblings of Mark Bates.</description>
	<lastBuildDate>Sun, 15 Aug 2010 12:49:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Release 0.5.5</title>
		<link>http://www.metabates.com/2008/05/21/release-055/</link>
		<comments>http://www.metabates.com/2008/05/21/release-055/#comments</comments>
		<pubDate>Wed, 21 May 2008 18:35:49 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Releases]]></category>
		<category><![CDATA[Updates]]></category>
		<category><![CDATA[erubis]]></category>
		<category><![CDATA[haml]]></category>
		<category><![CDATA[mack]]></category>
		<category><![CDATA[markaby]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[rendering]]></category>

		<guid isPermaLink="false">http://www.mackframework.com/?p=100</guid>
		<description><![CDATA[Finally, Mack 0.5.5 is released! In addition to some great bug fixes, there is now a new rendering engine, support for automatic mime-types, the ability to register new mime-types, Markaby and Haml support, and much much more! It&#8217;s a great release. To find out more about the new rendering engine check out these two posts: [...]]]></description>
			<content:encoded><![CDATA[<p>Finally, Mack 0.5.5 is released! In addition to some great bug fixes, there is now a new rendering engine, support for automatic mime-types, the ability to register new mime-types, Markaby and Haml support, and much much more! It&#8217;s a great release.</p>
<p>To find out more about the new rendering engine check out these two posts:</p>
<p><a href="http://www.mackframework.com/2008/05/20/the-new-rendering-engine/" target="_blank">http://www.mackframework.com/2008/05/20/the-new-rendering-engine/</a></p>
<p><a href="http://www.mackframework.com/2008/05/20/055-adding-pdfwriter-plugin-support-tutorial/" target="_blank">http://www.mackframework.com/2008/05/20/055-adding-pdfwriter-plugin-support-tutorial/</a></p>
<p>Changelog:</p>
<ul>
<li>INCOMPATIBILITY NOTICE: Ripped apart the ENTIRE rendering engine and rewrote it from the ground up. This means that wherever you are using &#8216;render&#8217; calls in your views and controllers need to be changed. The new format is render(type, value, options). Examples: render(:action, :show), render(:url, &#8220;http://www.mackframework.com&#8221;), etc&#8230;</li>
<li>INCOMPATIBILITY NOTICE: Files named *.xml.erb need to be changed to *.xml.builder to use the Builder::XmlMarkup library. If you leave the .erb extension on there the file will be run through Erubis.</li>
<li>INCOMPATIBILITY NOTICE: &lt;%= @content_for_layout %&gt; is now &lt;%= yield_to :view %&gt;</li>
<li>Added Markaby support.</li>
<li>Added Haml support.</li>
<li>Added content_for and yield_to methods in views.</li>
<li>Erubis compiled templates are now cached for increased performance.</li>
<li>Added render(:inline) and render(:template) support.</li>
<li>Refactored, and reorganized some files to clean up the gem.</li>
<li>Fixed bug with cookies not merging with configured app_config parameters.</li>
<li>Added mime-types. The &#8216;Content-Type&#8217; header is now being set based on the format that is requested. Default is text/html.</li>
<li>Fixed r.defaults in routes so they are always the last routes to be checked, no matter where they are placed in the routes definitions.</li>
<li>render(:url) now recognizes &#8216;local&#8217; urls and tries to run them through the app, mimicking most headers from the original request.</li>
<li>Added &#8216;options&#8217; banners to the mack and mack_ring_server binaries.</li>
<li>gem: genosaurus 1.1.8</li>
<li>gem: mack_ruby_core_extensions 0.1.28</li>
<li>gem: markaby 0.5.0</li>
<li>gem: mack-data_mapper 0.5.5</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2008/05/21/release-055/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preview (0.5.5): Adding PDF::Writer Plugin Support Tutorial</title>
		<link>http://www.metabates.com/2008/05/20/055-adding-pdfwriter-plugin-support-tutorial/</link>
		<comments>http://www.metabates.com/2008/05/20/055-adding-pdfwriter-plugin-support-tutorial/#comments</comments>
		<pubDate>Tue, 20 May 2008 20:45:27 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[engine]]></category>
		<category><![CDATA[erubis]]></category>
		<category><![CDATA[gems]]></category>
		<category><![CDATA[mack]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[render]]></category>
		<category><![CDATA[rendering]]></category>

		<guid isPermaLink="false">http://www.mackframework.com/?p=99</guid>
		<description><![CDATA[Ok, let&#8217;s take the new rendering system out for a spin, shall we? Let&#8217;s add the PDF::Writer library to our Obligatory Blog Demo application. If you haven&#8217;t followed this demo you should do that now. Let&#8217;s start by requiring the gem in our system. Open up your gems.rb file found in config/initializers and let&#8217;s add [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, let&#8217;s take the new rendering system out for a spin, shall we? Let&#8217;s add the PDF::Writer library to our Obligatory Blog Demo application. If you haven&#8217;t followed this demo you should do that <a href="http://www.mackframework.com/2008/04/18/046-the-obligatory-blog-demo-take-2/" target="_blank">now</a>.</p>
<p>Let&#8217;s start by requiring the gem in our system. Open up your gems.rb file found in config/initializers and let&#8217;s add the gem:</p>
<pre>require_gems do |gem|
  gem.add "pdf-writer", :version =&gt; "1.1.8", :libs =&gt; "pdf/writer"
end</pre>
<p>Great! We&#8217;ve told Mack we want to use the &#8216;pdf-writer&#8217; gem, version &#8217;1.1.8&#8242;, and we want to automatically require the file &#8216;pdf/writer&#8217;. Now, let&#8217;s install the gem:</p>
<pre>$ sudo rake gems:install</pre>
<p>See how easy this is? We&#8217;ve installed the gem, required the libraries, now we&#8217;re ready to write our plugin.</p>
<pre>$ rake generate:plugin name=render_pdf</pre>
<p>That should generate a few files/folders in our vendor/plugins directory. Let&#8217;s open up vendor/plugins/render_pdf/lib/render_pdf.rb and let&#8217;s start coding.</p>
<p>What we want to do is create a new Mack::Rendering::Engine::Base class so that when we call render(:action) it will have a new engine to render the view file as a PDF.</p>
<p>We&#8217;ll examine each section in a minute, but for now, let&#8217;s type this into our render_pdf.rb file:</p>
<pre>module Mack
  module Rendering
    module Engine
      class Pdf &lt; Mack::Rendering::Engine::Base

        def render(io, binding)
          @_pdf = ::PDF::Writer.new
          self.view_template.instance_variable_set("@_pdf", @_pdf)
          eval(io, binding)
          @_pdf.render
        end

        def extension
          :pdfw
        end

        module ViewHelpers
          def pdf
            @_pdf
          end
        end

      end
    end
  end
end
Mack::Rendering::ViewTemplate.send(:include, Mack::Rendering::Engine::Pdf::ViewHelpers)
Mack::Rendering::Engine::Registry.register(:action, :pdf)</pre>
<p>Ok, so on line #4 we extended Mack::Rendering::Engine::Base. This will give us access to a view methods, and will allow us to write to a very simple API. The only method you are <em>absolutely</em> required to implement is the render method. As we can see on line #6, we did just that.</p>
<p>First thing we do in the render method is instantiate a new PDF::Writer class and assign it to an instance variable. We then set that instance variable into the Mack::Rendering::ViewTemplate object we have. We do that because the way the PDF::Writer object works you need to constantly reference the instance of the writer to do your work. Example:</p>
<pre>@_pdf.text "Hello World", :font_size =&gt; 24, :justification =&gt; :center</pre>
<p>On line #9 we eval the io and the binding we&#8217;ve been given. The io will be contents of the view file we have disk, as a String, and the binding will be that of the Mack::Rendering::ViewTemplate object we&#8217;ve been given.</p>
<p>In the extension method we tell the system that are files are going to be found with the extension, pdfw. Another example of this would be the Erubis engine which declares its extension as erb.</p>
<p>The Mack::Rendering::Engine::Pdf::ViewHelpers module we&#8217;ve declared on line #17 is there to hide the @_pdf instance variable with a nicer pdf method. On line #27 we include this module into Mack::Rendering::ViewTemplate so it has access to it.</p>
<p>Finally, and most importantly, we need to register the new engine we&#8217;ve built with the system. We do that on line #28 with this bit of code:</p>
<pre>Mack::Rendering::Engine::Registry.register(:action, :pdf)</pre>
<p>That&#8217;s saying whenever someone calls render(:action), consider me as an engine to render that. The way the selection of which engine to use is done, is very simple. First come first serve. The engines are in an array, and the first one to have a file with its extension on disk wins. Plain and simple.</p>
<p>Now, let&#8217;s see all this in action. Let&#8217;s add PDF support for our &#8216;show&#8217; page.</p>
<p>Open up views/posts/show.html.erb and add the following line:</p>
<pre>&lt;%= link_to("pdf", posts_show_url(:id =&gt; @post, :format =&gt; :pdf)) %&gt;</pre>
<p>That will give us a link that looks like &#8216;/posts/:id.pdf&#8217;. This will, of course, go to our PostsController and the show action. This method does not need to be altered. That&#8217;s right, you heard me. It does not need to change. Mack will handle the appropriate content-type headers for you. Just another great feature in 0.5.5.</p>
<p>Create a file called views/posts/show.pdf.pdfw. I know this might look a little weird, what with &#8216;pdf.pdfw&#8217;, but here&#8217;s the reason why. That&#8217;s break the file name down into its three parts. &#8216;show&#8217; is the name of the action. &#8216;pdf&#8217; is the format of the request, think also html, xml, etc&#8230; &#8216;pdfw&#8217; is the engine we want to use. If we hated ourselves we could do this all in erb with a file called show.pdf.erb, but why would we want to do that?</p>
<p>Anyway, let&#8217;s dump this nice block of code into our show.pdf.pdfw file:</p>
<pre>pdf.select_font "Times-Roman"
pdf.fill_color(Color::RGB::Red)
pdf.text @post.title, :font_size =&gt; 24, :justification =&gt; :center
pdf.fill_color(Color::RGB::Black)
pdf.text "by #{@post.email}", :font_size =&gt; 12, :justification =&gt; :center
pdf.with_options(:font_size =&gt; 10, :justification =&gt; :left) do |p|
  p.text "\n\n"
  p.text @post.body
  p.text "\n\n"
  p.text "Created at: #{@post.created_at}"
  p.text "Updated at: #{@post.updated_at}"
end</pre>
<p>Since this is not a tutorial on this particular gem, I&#8217;m not going to go into what all that does. Instead, let&#8217;s just have a look at it in action.</p>
<p>Fire up your server:</p>
<pre>$ rake server</pre>
<p>And go to: http://localhost:3000. If you don&#8217;t already have a post created, create one. Now click on the show link. You should have a link on your page that says &#8216;pdf&#8217; click on that link. Voila! You should be seeing a wonderfully formatted PDF right now!</p>
<p>Congrats! You&#8217;ve built a plugin and a new rendering engine for Mack. Now, go crazy!</p>
<p>The source for all this can be found at:Â <a href="http://github.com/markbates/mack_blog_demo/tree/master" target="_blank">http://github.com/markbates/mack_blog_demo/tree/master</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2008/05/20/055-adding-pdfwriter-plugin-support-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preview (0.5.5): The New Rendering Engine</title>
		<link>http://www.metabates.com/2008/05/20/the-new-rendering-engine/</link>
		<comments>http://www.metabates.com/2008/05/20/the-new-rendering-engine/#comments</comments>
		<pubDate>Tue, 20 May 2008 20:12:32 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[erb]]></category>
		<category><![CDATA[erubis]]></category>
		<category><![CDATA[haml]]></category>
		<category><![CDATA[mack]]></category>
		<category><![CDATA[markaby]]></category>
		<category><![CDATA[rendering]]></category>

		<guid isPermaLink="false">http://www.mackframework.com/?p=97</guid>
		<description><![CDATA[In the latest version of Mack the rendering engine has been completely re-written from the ground up. With this comes some new features, some incompatibility, and most importantly,Â extensibility. Let&#8217;s jump on in and see what we can expect with this release. Incompatibility Gone is &#60;%= @content_for_layout %&#62; in layouts. In is &#60;%= yield_to :view %&#62;. [...]]]></description>
			<content:encoded><![CDATA[<p>In the latest version of Mack the rendering engine has been completely re-written from the ground up. With this comes some new features, some incompatibility, and most importantly,Â extensibility. Let&#8217;s jump on in and see what we can expect with this release.</p>
<h3>Incompatibility</h3>
<ul>
<li>Gone is &lt;%= @content_for_layout %&gt; in layouts. In is &lt;%= yield_to :view %&gt;.</li>
<li>Gone is render(options_hash) in controllers/views. In is render(type, value, options_hash)<br />
Examples:<br />
render(:action =&gt; :new) is now render(:action, :new)<br />
render(:url =&gt; &#8220;http://www.mackframework.com&#8221;, :parameters =&gt; {:message =&gt; &#8220;hi&#8221;}) is nowÂ render(:url, &#8220;http://www.mackframework.com&#8221;, :parameters =&gt; {:message =&gt; &#8220;hi&#8221;})</li>
<li>Gone is *.xml.erb. In is *.xml.builder</li>
</ul>
<div>Let&#8217;s quickly talk about how theseÂ incompatibilitiesÂ have come about. First there were several bugs that needed to be addressed with the rendering engine. For example, if you set an instance variable in a view, it wasn&#8217;t available in the layout. That&#8217;s a pain if you want to do things like programatically set the page title. There were also &#8216;hacks&#8217; used to do things like render xml using the Builder::XmlMarkup library. It wasn&#8217;t clean, but it worked. Finally, the rendering engine itself wasn&#8217;t that extensible. All of that has now changed.</div>
<div></div>
<h3>Render Me Softly</h3>
<p>In the new rendering engine there are two parts to the system, Mack::Rendering::Type::* objects and Mack::Rendering::Engine::* objects. Let me explain the difference.</p>
<h4>Mack::Rendering::Type::*</h4>
<p>A type is something like :action, :text, :inline, :url, etc&#8230; That is the type of thing you want to do. I want to render an action. I want to render a url, etc&#8230; There are classes for each of these types, and you can easily add your own. These types do all sorts of work before they pass it off to an engine, if need be. For example, in the case of Mack::Rendering::Type::Partial the render method does the work of inserting an &#8216;_&#8217; in the appropriate place, so the file can found.</p>
<pre>&lt;%= render(:partial, "users/form") %&gt; # =&gt; "users/_form"</pre>
<p>Once that happens it tries to find an engine to process the partial.</p>
<h4>Mack::Rendering::Engine::*</h4>
<p>An engine does the actual work of rendering the io, with the binding of the Mack::Rendering::ViewTemplate object, it&#8217;s been given by the results of the render method in the Mack::Rendering::Type::* object. Engine examples would be, Erubis (ERB), Markaby, Haml, and Builder::XmlMarkup, all of which are included with Mack in this release. New engines can easily be plugged in and registered with the system.</p>
<p>Coming soon a tutorial on adding PDF::Writer support using the new system.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2008/05/20/the-new-rendering-engine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Release 0.4.6</title>
		<link>http://www.metabates.com/2008/04/18/release-046/</link>
		<comments>http://www.metabates.com/2008/04/18/release-046/#comments</comments>
		<pubDate>Fri, 18 Apr 2008 21:55:04 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Releases]]></category>
		<category><![CDATA[Updates]]></category>
		<category><![CDATA[erb]]></category>
		<category><![CDATA[erubis]]></category>
		<category><![CDATA[generators]]></category>
		<category><![CDATA[mack]]></category>
		<category><![CDATA[migrations]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[scaffold]]></category>
		<category><![CDATA[thin]]></category>

		<guid isPermaLink="false">http://www.mackframework.com/?p=80</guid>
		<description><![CDATA[This is a pretty cool release. First off Thin has been updated to 0.8.0, a rather nice, stable release. ERB has been replaced with ErubisÂ to give a significant improvement in speed, which, after all is one of Mack&#8217;s most important traits.Â  There&#8217;s been a general overhaul of the generators included with Mack. Mostly, cleaning them [...]]]></description>
			<content:encoded><![CDATA[<p>This is a pretty cool release. First off Thin has been updated to 0.8.0, a rather nice, stable release. ERB has been replaced with <a href="http://www.kuwata-lab.com/erubis/" target="_blank">Erubis</a>Â to give a significant improvement in speed, which, after all is one of Mack&#8217;s most important traits.Â </p>
<p>There&#8217;s been a general overhaul of the generators included with Mack. Mostly, cleaning them up. With that said things like the scaffold, model, and migration generators have been updated to do what a lot of people have been asking for, that is take a &#8216;cols&#8217; parameter and build out the generated code corrrectly. This really makes life, very, very simple.</p>
<p>There will be a re-written &#8216;blog&#8217; tutorial coming out soon to make use of this, as well as migration support that&#8217;s now part of Mack.</p>
<p>Very exciting stuff! Enjoy!</p>
<p>Changelog:</p>
<ul>
<li>Mack now uses Erubis, http://www.kuwata-lab.com/erubis/, for it&#8217;s rendering engine instead of ERB. This makes Mack even faster now! Yippie!</li>
<li>Added rake generate:model name=&lt;model_name&gt; (optional: cols=&lt;col_1&gt;:&lt;col_1_type&gt;,&lt;col_2&gt;:&lt;col_2_type&gt;) This will also create a migration for you.</li>
<li>Updated rake generate:migration name=&lt;model_name&gt; (optional: cols=&lt;col_1&gt;:&lt;col_1_type&gt;,&lt;col_2&gt;:&lt;col_2_type&gt;) This will create the proper table migration for you.</li>
<li>Updated rake generate:scaffold to use the ModelGenerator now.</li>
<li>ScaffoldGenerator now create input fields based on the type of columns, if any, passed in.</li>
<li>Overall general refactoring of the generator classes.</li>
<li>Fixed a bug with request logging not, well, logging.</li>
<li>gem: erubis 2.5.0</li>
<li>gem: thin 0.8.0</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2008/04/18/release-046/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.350 seconds -->
