Debian Codegraph @

lib/autoprefixer-rails/railtie.rb

raw symbols SCIP
1 # frozen_string_literal: true
2
3 require "yaml"
4 begin
5 require "sprockets/railtie"
6 rescue LoadError
7 end
8
9 begin
10 module AutoprefixedRails
11 class Railtie < ::Rails::Railtie # :nodoc:
12 rake_tasks do |app|
13 require "rake/autoprefixer_tasks"
14 Rake::AutoprefixerTasks.new(config) if defined? app.assets
15 end
16
17 if config.respond_to?(:assets) && !config.assets.nil?
18 config.assets.configure do |env|
19 AutoprefixerRails.install(env, config)
20 end
21 else
22 initializer :setup_autoprefixer, group: :all do |app|
23 AutoprefixerRails.install(app.assets, config) if defined?(app.assets) && !app.assets.nil?
24 end
25 end
26
27 # Read browsers requirements from application or engine config
28 def config
29 params = {}
30
31 roots.each do |root|
32 file = File.join(root, "config/autoprefixer.yml")
33
34 next unless File.exist?(file)
35
36 parsed = ::YAML.load_file(file)
37 next unless parsed
38
39 params = parsed
40
41 break
42 end
43
44 params = params.symbolize_keys
45 params[:env] ||= Rails.env.to_s
46 params
47 end
48
49 def roots
50 [Rails.application.root] + Rails::Engine.subclasses.map(&:root)
51 end
52 end
53 end
54 rescue LoadError
55 end