1. Welcome
  2. Getting Started [+/-]
    1. Installing from RubyGems
    2. Installing from GitHub.com
    3. Installing with Sake
  3. The Basics [+/-]
    1. Hello World
      1. Application Generation Options
    2. Paths
    3. Environments
    4. Rake
  4. Configuration [+/-]
    1. Configatron
    2. Initializers
      1. Gems
      2. Mime-Types
  5. Routing [+/-]
    1. Default Routes
    2. Named Routes
    3. RESTful/Resource Routes
    4. Nested Resource Routes
    5. Regex Routes
    6. Wildcard Routes
    7. Blocks in Routes
    8. Redirecting
    9. Error Handling
    10. Deferred? Routes
    11. Misc. Routing
  6. Controllers [+/-]
    1. Actions
    2. Headers/Status
    3. Handling Content Types
    4. Filters
    5. Helpers
    6. Layouts
    7. Tell Messaging
    8. Redirecting
    9. Rendering
      1. Engines
        1. Erubis
        2. XML Builder
        3. Extending
          1. Case Study: PDF Writer
      2. Types
        1. :action
        2. :text
        3. :inline
        4. :xml
        5. :url
        6. :partial
        7. :template
        8. :public
        9. Extending
          1. Case Study: PDF Writer
  7. Views [+/-]
    1. Helpers
    2. Layouts
    3. Assets Host
    4. Assets Management
    5. Form Builders
  8. Sessions [+/-]
    1. Session Store API
  9. Request/Response [+/-]
    1. Cookies
  10. Testing [+/-]
    1. RSpec
    2. Test::Unit::TestCase
  11. Porlets [+/-]
    1. Developing
    2. Testing
    3. Packaging
    4. Using
  12. Plugins [+/-]
    1. Extending
      1. Case Study: PDF Writer
  13. Deploying [+/-]
    1. Thin
    2. Passenger (mod_rails)
    3. Joyent Accelerator
  14. Mack More [+/-]
    1. mack-active_record
    2. mack-asset_packager
    3. mack-caching
    4. mack-data_factory
    5. mack-data_mapper
    6. mack-distributed
    7. mack-encryption
    8. mack-facets
    9. mack-haml
    10. mack-javascript
    11. mack-localization
    12. mack-markaby
    13. mack-notifier
    14. mack-orm
    15. mack-pdf_writer
  15. Rails to Mack Cheat Sheet
  16. Contributing
  17. APIs [+/-]

Asset Manager

The Asset Manager module of a mack application allows developers to define a group of asset files (e.g. javascript and/or stylesheet files), and then refer to them using the bundle instead of listing them individually.

When the application is loaded, there's a global reference to the asset manager instance (asset_mgr) that you can use to: create new bundle, access existing bundle, or query all the defined bundles.

If you are to create asset bundles, it is recommended that you create a file (e.g. assets.rb) in config/initializers folder. This way, when the application is loaded, the file will be required, which in turns will define all the bundles you need.

The ability to bundle up asset files will not only make the erb file simpler, but it will also open up the opportunity to package and compress asset files before returning the response to the client. The packaging and compression will not be discuss in this document, but will be discussed in full detail in the 'mack-asset_packager' section.

The following are examples on how to use the asset manager:

    # each mack application comes with a bundle called defaults
    # and if you add stuff to this bundle, it will just append
    # to the existing list.
    assets_mgr.defaults do |a|

      # this block basically says, go to the asset_mgr, ask for 
      # defaults bundle, and to that bundle, add a new javascript file
      # called foo(.js)
      a.add_js "foo"
    end

    assets_mgr.my_bundle do |a|
      # this block is saying: I want to access a bundle called my_bundle,
      # if it doesn't exist create it, and then add 1 javascript file (foo) and
      # 1 css file to the bundle
      a.add_js "foo"
      a.add_css "bar"
    end
How to use the created bundle? In the layout file where you define the stylesheet or javascript tag, you will just refer to the bundle name instead of the individual files. NOTE: you will have to use the stylesheet and javascript methods to generate the tags in order to take advantage of the asset bundle.
    ...
    <%= stylesheet 'my_bundle' %>
    <%= javascript 'my_bundle' %>
    ...
It's nice that we can use the bundle, but can we mix regular asset file along with the bundle name when using the stylesheet/javascript methods? The answer is yes, and basically when the framework is about to generate the tag, it will try to resolve the bundle name, and if the listed name is not a defined bundle, then it will just treat it as regular asset file.
For example: let's say we have the my_bundle bundle, and 2 css files: style1.css and style2.css. To add those three components, we will do the following:
    ...
    <%= stylesheet ['my_bundle', 'style1', 'style2.css']%>
    ...
The above code will generate 3 stylesheet tags (2 from the explicit css, and 1 from the bundle since the bundle only contain 1 css file)

This guide was written for Mack version 0.8.2