Skip to content

Commit

Permalink
Revisions to provide integrated Rails 3.0 support.
Browse files Browse the repository at this point in the history
Repertoire Assets now detects when it is running in Rails, and installs
the Rack middleware automatically via a Railtie.  So now the only config
necessary is a single line in production.rb to turn on asset precaching.

The rake tasks have been revised to integrate cleanly with Rails, and
the gemspec configuration follows Rails standards.
  • Loading branch information
Christopher York committed Jul 29, 2010
1 parent 8926d46 commit 8bc2d6f
Show file tree
Hide file tree
Showing 17 changed files with 189 additions and 285 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*~
pkg
doc
*.gem
26 changes: 15 additions & 11 deletions FAQ
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ Q. My application is not loading javascript or css files. There is nothing
about them in the log.

A. You have not installed the Rack middleware in your application's rackup
file. Consult the README.
file. The middleware is automatically loaded for Rails 3.0 when you add
repertoire-assets to your Gemfile - but not for other frameworks. Consult
the README.



Expand Down Expand Up @@ -43,20 +45,13 @@ public/javascripts/application.js:



Q. I have compress_assets set to true, but in my deployed application
Q. I have compress set to true, but in my deployed application
digest.js or digest.css aren't YUI compressed.

A. You are probably using an uncompressable Javascript syntax. Try compressing
by hand on the command-line and YUI compressor will give you an error
statement. This should also appear in the application's log.



Q. Can I use repertoire-assets together with merb-assets?

A. Yes. It replaces merb-asset's bundling and javascript/stylesheet helpers,
but the remaining helpers can be used with assets from either the main app or
assets in gems. (See below.)
[ If using Rails 3, use rake 'assets:build' to compress the files by hand. ]



Expand All @@ -67,7 +62,7 @@ A. So that gems can specify in which directory in the host application they
appear. e.g., 'foo_gem-0.0.1/public/images/foo/bar.png' is served as though it
were '<host app>/public/images/foo/bar.png'.

This way, existing img_tag and other helpers in merb/rails can be used
This way, existing image_tag and other helpers in Rails can be used
with assets pulled from gems.


Expand All @@ -78,9 +73,18 @@ or different browsers.
A. This was considered, but isn't implemented. Issue a feature request.



Q. Repertoire assets seems like sprockets or juicer. How is it different?

A. Only Repertoire assets addresses distributing javascript and css via
rubygems. Its syntax is borrowed from sprockets, but it has better css support
than sprockets, and better provisions for debugging than either since you can
develop on unbundled source files.



Q. Can I use repertoire-assets together with merb-assets?

A. Yes. It replaces merb-asset's bundling and javascript/stylesheet helpers,
but the remaining helpers can be used with assets from either the main app or
assets in gems.
32 changes: 24 additions & 8 deletions INSTALL
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
Repertoire Assets
=================

(1) Make sure your application loads the middleware. e.g. for Merb:

<app>/config/rack.rb (Mongrel)
<app>/config.ru (Passenger)
(1) Make sure your application loads the middleware. For Rails 3.0,
including repertoire-assets in your Gemfile does this automatically.

For Merb and others, you will need to alter your rackup file. The
middleware takes two optional arguments: a configuration hash and
the system logger.

<app>/config/rack.rb (Mongrel)
<app>/config.ru (Passenger)

* require 'repertoire-assets'
* use Repertoire::Assets::Processor, Merb::Config, Merb.logger
* require 'repertoire-assets'
* use Repertoire::Assets::Processor, Merb::Config, Merb.logger

run Merb::Rack::Application.new
run Merb::Rack::Application.new


(2) Turn on precaching and compression in your production environment,
so gem assets are served by your web server. e.g. for Merb:
so gem assets are served by your web server. e.g. for Rails:

<app>/config/environments/production.rb:

* c[:compress_assets] = true
* config.repertoire_assets.compress = true

Or in Merb:

<app>/config/environments/production.rb:

* c[:compress] = true

