Class: Assette::Config
- Inherits:
-
Object
- Object
- Assette::Config
- Defined in:
- lib/assette/config.rb
Defined Under Namespace
Classes: Builder
Constant Summary collapse
- MULTIPLES =
%w{file_path asset_host}.freeze
- SINGLES =
%w{asset_dir templates_path template_format cache_method template_preloader template_partial asset_version_file uglifier minify less sass}.freeze
- BLOCKS =
%w{after_compile cachebuster_string}.freeze
- OPTIONS =
begin arr = MULTIPLES.collect do |m| "#{m}s" end arr += SINGLES arr += BLOCKS end.freeze
- DEFAULTS =
{ :asset_dir => 'assets', :asset_version_file => 'assets/version', :asset_hosts => [], :file_paths => %w{public}, :templates_path => 'app/templates', :template_format => 'AT.t[{*path*}] = {*template*};', :after_compile => Proc.new {}, :cachebuster_string => Proc.new {Git.open('.').log.first.sha[0...8] rescue Time.now.strftime("%y%m%d_%H%M%S")}, :uglifier => {:copyright => false, :mangle => false}, :less => {}, :sass => {} }.freeze
Instance Attribute Summary collapse
-
#compiling ⇒ Object
Returns the value of attribute compiling.
- #env ⇒ Object
-
#minifying ⇒ Object
Returns the value of attribute minifying.
-
#sha ⇒ Object
Returns the value of attribute sha.
Class Method Summary collapse
Instance Method Summary collapse
- #asset_host(i) ⇒ Object
- #asset_hosts? ⇒ Boolean
- #build_target ⇒ Object
- #compiled_path(str) ⇒ Object
- #compiling? ⇒ Boolean
- #dev? ⇒ Boolean
- #env?(e) ⇒ Boolean
- #find_file_from_relative_path(path) ⇒ Object
- #find_target_from_relative_path(path) ⇒ Object
-
#initialize(args = {}) ⇒ Config
constructor
A new instance of Config.
- #minify? ⇒ Boolean
- #minifying? ⇒ Boolean
- #prod? ⇒ Boolean
Constructor Details
#initialize(args = {}) ⇒ Config
Returns a new instance of Config.
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/assette/config.rb', line 50 def initialize args = {} args = DEFAULTS.merge(args||{}) args.each do |k,v| begin var = v.dup.freeze rescue TypeError var = v end instance_variable_set "@#{k}", var end end |
Instance Attribute Details
#compiling ⇒ Object
Returns the value of attribute compiling.
33 34 35 |
# File 'lib/assette/config.rb', line 33 def compiling @compiling end |
#env ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/assette/config.rb', line 63 def env return @env if @env case when defined?(ENVIRONMENT) ENVIRONMENT when defined?(Merb) Merb.env when defined?(Rails) Rails.env else ENV['RACK_ENV'] || ENV['RAILS_ENV'] end end |
#minifying ⇒ Object
Returns the value of attribute minifying.
33 34 35 |
# File 'lib/assette/config.rb', line 33 def @minifying end |
#sha ⇒ Object
Returns the value of attribute sha.
33 34 35 |
# File 'lib/assette/config.rb', line 33 def sha @sha end |
Class Method Details
Instance Method Details
#asset_host(i) ⇒ Object
133 134 135 136 |
# File 'lib/assette/config.rb', line 133 def asset_host i return '' unless asset_hosts? @asset_hosts[i % @asset_hosts.size] end |
#asset_hosts? ⇒ Boolean
109 110 111 |
# File 'lib/assette/config.rb', line 109 def asset_hosts? !@asset_hosts.empty? end |
#build_target ⇒ Object
105 106 107 |
# File 'lib/assette/config.rb', line 105 def build_target @asset_dir end |
#compiled_path(str) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/assette/config.rb', line 138 def compiled_path str str = str.dup if sha case cache_method.to_s when 'path' str = File.join(sha,str) when 'param' str << (str.include?('?') ? '&' : '?') str << 'v=' << sha else warn('No cache compile method set (param or path)') end end str end |
#compiling? ⇒ Boolean
113 114 115 |
# File 'lib/assette/config.rb', line 113 def compiling? !!compiling end |
#dev? ⇒ Boolean
86 87 88 |
# File 'lib/assette/config.rb', line 86 def dev? !prod? end |
#env?(e) ⇒ Boolean
78 79 80 |
# File 'lib/assette/config.rb', line 78 def env? e env == e end |
#find_file_from_relative_path(path) ⇒ Object
90 91 92 93 94 95 |
# File 'lib/assette/config.rb', line 90 def find_file_from_relative_path path a = Assette.config.file_paths.find do |pp| File.exist?(File.join(pp,path)) end File.join(a,path) end |
#find_target_from_relative_path(path) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/assette/config.rb', line 97 def find_target_from_relative_path path Assette.config.file_paths.find do |p| Assette::Reader.possible_targets(File.join(p,path)).find do |pp| File.exist?(pp) end end end |
#minify? ⇒ Boolean
117 118 119 |
# File 'lib/assette/config.rb', line 117 def minify? !!minify end |
#minifying? ⇒ Boolean
121 122 123 |
# File 'lib/assette/config.rb', line 121 def !!(@minifying && minify?) end |
#prod? ⇒ Boolean
82 83 84 |
# File 'lib/assette/config.rb', line 82 def prod? env == 'production' end |