Sha256: 03eaef61581bd8ae0b9139bdc9eada7c4f939ec9bf383958a435e28a24dc4ae3
Contents?: true
Size: 1.82 KB
Versions: 5
Compression:
Stored size: 1.82 KB
Contents
# encoding: utf-8 # Copyright (C) 2015 Szymon Kopciewski # # This file is part of SinatraAssetsLinker. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. require 'sinatra/base' module Sinatra module AssetsLinker def css_uri(file_name, add_script_name = true) cdn_url = get_settings(:cdn_url) css_dir = get_settings(:css_dir, 'stylesheets') generate_uri(cdn_url, css_dir, file_name, add_script_name) end def js_uri(file_name, add_script_name = true) cdn_url = get_settings(:cdn_url) js_dir = get_settings(:js_dir, 'javascripts') generate_uri(cdn_url, js_dir, file_name, add_script_name) end def img_uri(file_name, add_script_name = true) cdn_url = get_settings(:cdn_url) img_dir = get_settings(:img_dir, 'images') generate_uri(cdn_url, img_dir, file_name, add_script_name) end private def get_settings(key, default = nil) settings.respond_to?(key) ? settings.send(key) : default end def generate_uri(cdn_url, assets_dir, file_name, add_script_name) absolute_path = false relative_url = uri(File.join(assets_dir, file_name), absolute_path, add_script_name) return File.join(cdn_url, relative_url) unless cdn_url.nil? relative_url end end end
Version data entries
5 entries across 5 versions & 1 rubygems