Last Update: 2015-03-13 11:14:26 -0700

New Plugins

  • A view_options plugin has been added, for branch/route specific setting of view and layout options and locals. This allows for DRYer code when you want to change the view or layout settings for an entire routing branch. Options and locals set at the branch or route level have higher priority than those set at the plugin level, but lower priority than those provided as arguments to the render/view methods. Example:

    class App < Roda
      plugin :view_options
      route do |r|
        r.on 'albums' do
          layout_options :template=>'layouts/3_columns'
          layout_locals :heading=>'Albums'
          view_options :ext=>'haml'
          view_locals :name=>'Foo'
          # ...

    The view_options plugin is also a superset of the previous view_subdirs plugin, and attempts to load view_subdirs will now load view_options. In addition to set_view_subdir, the view_options plugin now supports append_view_subdir, which will append a subdirectory to an existing subdirectory, which makes it simpler to deal with nested view file hierarchies.

  • A static plugin has been added for easily serving static files using Rack::Static. Example:

    class App < Roda
      plugin :static, ['/js', '/css']
      # or:
      plugin :static, ['/js', '/css'], :root=>'pub'

Other New Features

  • Roda now supports a :root option for the application that sets the root directory. This is useful if the application’s files are not stored in the process’s working directory, which is common for processes containing of multiple Roda applications.

    By setting the :root option, plugins that use the file system will default to making relative paths relative to the :root option instead of the process’s working directory. The assets, render, and static plugins currently support the :root option. Example:

    class App < Roda
      opts[:root] = File.dirname(__FILE__)
  • Roda now supports an :add_script_name option for the application, which makes plugins automatically prepend the SCRIPT_NAME for the request’s environment to any paths created. This allows Roda applications to work transparently whenever they are mounted inside of another rack application.

    The assets and path plugins currently recognize the :add_script_name option. Example:

    class App < Roda
      opts[:add_script_name] = true
  • The path plugin now adds a Roda#path method, which creates paths based on the type of argument used. You can register classes with the path plugin by providing Roda.path with a class, which will cause Roda#path to recognize them and handle them accordingly.


    class App < Roda
      plugin :path
      path(Track){|track| "/albums/#{track.album_id}/tracks/#{track.number}"}
      route do
        r.get 'tracks/:id' do |track_id|

Other Improvements

  • add_file in the mailer plugin now adds the files after the email body instead of before. This fixes some issues where the email body would end up empty, due to issues with the mail gem’s API.

    add_file now accepts a block, and the block is called after the file has been attached. Among other things, this allows you to change the content_type for an attached file:

    add_file 'path/to/file' do
      response.mail.attachments.last.content_type = 'text/foo'
  • r.multi_route in the multi_route plugin now works if there are no named routes defined.

  • A render plugin :locals option is now respected, setting defaults to use for locals in views. Additionally, a :locals option in the :layout_opts option is now respected for setting locals in layouts. If both the render plugin option is set and :locals is passed to render/view, the two will be merged together. Previously, providing a :locals option to render/view would cause the plugin level option to be ignored.

Backwards Compatibility

  • Using the render plugin :layout=>nil option now removes any layout template set previously using :layout. Previously, the layout template would still be kept, but it would not be used by default.

  • Accessing attachments after adding a file using add_file in the mailer plugin no longer works, as the adding is now delayed until after the body is set. You should now pass a block to add_file if you want to access the attachment after it has been added.