Fork me on GitHub

Posts Tagged ‘haml’

Release 0.5.5

Wednesday, May 21st, 2008

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’s a great release.

To find out more about the new rendering engine check out these two posts:

http://www.mackframework.com/2008/05/20/the-new-rendering-engine/

http://www.mackframework.com/2008/05/20/055-adding-pdfwriter-plugin-support-tutorial/

Changelog:

  • INCOMPATIBILITY NOTICE: Ripped apart the ENTIRE rendering engine and rewrote it from the ground up. This means that wherever you are using ‘render’ calls in your views and controllers need to be changed. The new format is render(type, value, options). Examples: render(:action, :show), render(:url, “http://www.mackframework.com”), etc…
  • 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.
  • INCOMPATIBILITY NOTICE: <%= @content_for_layout %> is now <%= yield_to :view %>
  • Added Markaby support.
  • Added Haml support.
  • Added content_for and yield_to methods in views.
  • Erubis compiled templates are now cached for increased performance.
  • Added render(:inline) and render(:template) support.
  • Refactored, and reorganized some files to clean up the gem.
  • Fixed bug with cookies not merging with configured app_config parameters.
  • Added mime-types. The ‘Content-Type’ header is now being set based on the format that is requested. Default is text/html.
  • 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.
  • render(:url) now recognizes ‘local’ urls and tries to run them through the app, mimicking most headers from the original request.
  • Added ‘options’ banners to the mack and mack_ring_server binaries.
  • gem: genosaurus 1.1.8
  • gem: mack_ruby_core_extensions 0.1.28
  • gem: markaby 0.5.0
  • gem: mack-data_mapper 0.5.5

Preview (0.5.5): The New Rendering Engine

Tuesday, May 20th, 2008

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’s jump on in and see what we can expect with this release.

Incompatibility

  • Gone is <%= @content_for_layout %> in layouts. In is <%= yield_to :view %>.
  • Gone is render(options_hash) in controllers/views. In is render(type, value, options_hash)
    Examples:
    render(:action => :new) is now render(:action, :new)
    render(:url => “http://www.mackframework.com”, :parameters => {:message => “hi”}) is now render(:url, “http://www.mackframework.com”, :parameters => {:message => “hi”})
  • Gone is *.xml.erb. In is *.xml.builder
Let’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’t available in the layout. That’s a pain if you want to do things like programatically set the page title. There were also ‘hacks’ used to do things like render xml using the Builder::XmlMarkup library. It wasn’t clean, but it worked. Finally, the rendering engine itself wasn’t that extensible. All of that has now changed.

Render Me Softly

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.

Mack::Rendering::Type::*

A type is something like :action, :text, :inline, :url, etc… That is the type of thing you want to do. I want to render an action. I want to render a url, etc… 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 ‘_’ in the appropriate place, so the file can found.

<%= render(:partial, "users/form") %> # => "users/_form"

Once that happens it tries to find an engine to process the partial.

Mack::Rendering::Engine::*

An engine does the actual work of rendering the io, with the binding of the Mack::Rendering::ViewTemplate object, it’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.

Coming soon a tutorial on adding PDF::Writer support using the new system.