No commit activity in last 3 years
No release in over 3 years
Provides methods for generating assets urls.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Sinatra AssetsLinker Helper

Gem Version Code Climate Dependency Status

Provided methods:

  • css_uri(file_name, add_script_name = true)
  • js_uri(file_name, add_script_name = true)
  • img_uri(file_name, add_script_name = true)

They extend the uri method from the Sinatra. Always returns relative paths, unless you set :project_cdn_url.

Installation

Add this line to your application's Gemfile:

gem 'sinatra-assets_linker'

And then execute:

$ bundle

Or install it yourself as:

$ gem install sinatra-assets_linker

Configuration

Through SinatraAssetsLinker::Config class:

config = SinatraAssetsLinker::Config.new(
  "project_css_dir" => "css_dir"                    # default: "stylesheets"
  "project_javascripts_dir" => "js_dir"             # default: "javascripts"
  "project_js_compressed_dir" => "cjs_dir"          # default: "js"
  "project_images_dir" => "img_dir"                 # default: "images"
  "project_assets_verbose" => true                  # default: false
  "project_cdn_url" => "http://cdn.net"             # default: nil
)

Usage

Above methods look for configuration under: settings.assets_linker_config, so:

require 'sinatra/base'
require 'sinatra/assets_linker'

class MyApp < Sinatra::Base
  helpers Sinatra::AssetsLinker

  configure do
    set :assets_linker_config, SinatraAssetsLinker::Config.new(ENV.to_h)
  end
end

and when you call:

css_uri('file.css')       # -> /css_dir/file.css
js_uri('file.js')         # -> /js_dir/file.js
img_uri('file.jpg')       # -> /img_dir/file.jpg

if you set "project_cdn_url" before, you get:

css_uri('file.css')       # -> http://cdn.net/css_dir/file.css
js_uri('file.js')         # -> http://cdn.net/js_dir/file.js
img_uri('file.jpg')       # -> http://cdn.net/img_dir/file.jpg

Assets verbose

If you set "project_assets_verbose" to true, then the js_uri method will use project_javascripts_dir instead of project_js_compressed_dir

Versioning

See semver.org

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