Posts Tagged ‘routes’

Release 0.8.1

Sunday, October 26th, 2008

I know with each release I say how excited I am by this release, but that’s usually because with each release there’s some great new feature that makes me either proud to have developed it, or to proud to be associated with it. Mack 0.8.1 is definitely no exception.

Before I get into what has to be my favorite feature since the distributed features of 0.7.0, and quite possibly my favorite feature in Mack today, let’s talk about a few of the other features in this release.

More Routing Enhancements

There are a few great new features in the routing system in this release. The first off is a real crowd favorite, Nested Resources. Just like Rails you can now nest resources in Mack.

http://www.mackery.com/routing/nested_resources

In Mack 0.8.0 we introduced the ability to put host information in the routes file. This would be used to match the host when matching a route as well as building the url for that route when using the url helpers. This made dealing with subdomains very easier. Well, to really give everyone that subdomain fu everybody loves, we’ve added the ability to put embedded parameters in the host parameter in routes. It’s pretty dang cool, let me tell you. Checkout these examples:

http://www.mackery.com/routing/misc

Pagination API

There is now a pagination API that’s part of the mack-orm API. The first implementation of this in the mack-data_mapper package. At its heart it’s extremely easily to implement for new ORMs, one method, and using it is just as easy. There will be a write up on using the API in the forth coming days.

Jabber Support

The mack-notifier package can now send notifications using the Jabber protocol.

!!Portlets!!

Portlets are what components in Rails should’ve been and they’re what slices in Merb should be. Portlets are a way off packaging a full Mack application into a Ruby Gem so they can easily be shared and used in other Mack applications. As you’re about to see, this simple page is all the information you need to know about developing, testing, packaging, and using Portlets.

Portlets encapsulate a whole Mack application, from controllers to views to models to configuration settings to your images, stylesheets and javascripts. This makes it possible to develop extremely rich applications and share them with other Mack applications.

http://www.mackery.com/portlets/developing
http://www.mackery.com/portlets/testing
http://www.mackery.com/portlets/packaging
http://www.mackery.com/portlets/using

Bug Fixes and Minor Feature Updates

As always there are great bug fixes and feature updates. Below is the changelog that outlines those improvements.

