0.01
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Manage CSS/JS assets as dynamic resources rather than static files
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.6
~> 0.2.1
~> 3.0.23
~> 1.2.21
>= 0
~> 0.9.8
~> 1.6.1
~> 2.0.0
 Project Readme

AssetResource

Serve up your CSS and Javascript as first-class resources.

Supports in-line rendering of engines such as Sass and Less. These files will be served with 24-hour HTTP cache expiry.

Built-in configuration and helpers for Rails 2.x, Rails 3.x and Sinatra.

Usage

Rails 2.x

# public/stylesheets/*.{css|less|sass}
# public/javascripts/*.js

# config/environment.rb
config.gem "asset-resource"

# app/views/layouts/application.html.erb
<html>
  <head>
    <%= asset_resource_javascripts %>
    <%= asset_resource_stylesheets %>
  </head>
</html>

Rails 3.x

# public/stylesheets/*.{css|less|sass}
# public/javascripts/*.js

# Gemfile
gem "asset-resource"

# app/views/layouts/application.html.erb
<html>
  <head>
    <%= asset_resource_javascripts %>
    <%= asset_resource_stylesheets %>
  </head>
</html>

Sinatra

# assets/styles/*.{css|less|sass}
# assets/scripts/*.js

# app.rb
require "asset_resource"

class App < Sinatra::Base
  register Sinatra::AssetResource
end

__END__

@@ layout
%html
  %head
    = asset_resource_scripts
    = asset_resource_styles

Technical Details

AssetResource::Middleware serves requests at /assets/stylesheets.css and /assets/javascripts.js.

The gem will add appropriate view helpers to your framework of choice.

You can use the middleware yourself like this:

use AssetResource::Middleware,
  :base_path => "public",
  :handlers  => { :javascripts => "text/javascript",
                  :stylesheets => "text/css" }

Copyright

MIT License

Author

David Dollar

http://daviddollar.org