Mack 0.6.1.1 features 38 completed tickets and a whole host of really great features and improvements. Here’s a quick overview of a few of the big features in Mack 0.6.1.1.
Page Caching
There is now a mack-caching gem which gives you easy to use page caching when you require it. To use page caching first you need to add it to your gems.rb file like such:
gem.add "mack-caching", :libs => "mack-caching"
That will require the gem and give your app access to the page caching libraries. Next you to turn on page caching in your application. In the appropriate config/*.yml file add the following:
use_page_caching: true
Now, you just need to tell your controllers which actions they should cache:
class FooController
include Mack::Controller
cache_pages
nly => [:index, :show]
end
If you give the cache_pages no optional parameters then it will cache all the actions for that controller. Alternatively, you could give it an :except parameter to list the actions you don’t want cached.
Notifiers (aka Mailers)
Mack now has a mack-notifier gem that will be the repository for all ‘notification’ systems, the first of which is email. The Mack::Notifier API is simple and easy to use and will allow developers to plugin in different notification systems under the cover without having to change their application code.
A notifier can look as simple as:
class WelcomeEmail
include Mack::Notifier
end
With that you can then write the following bit of code:
we = WelcomeEmail.new
we.to = "foo@example.com"
we.from = "bar@example.com"
we.subject = "Hello World"
we.body(:text) = "My plain text body"
we.body(:html) = "My html body"
we.attach(Mack::Notifier::Attachment.new("/path/to/my/file"))
we.deliver
Obviously there’s a lot more to the API, including a validations module, but that’s a subject for another post.
JavaScript (aka RJS)
The mack-javascript gem now gives you Rails-like RJS support for Mack. The default library to use with mack-javascript is jQuery, but there is prototype support available as well.
Data Factory
Creating faux data for testing can be a real nightmare. Fixtures can be difficult to maintain and trying to create your own faux data can be a chore. That’s where the mack-data_factory gem comes in.
For each model that you want to produce, you will need to define a factory class.
Let’s say that I have 2 models: Item and User, and Item belongs to user. So the factories will look like the following:
class ItemFactory
include Mack::Data::Factory
field :title, "MyItem"
field
wner_id, {:user => 'id'}
end
class UserFactory
include Mack::Data::Factory
field :username, "planters", :length => 25, :content => :alpha
field :password, "roastedPeanuts", :immutable => true
end
So, the 2 classes above defined the factory for item and user. As you can see, each factory will need to explicitly list all the fields that it will populate, and for each field, you can define rules on how the content is generated.
Supported content types:
- :alpha –> alphabets. rules: [:length, :min_length, :max_length]
- :alphanumeric –> alphabets and number. rules: same as :alpha
- :numeric –> numbers [optional, because if the field's default value is number, its content type will automatically set to numeric)
- :email --> generate random email address
- :username --> generate random username
- :domain --> generate random domain name
- :firstname --> generate first name
- :lastname --> generate last name
- :name --> generate full name
- :city --> generate city name
- :streetname --> generate street name
- :state --> generate state. rules: [:country --> :us or :uk, :abbr --> true if you want a abbreviated state name (us only)]
- :zipcode –> generate zipcode. rules: [:country --> :us or :uk]
- :phone –> generate phone number
- :company –> generate company name. rules: [:include_bs --> include sales tag line]
example: field, “”, :content => :company, :include_bs => true could generate something like:
Fadel-Larkin monetize cross-media experiences
There’s a lot more to the mack-data_factory gem, so I highly recommend you check it out.
Changelog:
- [#60] Fixed Mack executable problem
- [#59] Fixed gems:* tasks
- [#57] Moved most files under to lib/mack
- [#56] mack-more: Added Mack::Utils::RegistryMap
- [#55] mack-more: mack-facets: Mack::Utils::Registry is now Mack::Utils::RegistryList
- [#54] Added DataMapper 0.9.3 support
- [#52] mack-more: mack-[orm] should require mack-[orm].rb using its full path.
- [#51] Application generator should generate orm support in the right place
- [#50] Mack will now have 2 environment files: mack_core and mack_app. Mack.rb will load both files, but it gives other module chance to load just the core files and not the application’s files.
- [#49] Making sure the orm tasks is available when orm_support is removed from the app_config
- [#49] mack-active_record: mack-active_record.rb will require mack-active_record_tasks.rb
- [#49] mack-data_mapper: mack-data_mapper.rb will require mack-data_mapper_tasks.rb
- [#49] Updated warning message if orm is defined in app_config (i.e. user only needs to require mack-[orm_name], instead of both that and mack-[orm_name]_tasks).
- [#48] rake generator:list now displays the correct names for the generator tasks.
- [#47] rake gems:* tasks now work, and no longer require mack_ruby_core_extensions
- [#46] Calling .to_param on nil now raises a NoMethodError exception.
- [#45] rake stats task now works with Test::Unit::TestCase
- [#44] Mack::Runner has now been extended to allow for greater extension flexibility.
- [#43] Added a Mack::Utils::Registry class to allow for easy creation of registries.
- [#42] Sessions can now be turned off globally using the app_config.mack.use_sessions switch.
- [#41] Deprecate orm_support.rb
- [#38] There is now a registry of Controllers that are in the system.
- [#36] Renamed the initialize method in the Mack::Controller module to configure_controller. This gives
- control of the initialize method back to the class.
- [#34] Mack::l10n now raises exception with a fully qualified name.
- [#33] mack-active_record now requires ActiveRecord 2.0.2 explicitly, not >=2.0.2
- [#31] Added support for ruby-debug.
- [#26] Log Coloring for console output.
- [#24] Added mack-notifier support.
- [#18] Added Page caching.
- [#14] Data Factory
- [#7] Added support for Extlib::Hook in a few places.
- [#6] RJS support
- Added a rake tmp:clear task.
- gem: application_configuration 1.5.1
- gem: ruby-debug 0.10.0
- gem: data_mapper 0.9.3