Changelog:

  • [#217] Fixed rake mack:dump:routes throws errors
  • [#216] Added ability to turn off view caching in distributed app
  • [#215] Asset path lookup flow update
  • [#213] Fixed the params method should be case insensitive
  • [#211] Added a pagination API to mack-data_mapper
  • [#210] Added a pagination API to mack-orm
  • [#209] inline form built by link_to should include authenticity token
  • [#208] Added support for DataMapper repository context per request
  • [#207] Fixed session cookie not being deleted properly
  • [#206] Portlet now have access to its base_path
  • [#205] Fixed testing of nested parameters and file uploads breaks
  • [#204] Resource routes can now take options when being defined.
  • [#203] Updated distributed: view_cache to include Mack::ViewHelpers instead of Mack::ViewHelpers::LinkHelpers
  • [#200] INCOMPATIBILITY NOTICE: mack-notifier configatron namespaces have changed from *_settings to * (e.g. smtp_settings to smtp)
  • [#198] Added Embedded parameters in ‘host’ for Routes
  • [#196] Extlib 0.9.8 support
  • [#195] DataMapper 0.9.6 support
  • [#193] Portlet Support
  • [#192] mack-localization now supports portlet
  • [#191] Asset-Packager support for Portlet
  • [#143] Nested resources in Routes
  • [#134] Form elements are now ‘errorfied’.
  • [#131] Date/Time select boxes can now be easily re-arranged.
  • [#78] Jabber support
  • gem: configatron 2.1.5
  • gem: extlib 0.9.8

Release 0.8.0

Monday, October 6th, 2008

Here it is the 0.8.0 release of Mack! What a fun and exciting release it is as well. There are a few big changes under the hood, all for the better of course, but there’s only really one that will cause existing Mack projects some conversion pain. However, we’ve tried to take the sting out of that with a helpful rake task.

Configatron Support

Mack 0.8.0 replaces the old application_configuration system with the new ultra sexy and cool, Configatron system. This is a much better way of doing system configurations, and I’m sure you’ll agree once you give it a spin. We’ve tried to take the edge off the conversion of these configuration systems with a helpful little rake task:

$ rake mack:update:configuration

For most cases, that task should do just fine. There might be a few places you have to tweak, such as in your own code, but once you do that, you’ll love Configatron!

For more information about using Configatron checkout this page:

http://www.mackery.com/configuration/configatron

A New Router

That’s right, the router in Mack has been completely rewritten from the ground up, yet unlike other frameworks, we’ve managed to keep our external API the same, so you don’t have to change your routes.rb at all. :) That’s a bit of good news, isn’t it?

What do you get with the new router? Well, for one, it should be faster, that’s always a plus. You can also now do ‘wildcard’ parameters in routes, use procs, extended ‘resourced’ routes, define ‘host’ and ‘scheme’ parameters, use regular expressions, and a few other little nifty things. Plus, because of the rewrite, it’s going to make it easier to extending the routing system to be even more powerful! In a future release, sometime in the 0.8.x series, you’ll even be able to plugin in your own router just by implementing a few API methods.

For more information about the new router, and what you can do, check out:

http://www.mackery.com/routing/index

Asset Management

There is now a really great asset management system that easily allows you to build bundles of CSS and JavaScript files to help keep your code neat and easy to use. Bundle that with the new mack-asset_packager gem, and support for asset hosts, you get a simple, easy, and fast way to compress and deliver your assets. 

For more information, checkout these helpful pages from the user guide:

http://www.mackery.com/views/asset_mgr
http://www.mackery.com/views/asset_host 

Misc.

As always, there’s a bunch of other great stuff just lurking around in this release. A better logger, for a start, more helpers, bug fixes, better error reporting, default 404 and 500 pages, and more. Please download and enjoy the release, I’m sure you’ll find worth it. Enjoy!

Changelog:

  1. [#187] Fixed: When an exception is raised, the request doesn’t get ‘logged’
  2. [#185] Fixed: .html is being appended to logged requests when there’s a 404
  3. [#184] Request logging should also print the message of the status code
  4. [#183] Updates to asset mgr/host
  5. [#181] Content-type can now be set with calling render.
  6. [#179] When configatron.mack.show_exceptions is false you now either the public/404.html or public/500.html file.
  7. [#178] Added a configure parameter to turn off log coloring
  8. [#176] Added a Google Analytics helper.
  9. [#175] Generating urls should use host or scheme if defined
  10. [#171] Ability to extend resources in routes
  11. [#170] Regex support in routes
  12. [#169] Proc support for Routes
  13. [#168] Fixed ERB errors not being reported correctly.
  14. [#167] Rake task to convert app config yamls to configatron
  15. [#165] Asset Packager
  16. [#164] Response helper for ‘attachments’
  17. [#159] Added link_unless_current and link_if helpers
  18. [#156] Added ‘Wildcard’ Routes support
  19. [#152] INCOMPATIBILITY NOTICE: Removed deprecated support for delivered_emails use delivered_notifiers instead.
  20. [#138] Added support for ‘host’ & ‘scheme’ parameters in routes
  21. [#135] Replaced log4r with logging gem.
  22. [#119] Freeze gems
  23. [#106] INCOMPATIBILITY NOTICE: Removed deprecated support for droute_url
  24. [#93] INCOMPATIBILITY NOTICE: Removed deprecated support for ‘top’ level ApplicationHelper
  25. [#23] INCOMPATIBILITY NOTICE: Removed support for application_configuration and added support for configatron
  26. gem: logging 0.9.4
  27. gem: thin 1.0.0
  28. gem: rspec 1.1.8
  29. gem: configatron 2.1.4
  30. gem: cachetastic 2.0.0

(0.6.0) 4 Little Known Mack Features

Wednesday, July 23rd, 2008

I thought it might be fun to start posting about some of the little known features in Mack. There are a treasure trove of them in there, so let’s pick a couple and start there.

render(:url)

This is a great little feature, one of my personal favorites. In your views you can do things like this:

<%= render(:url, "http://www.mackframework.com) %>

that will render the contents of http://www.mackframework.com into your view. You can also do ‘local’ urls.

<%= render(:url, "/users/1") %>

will make an internal request to your application and render the results of “/users/1″ into your view. The optional 3rd parameter to render allows you to do things like set the HTTP method:

<%= render(:url, "/users/1", :method => :post) %>

or add parameters you want to pass to the URL you want to render: 

<%= render(:url, "/users/1", :method => :post, :parameters => {:id => 1}) %>

Error handling in routes

Routing allows you to define controllers/actions you want to catch and handle exceptions that happen in other controllers. Let’s look at the following routes.rb file:

Mack::Routes.build do |r|
  r.resource :users
  r.home_page "/", :controller => :default, :action => :index
  r.handle_errors ArgumentError, :controller => :problems, :action => :arguments
  r.handle_errors DataMapper::ObjectNotFoundError, :controller => :problems, :action => :not_found
  r.defaults
end

What’s going on with r.handle_errors you ask? Well, first we tell the routing system which error we want to capture in our controllers, DataMapper::ObjectNotFoundError, then we tell it which controller and which action we want to handle that error.

When an exception is thrown during a request Mack checks to see if that exception has been registered, if it has been then the request gets forwarded to the defined controller and action for handling. So in the above example if a DataMapper::ObjectNotFoundError is raised, the request will be forwarded to the ProblemsController, not_found action.

One of the really nice things about this is that you have access to the original request, so you can’t get the page the person was trying to access, any parameters that were passed, etc… You also have access the exception itself with the caught_exception method.

Server-side redirects

Let’s be honest, redirects are the most exciting topic, and this is the first of two sections on it! I’ll try to be brief. When dealing with redirects it can sometimes be helpful to do a server-side redirect. The difference, for those who don’t know, between a server-side redirect and a regular redirect is the following. With a regular redirect the response is sent back down to the client’s browser, which then issues another response back to the server for the new url that was specified in the previous response. You’ll often hear this referred to as a client-side redirect. A server-side redirect sends you to a different url on the server, without first sending down a response to the client. Because of this the client only gets one response.

To do a server-side redirect in Mack is very easy. Here’s what a client side redirect in an action would look like:

redirect_to(users_index_url)

To make that a server-side redirect you would simply pass an extra option to the redirect_to method:

redirect_to(users_index_url, :server_side => true)

Redirects in routes

This is a cool little feature. Let’s say that you have changed a few urls around. You want a quick way to redirect people who have bookmarked the old urls to the new urls. You could have a controller that did nothing but that, but that seems like a lot of extra work, and it’s really something that your routing system should be doing for you anyway. Enter redirects in routes.

Mack::Routes.build do |r|
  r.old_foo "/my_old_foo", :redirect_to => "/my_new_foo", :status => 301
end

From now on anything comes in to “/my_old_foo” will be redirected to “/my_new_foo” with a status of 301.

Release 0.4.5

Monday, April 14th, 2008

Well, here it is! The release you all were waiting for, the one that finally gives migration support to Mack! That’s right, now whether you use ActiveRecord or DataMapper, you can use the familiar rake task ‘db:migrate’ to run your migrations. Yippie! The scaffold generator will also generate a migration for you, assuming you have ORM support enabled.

There’s still some work to go on this, like the ability to pass in command line args to the task to build the full migration for you, but it’s a start! It’s now pretty easy to get your app going.

Also in this release is a rewrite of the distributed routing functionality. It’s now been rewritten to use Rinda. This is going to be the standard for all the distributed functionality that will be coming Mack over the next couple of months. As more functionality lke this is developed, the more it will be wrapped in nice, easy to use APIs.

There’s also been some tidying up here in there in the code tree. For example, new applications don’t get generated with a boot.rb file. Looking at it, there’s really no need for it, since everything is done with Rake tasks.

Overall, I’m very happy with the release, and I feel that this release definitely makes Mack a VERY useable framework because of the migration support. Enjoy!

Changelog:

  • Removed boot.rb file. It was unnecessary.
  • When a new Mack application is generated the Rakefile that gets generated is stamped with the Mack gem version used to create it. This ties the project to that gem. This can, of course, be upgraded as new Mack gems come out, but it’s a good way of tying your app to a specific revision of Mack.
  • Added support for migrations for both ActiveRecord and DataMapper. DataMapper migration support requires DataMapper 0.3.0 gem. Please keep in mind, though, that DataMapper 0.3.0 has a serious bug in it, which may prevent you from using it. Please see http://www.mackframework.com/2008/04/09/horrible-bug-in-datamapper-030/ for more information.
  • Rewrote distributed routing support to use Rinda inside of plain old DRb. This makes for an almost zero configuration usage.
  • Added: mack_ring_server binary to start a Rinda ring server for use with distributed routing.
  • Sqlite3 is now the default database for Mack applications configured with ORM support.
  • Added a test helper method, rake_task, to aid in the testing of Rake tasks.
  • Added: rake generate:migration name=<migration_name>
  • Added: rake db:migrate
  • Added: rake db:abort_if_pending_migrations
  • Added: rake db:rollback
  • Added: rake db:version
  • Added: rake mack:ring_server:start
  • Added: rake mack:ring_server:stop
  • Added: rake mack:ring_server:restart
  • Added: rake mack:ring_server:services:list
  • gem: application_configuration 1.2.2
  • gem: daemons 1.0.10

    Release 0.4.0

    Wednesday, March 26th, 2008

    It’s finally here! The release you’ve all been waiting for, 0.4.0!! What’s new in this one? Well, the big one, DISTRIBUTED ROUTING!!! Now you can share your routes between all of your Mack applications.

    I’m very excited about this release. This is one of the first features that starts to set Mack apart from other Ruby frameworks such as Rails and Merb.  Mack is trying to set itself as the framework for doing multiple, distributed, portal applications. This release gets us headed in that direction.

    There will be a tutorial post and app in the next few days. In the meantime I highly encourage you to download this release and check it out.

    Changelog:

    • Added Distributed Routes!
    • gem: mack_ruby_core_extensions 0.1.3
    • removed gem: ruby_extensions
    $ sudo gem install mack