module Conjoin::Assets
Attributes
app[RW]
Public Class Methods
setup(app)
click to toggle source
# File lib/conjoin/assets.rb, line 18 def self.setup app self.app = app # if ENV['RACK_ENV'] != 'production' # require 'rugged' # end Slim::Engine.set_default_options \ disable_escape: true, use_html_safe: true, disable_capture: false, pretty: (Conjoin.env.production? or Conjoin.env.staging?) ? false : true app.settings[:assets] ||= OpenStruct.new({ settings: {}, stylesheet: [], images: [], javascript_head: [], javascript: [] }) end
Public Instance Methods
accepted_assets()
click to toggle source
# File lib/conjoin/assets.rb, line 76 def accepted_assets "(.*)\.(js|css|eot|svg|ttf|woff|png|gif|jpg|jpeg)$" end
asset_path(file)
click to toggle source
# File lib/conjoin/assets.rb, line 46 def asset_path file if Conjoin.env.production? or Conjoin.env.staging? path = "#{plugin.settings[:path] || '/'}public/assets/#{file}" else case file[/(\.[^.]+)$/] when '.css', '.js' path = "#{plugin.settings[:path] || '/'}#{cache_string}assets/#{file}" else path = "#{plugin.settings[:path] || '/'}#{cache_string}assets/images/#{file}" end end "http#{(Conjoin.env.production? or Conjoin.env.staging?)? 's' : ''}://#{req.env['HTTP_HOST']}#{path}" end
fa_icon(icon, options = {})
click to toggle source
# File lib/conjoin/assets.rb, line 67 def fa_icon icon, options = {} options[:class] ||= '' options[:class] += " fa fa-#{icon}" mab do i options end end
image_tag(file, options = {})
click to toggle source
# File lib/conjoin/assets.rb, line 60 def image_tag file, options = {} options[:src] = asset_path(file) mab do img options end end
Private Instance Methods
cache_string()
click to toggle source
# File lib/conjoin/assets.rb, line 82 def cache_string if Conjoin.env.mounted? # @cache_string ||= (File.read "#{Assets.app.root}/sha") + "/" "/" end end
links_for(type, opts = {})
click to toggle source
# File lib/conjoin/assets.rb, line 93 def links_for type, opts = {} method = :link path = :href extention = :css options = { 'data-turbolinks-track' => 'true' } case type when :stylesheet_assets options.merge!({ rel: 'stylesheet', type: 'text/css', media: 'all' }) when :javascript_assets, :javascript_head_assets method = :script path = :src extention = :js else raise 'Please choose a type: stylesheet_assets, javascript_head_assets or javascript_assets' end # merge in the user options allowing them to override options.merge! opts app = self mab do if Conjoin.env.production? or Conjoin.env.staging? Thread.current[:sha] ||= File.read "#{Assets.app.root}/sha" case type when :stylesheet_assets name = 'stylesheet' when :javascript_assets name = 'javascript' end options[path] = asset_path "#{name}-#{Thread.current[:sha]}.#{extention}" send(method, options) else app.send(type).each do |asset| options[path] = asset_path asset.gsub(/\.coffee/, '.js').gsub(/\.(scss|styl)/, '.css') send(method, options) end end end end
plugin()
click to toggle source
# File lib/conjoin/assets.rb, line 89 def plugin Assets.app.settings[:assets] end