Skip to content

Commit

Permalink
Update environment.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
ixti committed Mar 3, 2015
1 parent e01a9e6 commit a1783f7
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions lib/jekyll/assets_plugin/environment.rb
Expand Up @@ -10,6 +10,8 @@
module Jekyll
module AssetsPlugin
class Environment < Sprockets::Environment
AUTOPREFIXER_CONFIG_FILES = %w(autoprefixer.yml _autoprefixer.yml)

class AssetNotFound < StandardError
def initialize(path)
super "Couldn't find file '#{path}'"
Expand Down Expand Up @@ -56,31 +58,23 @@ def find_asset(path, *args)

private

def load_autoprefixer_yml(files)
params = {}

files.each do |file|
f = Pathname.new(@site.source).join file
if f.exist?
params = YAML.load_file(f)
break
end
end

params.reduce({}) do |h, (key, value)|
h.update(key.to_sym => value)
end
end

def browsers
opts = {}
params = load_autoprefixer_yml([
"autoprefixer.yml",
"_autoprefixer.yml"
])

opts[:safe] = true if params.delete(:safe)
[params, opts]
config = autoprefixer_config
opts = { :safe => params.delete(:safe) }

[config, opts]
end

def autoprefixer_config
config_file = AUTOPREFIXER_CONFIG_FILES
.map { |f| Pathname.new(@site.source).join f }
.find(&:exist?)

return {} unless config_file

YAML.load_file(config_file).reduce({}) do |h, (k, v)|
h.update(k.to_sym => v)
end
end

def install_autoprefixer!
Expand Down

0 comments on commit a1783f7

Please sign in to comment.