Permalink
Browse files

Initial entry

  • Loading branch information...
0 parents commit ce14b774a20139888148e21b6549caf2f95a2cf5 Benjamin Bloch committed Jan 12, 2012
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
@@ -0,0 +1,4 @@
+# Version History
+
+### 0.1.0 - (January 12, 2012)
+* Initial release
@@ -0,0 +1,2 @@
+source :rubygems
+gemspec
19 LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2012 Benjamin Bloch
+
+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:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
@@ -0,0 +1,45 @@
+# Padrino Assets
+
+### Overview
+
+Padrino assets is a plugin for the [Padrino](https://github.com/padrino/padrino-framework) web framework which makes use of the [Rack](https://github.com/rack/rack) plugin [Sprockets](https://github.com/sstephenson/sprockets) to manage and compile web assets.
+
+### Setup & Installation
+
+Include it in your project's `Gemfile` with Bundler:
+
+``` ruby
+gem 'padrino-assets'
+```
+
+Modify your `app/app.rb` file to register the plugin:
+
+``` ruby
+class ExampleApplication < Padrino::Application
+ register Padrino::Assets
+end
+```
+
+Modify your `config.ru` file to mount the environment:
+
+``` ruby
+map '/assets' do
+ run Padrino::Assets.environment
+end
+```
+
+### Dependencies
+
+* [Padrino-Core](https://github.com/padrino/padrino-framework) and [Padrino-Helpers](https://github.com/padrino/padrino-framework)
+* [Ruby](http://www.ruby-lang.org/en) >= 1.9.2
+* [Sprockets](https://github.com/sstephenson/sprockets)
+
+### TODO
+
+* Support for CSS/Javascript minification
+* Additional documentation
+* Tests
+
+### Copyright
+
+Copyright © 2012 Benjamin Bloch (Cirex). See LICENSE for details.
@@ -0,0 +1 @@
+require 'bundler/gem_tasks'
@@ -0,0 +1,11 @@
+Nginx Configuration Example
+=============================
+
+``` nginx
+location ~ ^/(assets)/ {
+ add_header Cache-Control public;
+ root /path/to/public;
+ gzip_static on;
+ expires max;
+}
+```
@@ -0,0 +1,81 @@
+require 'padrino-core'
+require 'padrino-helpers'
+
+FileSet.glob_require('padrino-assets/**/*.rb', __FILE__)
+
+module Padrino
+ module Assets
+ class << self
+ ##
+ # Returns a list of paths Sprockets will use in order to find assets used by the project
+ #
+ # @return [Array]
+ # List of assets paths
+ #
+ # @example
+ # Padrino::Assets.load_paths << Padrino.root('vendor', '**', 'assets')
+ #
+ # @api public
+ def load_paths
+ @_load_paths ||= ['app/assets/**', 'lib/assets/**'].map do |file|
+ Dir[Padrino.root(file)]
+ end.flatten
+ end
+
+ ##
+ # Returns the configured Sprockets environment
+ #
+ # @return [Sprockets::Environment]
+ # Sprockets environment
+ #
+ # @api public
+ def environment
+ @_environment
+ end
+
+ ##
+ # Returns a compiled manifest of our assets
+ #
+ # @return [Sprockets::Manifest]
+ # Sprockets manifest
+ #
+ # @api public
+ def manifest
+ @_manifest
+ end
+
+ # @private
+ def registered(app)
+ app.helpers Helpers
+ app.set :assets_prefix, '/assets'
+ app.set :assets_version, 1.0
+ app.set :assets_host, nil
+ app.set :compress_assets, true
+ app.set :index_assets, -> { app.environment == :production }
+ app.set :manifest_file, -> { File.join(app.public_folder, app.assets_prefix, 'manifest.json') }
+ app.set :precompile_assets, [ /^.+\.(?!js|css).+$/i, /^application\.(js|css)$/i ]
+
+ require 'sprockets'
+
+ Padrino.after_load do
+ @_environment = Sprockets::Environment.new(app.root) do |environment|
+ environment.logger = app.logger
+ environment.version = app.assets_version
+ if defined?(Padrino::Cache)
+ if app.respond_to?(:caching) && app.caching?
+ environment.cache = app.cache
+ end
+ end
+ end
+
+ load_paths.each { |path| environment.append_path(path) }
+
+ @_environment = environment.index if app.index_assets?
+ @_manifest = Sprockets::Manifest.new(environment, app.manifest_file)
+ end
+
+ Padrino::Tasks.files << Dir[File.dirname(__FILE__) + '/tasks/**/*.{rake,rb}']
+ end
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit ce14b77

Please sign in to comment.