Coder Social home page Coder Social logo

alxndr / smart_asset Goto Github PK

View Code? Open in Web Editor NEW

This project forked from winton/smart_asset

0.0 3.0 0.0 4.52 MB

Smart asset packaging for Rails, Sinatra, and Stasis

Home Page: http://winton.github.com/smart_asset

License: MIT License

Ruby 46.70% JavaScript 28.54% CSS 24.76%

smart_asset's Introduction

SmartAsset

Smart asset packaging for Rails, Sinatra, and Stasis.

Build Status

Features

Similar to AssetPackager, but with the following changes:

  • Uses file size and super fast hashing (Murmur3) to determine if a new compressed package should be created
  • uglify-js for javascript compression
  • clean-css for css compression
  • Framework agnostic (adapters provided for Rails 2, Rails 3, Sinatra, and Stasis)

Installation

Install gem

gem install smart_asset

Install npm packages

npm install uglify-js clean-css -g

Install

Rails 2

config/environment.rb

config.gem 'smart_asset'

Rails 3

Gemfile

gem 'smart_asset'

Sinatra

require 'sinatra/base'
require 'smart_asset'

class Application < Sinatra::Base
  include SmartAsset::Adapters::Sinatra
end

Create Configuration File

config/assets.yml

javascripts:
  package_1:
    - jquery/jquery
    - underscore
  package_2:
    - front_page
stylesheets:
  package_1:
    - blueprint/blueprint
    - 960
  package_2:
    - front_page

By default, SmartAsset will look for assets in public/javascripts and public/stylesheets.

Create Packaged Assets

cd to your project and run

smart_asset

If your project is Git version controlled, only the assets that have changed are repackaged.

Otherwise, all packages generate every time.

Include Packages in Your Template

<%= javascript_include_merged :package_1, :package_2 %>
<%= stylesheet_link_merged :package_1, :package_2 %>

Migrating from AssetPackager

  • rm vendor/plugins/asset_packager
  • Install SmartAsset
  • Move config/asset_packages.yml to config/assets.yml
  • Instead of running rake asset:packager:build_all, run smart_asset

Other Options

config/assets.yml

You may add extra options to your config/assets.yml file.

Below are the default values (excluding asset_host):

# Append random numbers to script paths on each request
append_random:
  development: true

# Asset host URL (defaults to ActionController::Base.asset_host or nil)
asset_host:
  production: http://assets%d.mydomain.com

# How many asset hosts you have (use if asset_host defined with %d)
asset_host_count: 4

# Public directory
public: public

# Package destination directory (within the public directory)
destination:
  javascripts: javascripts/packaged
  stylesheets: stylesheets/packaged

# Asset source directories (within the public directory)
sources:
  javascripts: javascripts
  stylesheets: stylesheets

smart_asset

You may use environment variables with the smart_asset command to alter its behavior.

DEBUG=1
Output commands that are running, leave the tmp file around for inspection

PACKAGE=package_1
Only compress a specific package

MODIFIED='12/1/2010 12:00'
Use a default modified time other than Time.now for non-version controlled files

WARN=1
Get compression warnings from UglifyJS

Example:

WARN=1 smart_asset

Running Specs

Forks and contributions to this project are much appreciated, but please make sure the specs run!

To run the basic specs:

spec spec

There are also framework specs to make sure the helpers work in Rails 2, Rails 3, and Sinatra 1:

spec/run

smart_asset's People

Contributors

winton avatar dcu avatar tongueroo avatar

Watchers

Alexander Quine avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.