For other options that can be used in the configuration hash, see the
documentation for Repertoire::Assets::Processor.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2009 MIT Hyperstudio
Copyright (c) 2009-2010 MIT Hyperstudio

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
Expand Down
78 changes: 17 additions & 61 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ sourced, it is not loaded again.
This is accomplished by compiling an ordered manifest of all the javascript
files required by your code, and then inserting the appropriate <script> and
<link> tags into your pages' html. Because it uses a rack filter, the system
is largely transparent to your application. Whether it's written in Merb,
Rails, Sinatra, or another ruby web framework, the javascript and css will
is largely transparent to your application. Whether it's written in Rails,
Merb, Sinatra, or another ruby web framework, the javascript and css will
still work.


Expand All @@ -61,30 +61,15 @@ can, and cache them in your application's public asset directory.
*Preparing your application*

You can use javascript components packaged with Repertoire Assets in any ruby
web application based on Rack (this includes Merb, Rails, Sinatra and others).
web application based on Rack (this includes Rails, Merb, Sinatra and others).

The javascript gem libraries can either be bundled with your application, or
reside in the system rubygems repository. Likewise, the repertoire-assets gem
may be in either place.

Three lines of configuration are required.

(1) Make sure your application loads the middleware. e.g. for Merb:

<app>/config/rack.rb (Mongrel)
<app>/config.ru (Passenger)

* require 'repertoire-assets'
* use Repertoire::Assets::Processor, Merb::Config, Merb.logger

run Merb::Rack::Application.new

(2) Turn on precaching and compression in your production environment,
so gem assets are served by your web server. e.g. for Merb:

<app>/config/environments/production.rb:

* c[:compress_assets] = true
For Rails 3.0, no configuration is necessary for development use. Production
environments require a single line of configuration. See the INSTALL file
for details.



