Agile Web Development with Rails, Edition 4

Agile Web Development with Rails, Edition 4

26.3 HAML 26.1 Active Merchant

26.2 Asset Packager

Minimize scripts and stylesheets

rails plugin install git://github.com/sbecker/asset_packager.git

cp -rpv /home/rubys/git/awdwr/edition4/data/plugins/asset_packager vendor/plugins/
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager' -> `vendor/plugins/asset_packager'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/install.rb' -> `vendor/plugins/asset_packager/install.rb'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/test' -> `vendor/plugins/asset_packager/test'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/test/asset_packages.yml' -> `vendor/plugins/asset_packager/test/asset_packages.yml'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/test/asset_package_helper_development_test.rb' -> `vendor/plugins/asset_packager/test/asset_package_helper_development_test.rb'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/test/assets' -> `vendor/plugins/asset_packager/test/assets'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/test/assets/javascripts' -> `vendor/plugins/asset_packager/test/assets/javascripts'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/test/assets/javascripts/foo.js' -> `vendor/plugins/asset_packager/test/assets/javascripts/foo.js'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/test/assets/javascripts/dragdrop.js' -> `vendor/plugins/asset_packager/test/assets/javascripts/dragdrop.js'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/test/assets/javascripts/effects.js' -> `vendor/plugins/asset_packager/test/assets/javascripts/effects.js'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/test/assets/javascripts/application.js' -> `vendor/plugins/asset_packager/test/assets/javascripts/application.js'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/test/assets/javascripts/controls.js' -> `vendor/plugins/asset_packager/test/assets/javascripts/controls.js'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/test/assets/javascripts/prototype.js' -> `vendor/plugins/asset_packager/test/assets/javascripts/prototype.js'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/test/assets/javascripts/bar.js' -> `vendor/plugins/asset_packager/test/assets/javascripts/bar.js'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/test/assets/stylesheets' -> `vendor/plugins/asset_packager/test/assets/stylesheets'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/test/assets/stylesheets/screen.css' -> `vendor/plugins/asset_packager/test/assets/stylesheets/screen.css'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/test/assets/stylesheets/header.css' -> `vendor/plugins/asset_packager/test/assets/stylesheets/header.css'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/test/assets/stylesheets/bar.css' -> `vendor/plugins/asset_packager/test/assets/stylesheets/bar.css'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/test/assets/stylesheets/subdir' -> `vendor/plugins/asset_packager/test/assets/stylesheets/subdir'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/test/assets/stylesheets/subdir/bar.css' -> `vendor/plugins/asset_packager/test/assets/stylesheets/subdir/bar.css'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/test/assets/stylesheets/subdir/foo.css' -> `vendor/plugins/asset_packager/test/assets/stylesheets/subdir/foo.css'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/test/assets/stylesheets/foo.css' -> `vendor/plugins/asset_packager/test/assets/stylesheets/foo.css'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/test/asset_package_helper_production_test.rb' -> `vendor/plugins/asset_packager/test/asset_package_helper_production_test.rb'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/test/asset_packager_test.rb' -> `vendor/plugins/asset_packager/test/asset_packager_test.rb'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/init.rb' -> `vendor/plugins/asset_packager/init.rb'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/Rakefile' -> `vendor/plugins/asset_packager/Rakefile'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/CHANGELOG' -> `vendor/plugins/asset_packager/CHANGELOG'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/lib' -> `vendor/plugins/asset_packager/lib'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/lib/synthesis' -> `vendor/plugins/asset_packager/lib/synthesis'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/lib/synthesis/asset_package.rb' -> `vendor/plugins/asset_packager/lib/synthesis/asset_package.rb'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/lib/synthesis/asset_package_helper.rb' -> `vendor/plugins/asset_packager/lib/synthesis/asset_package_helper.rb'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/lib/jsmin.rb' -> `vendor/plugins/asset_packager/lib/jsmin.rb'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/lib/tasks' -> `vendor/plugins/asset_packager/lib/tasks'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/lib/tasks/asset_packager_tasks.rake' -> `vendor/plugins/asset_packager/lib/tasks/asset_packager_tasks.rake'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/README' -> `vendor/plugins/asset_packager/README'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/about.yml' -> `vendor/plugins/asset_packager/about.yml'

list the new tasks introduced

rake -T asset
rake asset:packager:build_all   # Merge and compress assets
rake asset:packager:create_yml  # Generate asset_packages.yml from existing assets
rake asset:packager:delete_all  # Delete all asset builds

inventory existing assets

rake asset:packager:create_yml
config/asset_packages.yml example file created!
Please reorder files under 'base' so dependencies are loaded in correct order.

Look at the file that was produced

cat config/asset_packages.yml
---
javascripts:
- base:
  - prototype
  - controls
  - rails
  - application
  - effects
  - dragdrop
stylesheets:
- base:
  - scaffold
  - depot

produce a minimized version

rake asset:packager:build_all
Created /home/rubys/git/awdwr/edition4/work-193-30/depot/public/javascripts/base_packaged.js
Created /home/rubys/git/awdwr/edition4/work-193-30/depot/public/stylesheets/base_packaged.css
edit app/views/layouts/application.html.erb
<!DOCTYPE html>
<html>
<head>
  <title>Pragprog Books Online Store</title>
  <%= raw stylesheet_link_merged :base %>
  <%= raw javascript_include_merged :base %>
  <%= csrf_meta_tag %>
</head>
<!-- ... -->

26.3 HAML 26.1 Active Merchant