From 8bc2d6f40d52ad2b29102c8708677b9d74d25889 Mon Sep 17 00:00:00 2001 From: Christopher York Date: Thu, 29 Jul 2010 16:14:38 +0100 Subject: [PATCH] Revisions to provide integrated Rails 3.0 support. 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. --- .gitignore | 1 + FAQ | 26 +++++---- INSTALL | 32 ++++++++--- LICENSE | 2 +- README | 78 ++++++--------------------- Rakefile | 58 +++----------------- SNIPPETS | 31 +++++++++++ TODO | 4 ++ VERSION | 1 - lib/repertoire-assets.rb | 4 +- lib/repertoire-assets/processor.rb | 18 +++---- lib/repertoire-assets/railtie.rb | 16 ++++++ lib/repertoire-assets/tasks.rake | 29 ++++++++++ lib/repertoire-assets/tasks.rb | 58 -------------------- lib/repertoire-assets/version.rb | 5 ++ repertoire-assets.gemspec | 86 ++++++++++-------------------- templates/Rakefile | 25 --------- 17 files changed, 189 insertions(+), 285 deletions(-) delete mode 100644 VERSION create mode 100644 lib/repertoire-assets/railtie.rb create mode 100644 lib/repertoire-assets/tasks.rake delete mode 100644 lib/repertoire-assets/tasks.rb create mode 100644 lib/repertoire-assets/version.rb delete mode 100644 templates/Rakefile diff --git a/.gitignore b/.gitignore index a8f117f..20fd609 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *~ pkg doc +*.gem \ No newline at end of file diff --git a/FAQ b/FAQ index 4423d52..d87edff 100644 --- a/FAQ +++ b/FAQ @@ -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. @@ -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. ] @@ -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 '/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. @@ -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. \ No newline at end of file diff --git a/INSTALL b/INSTALL index 04d1bfe..701101d 100644 --- a/INSTALL +++ b/INSTALL @@ -1,19 +1,35 @@ Repertoire Assets ================= -(1) Make sure your application loads the middleware. e.g. for Merb: - /config/rack.rb (Mongrel) - /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. + + /config/rack.rb (Mongrel) + /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: /config/environments/production.rb: -* c[:compress_assets] = true +* config.repertoire_assets.compress = true + + Or in Merb: + + /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. diff --git a/LICENSE b/LICENSE index 52167b2..a6df02d 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/README b/README index e078670..fa50a96 100644 --- a/README +++ b/README @@ -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 -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. \ No newline at end of file +Note, however, that the server performance gain from 'disable_rack_assets' is +minimal. \ No newline at end of file diff --git a/Rakefile b/Rakefile index 97125fe..a514a91 100644 --- a/Rakefile +++ b/Rakefile @@ -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 = "yorkc@mit.edu" - 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