module Ustyle

Constants

BUCKET
CLOUDFRONT_DISTRIBUTION
ONE_YEAR_FROM_NOW
ONE_YEAR_IN_S
REGION
VERSION

Public Class Methods

asset_digest(path) click to toggle source
# File lib/ustyle/utils.rb, line 17
def self.asset_digest path
  path.sub(/\.(\w+)$/) { |ext| "-#{digest}#{ext}" }
end
asset_directories() click to toggle source
# File lib/ustyle.rb, line 42
def asset_directories
  %w(stylesheets javascripts images fonts)
end
assets_path() click to toggle source
# File lib/ustyle.rb, line 38
def assets_path
  @assets_path ||= File.join gem_path, "vendor", "assets"
end
autoprefixer_config() click to toggle source
# File lib/ustyle.rb, line 50
def autoprefixer_config
  file   = File.join Ustyle.gem_path, 'config/autoprefixer.yml'
  params = YAML.load_file(file).symbolize_keys
  params
end
cloudfront_url(path, type, versioned = true, digest = true) click to toggle source
# File lib/ustyle/utils.rb, line 10
def self.cloudfront_url path, type, versioned = true, digest = true
  File.join "https://assets0.uswitch.com/s3/uswitch-assets-eu/ustyle/",
            (versioned ? Ustyle::VERSION : ""),
            folder_by_type(type),
            (digest ? asset_digest(path) : path)
end
digest() click to toggle source
# File lib/ustyle/utils.rb, line 29
def self.digest
  Digest::SHA1.hexdigest Ustyle::VERSION
end
folder_by_type(type) click to toggle source
# File lib/ustyle/utils.rb, line 33
def self.folder_by_type type
  case type
  when :image
    "images"
  when :font
    "fonts"
  else ""
  end
end
gem_path() click to toggle source
# File lib/ustyle.rb, line 34
def gem_path
  @gem_path ||= File.expand_path "..", File.dirname(__FILE__)
end
invalidate(files) click to toggle source
# File lib/ustyle/deploy.rb, line 24
def self.invalidate files
  cloudfront = Aws::CloudFront::Client.new(region: REGION)
  cloudfront.create_invalidation(
    distribution_id: CLOUDFRONT_DISTRIBUTION,
    invalidation_batch: {
      paths: {
        quantity: files.length,
        items: files
      },
      caller_reference: "ustyle invalidation at #{Time.now.to_s}"
    }
  )
end
load!() click to toggle source
# File lib/ustyle.rb, line 11
def load!
  require "ustyle/sass_functions"
  require "ustyle/icons"
  require "ustyle/helpers/icon_helper"

  if rails?
    require "ustyle/engine"
  elsif sprockets?
    require "ustyle/sprockets"
    require "ustyle/sinatra"
  end

  ::Sass.load_paths << File.join(assets_path, "stylesheets")
end
mime_type_for(asset) click to toggle source
# File lib/ustyle/utils.rb, line 21
def self.mime_type_for asset
  MIME::Types.type_for( asset ).first.content_type
end
production?() click to toggle source
# File lib/ustyle/utils.rb, line 6
def self.production?
  ENV['RACK_ENV'] == 'production' || ENV['RAILS_ENV'] == 'production' || ENV['NODE_ENV'] == 'production' || false
end
rails?() click to toggle source
# File lib/ustyle.rb, line 30
def rails?
  defined?(::Rails)
end
s3() click to toggle source
# File lib/ustyle/deploy.rb, line 38
def self.s3
  @conn ||= Aws::S3::Resource.new(region: REGION)
end
s3_upload(to, from, content_type, bucket = BUCKET) click to toggle source
# File lib/ustyle/deploy.rb, line 12
def self.s3_upload to, from, content_type, bucket = BUCKET
  bucket = s3.bucket(bucket)
  object = bucket.object(to)
  object.put(
    body: open(from),
    content_type: content_type,
    acl: 'public-read',
    cache_control: "max-age=#{ONE_YEAR_IN_S}, public",
    expires: ONE_YEAR_FROM_NOW.httpdate
  )
end
sprockets?() click to toggle source
# File lib/ustyle.rb, line 26
def sprockets?
  defined?(::Sprockets)
end
sprockets_env() click to toggle source
# File lib/ustyle.rb, line 46
def sprockets_env
  @sprockets_env ||= ::Sprockets::Environment.new
end
versioned_path(file) click to toggle source
# File lib/ustyle/utils.rb, line 25
def self.versioned_path file
  File.join "ustyle", Ustyle::VERSION, file
end