Agile Web Development with Rails, Edition 4

26.1.4 JQuery 26.1 Active Merchant

26.1.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/Rakefile' -> `vendor/plugins/asset_packager/Rakefile'
`/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_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_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/asset_packager_test.rb' -> `vendor/plugins/asset_packager/test/asset_packager_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/application.js' -> `vendor/plugins/asset_packager/test/assets/javascripts/application.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/controls.js' -> `vendor/plugins/asset_packager/test/assets/javascripts/controls.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/bar.js' -> `vendor/plugins/asset_packager/test/assets/javascripts/bar.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/stylesheets' -> `vendor/plugins/asset_packager/test/assets/stylesheets'
`/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/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/header.css' -> `vendor/plugins/asset_packager/test/assets/stylesheets/header.css'
`/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/subdir' -> `vendor/plugins/asset_packager/test/assets/stylesheets/subdir'
`/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/subdir/bar.css' -> `vendor/plugins/asset_packager/test/assets/stylesheets/subdir/bar.css'
`/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/init.rb' -> `vendor/plugins/asset_packager/init.rb'
`/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/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/lib/jsmin.rb' -> `vendor/plugins/asset_packager/lib/jsmin.rb'
`/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/README' -> `vendor/plugins/asset_packager/README'
`/home/rubys/git/awdwr/edition4/data/plugins/asset_packager/about.yml' -> `vendor/plugins/asset_packager/about.yml'
`/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/CHANGELOG' -> `vendor/plugins/asset_packager/CHANGELOG'

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
--- 
stylesheets: 
- base: 
  - depot
  - scaffold
javascripts: 
- base: 
  - prototype
  - dragdrop
  - rails
  - controls
  - effects
  - application

produce a minimized version

rake asset:packager:build_all
Created /home/rubys/git/awdwr/edition4/work-187-30/depot/public/javascripts/base_packaged.js
Created /home/rubys/git/awdwr/edition4/work-187-30/depot/public/stylesheets/base_packaged.css
edit app/views/layouts/application.html.erb
#<IndexError: regexp not matched>
  /home/rubys/git/gorp/lib/gorp/edit.rb:150:in `[]='
  /home/rubys/git/gorp/lib/gorp/edit.rb:150:in `msub'
  makedepot.rb:3911
  /home/rubys/git/gorp/lib/gorp/edit.rb:95:in `instance_exec'
  /home/rubys/git/gorp/lib/gorp/edit.rb:95:in `edit'
  /home/rubys/git/gorp/lib/gorp/edit.rb:93:in `sub!'
  /home/rubys/git/gorp/lib/gorp/edit.rb:93:in `edit'
  makedepot.rb:3910
  /home/rubys/git/gorp/lib/gorp/edit.rb:173:in `instance_exec'
  /home/rubys/git/gorp/lib/gorp/edit.rb:173:in `edit'
  makedepot.rb:3906
  /home/rubys/git/gorp/lib/gorp/output.rb:59:in `call'
  /home/rubys/git/gorp/lib/gorp/output.rb:59
  /home/rubys/git/gorp/lib/gorp/output.rb:49:in `each'
  /home/rubys/git/gorp/lib/gorp/output.rb:49
  /home/rubys/.rvm/gems/ruby-1.8.7-p374/gems/builder-2.1.2/lib/builder/xmlbase.rb:134:in `call'
  /home/rubys/.rvm/gems/ruby-1.8.7-p374/gems/builder-2.1.2/lib/builder/xmlbase.rb:134:in `_nested_structures'
  /home/rubys/.rvm/gems/ruby-1.8.7-p374/gems/builder-2.1.2/lib/builder/xmlbase.rb:58:in `method_missing'
  /home/rubys/git/gorp/lib/gorp/output.rb:22
  /home/rubys/.rvm/gems/ruby-1.8.7-p374/gems/builder-2.1.2/lib/builder/xmlbase.rb:134:in `call'
  /home/rubys/.rvm/gems/ruby-1.8.7-p374/gems/builder-2.1.2/lib/builder/xmlbase.rb:134:in `_nested_structures'
  /home/rubys/.rvm/gems/ruby-1.8.7-p374/gems/builder-2.1.2/lib/builder/xmlbase.rb:58:in `method_missing'
  /home/rubys/git/gorp/lib/gorp/output.rb:11
  makedepot.rb:4174
    
<!DOCTYPE html>
<html>
<head>
  <title>Pragprog Books Online Store</title>
  <%= stylesheet_link_tag    "depot", :media => "all",
    "data-turbolinks-track" => true %>
  <%= javascript_include_tag "depot", "data-turbolinks-track" => true %>
  <%= csrf_meta_tag %>
</head>
<!-- ... -->
<body class="<%= controller.controller_name %>">
  <div id="banner">
    <%= form_tag store_path, :class => 'locale' do %>
      <%= select_tag 'set_locale', 
        options_for_select(LANGUAGES, I18n.locale.to_s),
        :onchange => 'this.form.submit()' %>
      <%= submit_tag 'submit' %>
      <%= javascript_tag "$('.locale input').hide()" %>
    <% end %>
    <%= image_tag("logo.png") %>
    <%= @page_title || t('.title') %>
  </div>
  <div id="columns">
    <div id="side">
      <% if @cart %>
        <%= hidden_div_if(@cart.line_items.empty?, :id => 'cart') do %>
          <%= render @cart %>
        <% end %>
      <% end %>
 
      <ul>
        <li><a href="http://www...."><%= t('.home') %></a></li>
        <li><a href="http://www..../faq"><%= t('.questions') %></a></li>
        <li><a href="http://www..../news"><%= t('.news') %></a></li>
        <li><a href="http://www..../contact"><%= t('.contact') %></a></li>
      </ul>
 
      <% if session[:user_id] %>
        <ul>
          <li><%= link_to 'Orders',   orders_path   %></li>
          <li><%= link_to 'Products', products_path %></li>
          <li><%= link_to 'Users',    users_path    %></li>
        </ul>
        <%= button_to 'Logout', logout_path, :method => :delete   %>
      <% end %>
    </div>
    <div id="main">
      <%= yield %>
    </div>
  </div>
</body>
</html>

26.1.4 JQuery 26.1 Active Merchant