0.0
No release in over 3 years
Low commit activity in last 3 years
Access paths to compiled assets from in javascript.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 4.2, < 6.1
>= 2.0, < 4
 Project Readme

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