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
plugin() click to toggle source
# File lib/conjoin/assets.rb, line 89
def plugin
  Assets.app.settings[:assets]
end