Skip to content

singlebrook/js-asset_paths

 
 

Repository files navigation

JS Asset Paths

gem version build status code climate test coverage

Inspired by js-routes, JS Asset Paths makes the helper methods found in ActionView::Helpers::AssetUrlHelper available to the client.

Installation

Add this line to your application's Gemfile:

gem 'js-asset_paths'

Then require the js-asset_paths file in your application.js.

/*
= require js-asset_paths
*/

Ensure that your config/environments/production.rb has the following:

config.assets.compile = true

(This avoids a NoMethodError: undefined method each_file for nil:NilClass when precompiling your assets upon deployment.)

Usage

A global object called PathHelper will be created with the following methods:

  • assetPath(source[, options])
  • audioPath(source)
  • fontPath(source)
  • imagePath(source)
  • javascriptPath(source)
  • stylesheetPath(source)
  • videoPath(source)

These functions operate in the same manner as their server-side counterparts.

Explanation

JS Asset Paths inspects the configuration options for the current environment and determines whether or not a digest will be appended to the pathname of asset files. An object correlating the truncated asset path with the actual path to the asset on the server is stored in the generated javascript and referenced during each call.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

Asset path helpers for your javascript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 86.8%
  • JavaScript 13.2%