Sinatra AssetsLinker Helper
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
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request