Expand Down Expand Up @@ -192,8 +177,8 @@ named after your library (e.g. /images/superdraw/circle.png rather than
For security reasons, the system will never serve a file that was not
explicitly required or provided.

A template for your own gems' Rakefile, based on jeweler, is distributed in
repertoire-assets/templates/Rakefile. Copy it out and modify as necessary.
If you are using Rails and would like to preview the manifest or generate
digests by hand, use 'rake assets:list' and 'rake assets:build'.



Expand Down Expand Up @@ -224,55 +209,26 @@ the conflict and told which one is being used.

The following options are available for production configurations.

:precache_assets [false] # copy and bundle assets into host application?
:compress_assets [false] # compress bundled javascript & stylesheets? (implies :precache)
:disable_rack_assets [false] # don't interpolate <script> and <link> tags
:path_prefix [''] # prefix for all generated urls
- precache [false] # copy and bundle assets into host application?
- compress [false] # compress bundled javascript & stylesheets? (implies :precache)
- disable_rack_assets [false] # don't interpolate <script> and <link> tags
- path_prefix [''] # prefix for all generated urls

In general, :compress_assets is preferred. This copies all binary assets into
In general, 'compress' is preferred. This copies all binary assets into
your host application, bundles together all required javascript and css into
files named '/digest.js' and '/digest.css', and compresses these files using
YUI compressor. Use :precache_assets if you do not want to compress the files.
YUI compressor. Use 'precache' if you do not want to compress the files.

In both cases, the asset mirroring middleware is disabled, and your app's
webserver serves all assets directly from the filesystem.

If desired, you may also disable the <script> and <link> middleware in your
production install while still precaching and compressing all assets. Set the
:disable_rack_assets configuration option to true, and add the following to
'disable_rack_assets' configuration option to true, and add the following to
your html header:

<link rel='stylesheet' type='text/css' href='/digest.css'/>
<script language='javascript' type='text/javascript' src='/digest.js'></script>

Note, however, that the server performance gain from :disable_rack_assets is
minimal.


* Using Repertoire Assets as a Build Tool *

If you want to build your assets for use outside of ruby applications, you can
use the repertoire assets' rake tasks to generate a set of bundled standalone
files. First, import the rake tasks into your gem's Rakefile:

... [ ./Rakefile ]
begin
require 'repertoire-assets'
Repertoire::Assets::Tasks.new(:gem_excludes => ["jquery", ...]) # list any libraries to distribute separately here
rescue LoadError
puts "Repertoire assets not available. Install it with: sudo gem install repertoire-assets"
end
...

Then you can build a bundled and compressed directory of assets for your
component with:

# rake assets:build

This gives you the flexibility of developing and deploying components that use
javascript dependencies and version management for use within ruby frameworks,
but also distributing your code for a wider audience.

The gem_excludes option allow you to list of required javascript libraries NOT to
bundle into your distribution directory for legal reasons. You may also supply
any of the other the other standard repertoire-assets options.
Note, however, that the server performance gain from 'disable_rack_assets' is
minimal.
58 changes: 6 additions & 52 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,56 +1,10 @@
begin
require 'jeweler'
Jeweler::Tasks.new do |s|
s.name = "repertoire-assets"
s.summary = "Repertoire Assets javascript and css distribution framework"
s.description = "Repertoire Assets javascript and css distribution framework"
s.email = "[email protected]"
s.homepage = "http://github.com/repertoire/repertoire-assets"
s.authors = ["Christopher York"]
s.add_dependency('rack', '>=1.0.1')
s.post_install_message = <<-POST_INSTALL_MESSAGE
#{'*'*80}
One of your gems uses Repertoire asset support, which provides access to
javascript, stylesheets and or others assets distributed via Rubygems.
require __FILE__ + '/../lib/repertoire-assets'

Rack middleware serves assets in front of your Merb or Rails application,
and includes <script> and <link> tags in the header automatically.
gemspec = eval(File.read("repertoire-assets.gemspec"))

(1) Make sure your application loads the middleware. e.g. for Merb:
task :build => "#{gemspec.full_name}.gem"

<app>/config/rack.rb (Mongrel)
<app>/config.ru (Passenger)
require 'repertoire-assets'
use Repertoire::Assets::Processor, Merb::Config, Merb.logger
run Merb::Rack::Application.new
(2) Turn on precaching and compression in your production environment,
so gem assets are served by your web server. e.g. for Merb:
<app>/config/environments/production.rb:
c[:compress_assets] = true
See the repertoire-assets README for details.
#{'*'*80}
POST_INSTALL_MESSAGE
end
Jeweler::RubyforgeTasks.new do |rubyforge|
rubyforge.doc_task = "yardoc"
end

Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler not available. Install it with: sudo gem install jeweler"
file "#{gemspec.full_name}.gem" => gemspec.files + ["repertoire-assets.gemspec"] do
system "gem build repertoire-assets.gemspec"
system "gem install repertoire-assets-#{Repertoire::Assets::VERSION}.gem"
end


begin
require 'yard'
YARD::Rake::YardocTask.new(:yardoc)
rescue LoadError
task :yardoc do
abort "YARD is not available. In order to run yard, you must: sudo gem install yard"
end
end
31 changes: 31 additions & 0 deletions SNIPPETS
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
* Using Repertoire Assets as a Build Tool *

If you want to build your assets for use outside of ruby applications, you can
use the repertoire assets' rake tasks to generate a set of bundled standalone
files. First, import the rake tasks into your gem's Rakefile:

... [ ./Rakefile ]
begin
require 'repertoire-assets'
Repertoire::Assets::Tasks.new(:gem_excludes => ["jquery", ...]) # list any libraries to distribute separately here
rescue LoadError
puts "Repertoire assets not available. Install it with: sudo gem install repertoire-assets"
end
...

Then you can build a bundled and compressed directory of assets for your
component with:

# rake assets:build

This gives you the flexibility of developing and deploying components that use
javascript dependencies and version management for use within ruby frameworks,
but also distributing your code for a wider audience.

The gem_excludes option allow you to list of required javascript libraries NOT to
bundle into your distribution directory for legal reasons. You may also supply
any of the other the other standard repertoire-assets options.

[ since the Rake tasks now require Rails, this use case is less useful ]


/* Repertoire gem assets manifest file */
(function() {

Expand Down
4 changes: 4 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
- tainted files need to check css

- rails3. rework rake tasks to use Rails configuration DONE
- rails3. use middleware automatically via a railtie DONE
- rails3. use rails-style gemspec configuration DONE

- create digests based on the gem name for asset builds DONE
- test exclude functionality DONE
- test asset build config DONE
Expand Down
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

4 changes: 3 additions & 1 deletion lib/repertoire-assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
require dir + 'manifest'
require dir + 'provides'
require dir + 'processor'
require dir + 'tasks'
require dir + 'version'

require dir + 'railtie' if defined?(Rails)
Loading

0 comments on commit 8bc2d6f

Please sign in to comment.