Organizando plugins e gems.
This commit is contained in:
91
vendor/plugins/asset_packager/README
vendored
91
vendor/plugins/asset_packager/README
vendored
@@ -13,15 +13,9 @@ speed and saving bandwidth.
|
||||
When in development, it allows you to use your original versions
|
||||
and retain formatting and comments for readability and debugging.
|
||||
|
||||
Because not all browsers will dependably cache JavaScript and CSS
|
||||
files with query string parameters, AssetPackager writes a timestamp
|
||||
or subversion revision stamp (if available) into the merged file names.
|
||||
Therefore files are correctly cached by the browser AND your users
|
||||
always get the latest version when you re-deploy.
|
||||
|
||||
This code is released under the MIT license (like Ruby). You<6F>re free
|
||||
This code is released under the MIT license (like Ruby). You're free
|
||||
to rip it up, enhance it, etc. And if you make any enhancements,
|
||||
I<EFBFBD>d like to know so I can add them back in. Thanks!
|
||||
I'd like to know so I can add them back in. Thanks!
|
||||
|
||||
* Formerly known as MergeJS.
|
||||
|
||||
@@ -39,22 +33,30 @@ http://www.crockford.com/javascript/jsmin.html
|
||||
|
||||
* Merges and compresses JavaScript and CSS when running in production.
|
||||
* Uses uncompressed originals when running in development.
|
||||
* Handles caching correctly. (No querystring parameters - filename timestamps)
|
||||
* Versions each package individually. Updates to files in one won't re-trigger downloading the others.
|
||||
* Uses subversion revision numbers instead of timestamps if within a subversion controlled directory.
|
||||
* Guarantees new version will get downloaded the next time you deploy.
|
||||
* Generates packages on demand in production
|
||||
|
||||
== Components
|
||||
|
||||
* Rake Task for merging and compressing JavaScript and CSS files.
|
||||
* Rake tasks for managing packages
|
||||
* Helper functions for including these JavaScript and CSS files in your views.
|
||||
* YAML configuration file for mapping JavaScript and CSS files to merged versions.
|
||||
* YAML configuration file for mapping JavaScript and CSS files to packages.
|
||||
* Rake Task for auto-generating the YAML file from your existing JavaScript files.
|
||||
|
||||
== Updates
|
||||
|
||||
November '08:
|
||||
* Rails 2.2 compatibility fixes
|
||||
* No more mucking with internal Rails functions, which means:
|
||||
* Return to use of query-string timestamps. Greatly simplifies things.
|
||||
* Multiple asset-hosts supported
|
||||
* Filenames with "."'s in them, such as "jquery-x.x.x" are supported.
|
||||
* Now compatible with any revision control system since it no longer uses revision numbers.
|
||||
* Packages generated on demand in production mode. Running create_all rake task no longer necessary.
|
||||
|
||||
== How to Use:
|
||||
|
||||
1. Download and install the plugin:
|
||||
./script/plugin install http://sbecker.net/shared/plugins/asset_packager
|
||||
./script/plugin install git://github.com/sbecker/asset_packager.git
|
||||
|
||||
2. Run the rake task "asset:packager:create_yml" to generate the /config/asset_packages.yml
|
||||
file the first time. You will need to reorder files under 'base' so dependencies are loaded
|
||||
@@ -64,6 +66,8 @@ IMPORTANT: JavaScript files can break once compressed if each statement doesn't
|
||||
The minifier puts multiple statements on one line, so if the semi-colon is missing, the statement may no
|
||||
longer makes sense and cause a syntax error.
|
||||
|
||||
== Examples of config/asset_packages.yml
|
||||
|
||||
Example from a fresh rails app after running the rake task. (Stylesheets is blank because a
|
||||
default rails app has no stylesheets yet.):
|
||||
|
||||
@@ -78,7 +82,7 @@ javascripts:
|
||||
stylesheets:
|
||||
- base: []
|
||||
|
||||
Example with multiple merged files:
|
||||
Multiple packages:
|
||||
|
||||
---
|
||||
javascripts:
|
||||
@@ -101,8 +105,13 @@ stylesheets:
|
||||
|
||||
3. Run the rake task "asset:packager:build_all" to generate the compressed, merged versions
|
||||
for each package. Whenever you rearrange the yaml file, you'll need to run this task again.
|
||||
|
||||
Merging and compressing is expensive, so this is something we want to do once, not every time
|
||||
your app starts. Thats why its a rake task.
|
||||
your app starts. Thats why its a rake task. You can run this task via Capistrano when deploying
|
||||
to avoid an initially slow request the first time a page is generated.
|
||||
|
||||
Note: The package will be generated on the fly if it doesn't yet exist, so you don't *need*
|
||||
to run the rake task when deploying, its just recommended for speeding up initial requests.
|
||||
|
||||
4. Use the helper functions whenever including these files in your application. See below for examples.
|
||||
|
||||
@@ -111,46 +120,43 @@ away some CSS hackery. To disable comment removal, comment out /lib/synthesis/as
|
||||
|
||||
== JavaScript Examples
|
||||
|
||||
Example call:
|
||||
<%= javascript_include_merged 'prototype', 'effects', 'controls', 'dragdrop', 'application', 'foo', 'bar' %>
|
||||
Example call (based on above /config/asset_packages.yml):
|
||||
<%= javascript_include_merged :base %>
|
||||
|
||||
In development, this generates:
|
||||
<script type="text/javascript" src="/javascripts/prototype.js"></script>
|
||||
<script type="text/javascript" src="/javascripts/effects.js"></script>
|
||||
<script type="text/javascript" src="/javascripts/controls.js"></script>
|
||||
<script type="text/javascript" src="/javascripts/dragdrop.js"></script>
|
||||
<script type="text/javascript" src="/javascripts/application.js"></script>
|
||||
<script type="text/javascript" src="/javascripts/foo.js"></script>
|
||||
<script type="text/javascript" src="/javascripts/bar.js"></script>
|
||||
<script type="text/javascript" src="/javascripts/prototype.js?1228027240"></script>
|
||||
<script type="text/javascript" src="/javascripts/effects.js?1228027240"></script>
|
||||
<script type="text/javascript" src="/javascripts/controls.js?1228027240"></script>
|
||||
<script type="text/javascript" src="/javascripts/dragdrop.js?1228027240"></script>
|
||||
<script type="text/javascript" src="/javascripts/application.js?1228027240"></script>
|
||||
|
||||
In production, this generates:
|
||||
<script type="text/javascript" src="/javascripts/base_1150571523.js"></script>
|
||||
<script type="text/javascript" src="/javascripts/secondary_1150729166.js"></script>
|
||||
|
||||
Now supports symbols and :defaults as well:
|
||||
<%= javascript_include_merged :defaults %>
|
||||
<%= javascript_include_merged :foo, :bar %>
|
||||
<script type="text/javascript" src="/javascripts/base_packaged.js?123456789"></script>
|
||||
|
||||
== Stylesheet Examples
|
||||
|
||||
Example call:
|
||||
<%= stylesheet_link_merged 'screen', 'header' %>
|
||||
<%= stylesheet_link_merged :base %>
|
||||
|
||||
In development, this generates:
|
||||
<link href="/stylesheets/screen.css" media="screen" rel="Stylesheet" type="text/css" />
|
||||
<link href="/stylesheets/header.css" media="screen" rel="Stylesheet" type="text/css" />
|
||||
<link href="/stylesheets/screen.css?1228027240" media="screen" rel="Stylesheet" type="text/css" />
|
||||
<link href="/stylesheets/header.css?1228027240" media="screen" rel="Stylesheet" type="text/css" />
|
||||
|
||||
In production this generates:
|
||||
<link href="/stylesheets/base_1150729166.css" media="screen" rel="Stylesheet" type="text/css" />
|
||||
<link href="/stylesheets/base_packaged.css?1228027240" media="screen" rel="Stylesheet" type="text/css" />
|
||||
|
||||
== Different CSS Media
|
||||
|
||||
All options for stylesheet_link_tag still work, so if you want to specify a different media type:
|
||||
<%= stylesheet_link_merged :secondary, 'media' => 'print' %>
|
||||
|
||||
== Running the tests
|
||||
== Rake tasks
|
||||
|
||||
So you want to run the tests eh? Ok, then listen:
|
||||
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
|
||||
|
||||
== Running the tests
|
||||
|
||||
This plugin has a full suite of tests. But since they
|
||||
depend on rails, it has to be run in the context of a
|
||||
@@ -158,13 +164,12 @@ rails app, in the vendor/plugins directory. Observe:
|
||||
|
||||
> rails newtestapp
|
||||
> cd newtestapp
|
||||
> ./script/plugin install http://sbecker.net/shared/plugins/asset_packager
|
||||
> cd vendor/plugins/asset_packager/
|
||||
> rake # all tests pass
|
||||
> ./script/plugin install ./script/plugin install git://github.com/sbecker/asset_packager.git
|
||||
> rake test:plugins PLUGIN=asset_packager # all tests pass
|
||||
|
||||
== License
|
||||
Copyright (c) 2006 Scott Becker - http://synthesis.sbecker.net
|
||||
Contact Email: becker.scott@gmail.com
|
||||
Copyright (c) 2006-2008 Scott Becker - http://synthesis.sbecker.net
|
||||
Contact via Github for change requests, etc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user