Class: Bunto::Assets::Env
- Inherits:
-
Sprockets::Environment
- Object
- Sprockets::Environment
- Bunto::Assets::Env
- Defined in:
- lib/bunto/assets/env.rb
Class Attribute Summary collapse
-
.past ⇒ Object
Returns the value of attribute past.
Instance Attribute Summary collapse
-
#bunto ⇒ Object
readonly
Returns the value of attribute bunto.
-
#used ⇒ Object
readonly
Returns the value of attribute used.
Class Method Summary collapse
Instance Method Summary collapse
-
#all_assets ⇒ Object
———————————————————————- Merged form of ‘#extra_assets` ———————————————————————-.
-
#all_unparsed_assets ⇒ Object
———————————————————————-.
-
#asset_config ⇒ Object
———————————————————————-.
-
#baseurl ⇒ Object
———————————————————————-.
-
#cached ⇒ Object
———————————————————————-.
-
#cdn? ⇒ Boolean
———————————————————————-.
-
#compress?(what) ⇒ Boolean
———————————————————————-.
-
#dev? ⇒ Boolean
———————————————————————-.
-
#digest? ⇒ Boolean
———————————————————————-.
-
#excludes ⇒ Object
———————————————————————-.
-
#extra_assets ⇒ Object
———————————————————————- Assets you tell us you want to always compile, even if you do not use them.
-
#in_cache_dir(*paths) ⇒ Object
———————————————————————- Make sure a path falls withint our cache dir.
-
#initialize(path, bunto = nil) ⇒ Env
constructor
———————————————————————-.
-
#liquid_proxies ⇒ Object
———————————————————————-.
-
#prefix_path(path = nil) ⇒ Object
———————————————————————- Prefix path prefixes the path with the baseurl and the cdn if it exists and is in the right mode to use it.
-
#to_liquid_payload ⇒ Object
———————————————————————-.
-
#write_all ⇒ Object
———————————————————————-.
Constructor Details
#initialize(path, bunto = nil) ⇒ Env
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/bunto/assets/env.rb', line 47 def initialize(path, bunto = nil) bunto, path = path, nil if path.is_a?(Bunto::Site) @bunto = bunto @used = Set.new path ? super(path) : super() Hook.trigger :env, :init do |hook| hook.arity > 0 || 0 > hook.arity ? hook.call(self) : instance_eval(&hook) end end |
Class Attribute Details
.past ⇒ Object
Returns the value of attribute past.
13 14 15 |
# File 'lib/bunto/assets/env.rb', line 13 def past @past end |
Instance Attribute Details
#bunto ⇒ Object (readonly)
Returns the value of attribute bunto.
10 11 12 |
# File 'lib/bunto/assets/env.rb', line 10 def bunto @bunto end |
#used ⇒ Object (readonly)
Returns the value of attribute used.
10 11 12 |
# File 'lib/bunto/assets/env.rb', line 10 def used @used end |
Class Method Details
.context_patches ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/bunto/assets/env.rb', line 191 def context_patches Proc.new do alias _old_asset_path asset_path def asset_path(asset, _ = {}) rtn = _old_asset_path asset return unless rtn path = environment.find_asset(resolve(asset)) environment.parent.used.add(path) rtn end end end |
Instance Method Details
#all_assets ⇒ Object
Merged form of ‘#extra_assets`
77 78 79 |
# File 'lib/bunto/assets/env.rb', line 77 def all_assets Set.new(@used).merge extra_assets end |
#all_unparsed_assets ⇒ Object
29 30 31 32 33 |
# File 'lib/bunto/assets/env.rb', line 29 def all_unparsed_assets @unparsed_assets ||= logical_paths.select do |(_, val)| val.start_with?(bunto.in_source_dir) end end |
#asset_config ⇒ Object
128 129 130 |
# File 'lib/bunto/assets/env.rb', line 128 def asset_config bunto.config["assets"] ||= {} end |
#baseurl ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/bunto/assets/env.rb', line 102 def baseurl ary = [] ary << bunto.config["baseurl"] unless cdn? && asset_config["skip_baseurl_with_cdn"] ary << asset_config[ "prefix"] unless cdn? && asset_config[ "skip_prefix_with_cdn"] File.join(*ary.delete_if do |val| val.nil? || val.empty? end) end |
#cached ⇒ Object
158 159 160 |
# File 'lib/bunto/assets/env.rb', line 158 def cached Cached.new(self) end |
#cdn? ⇒ Boolean
95 96 97 98 |
# File 'lib/bunto/assets/env.rb', line 95 def cdn? !dev? && asset_config.key?("cdn") && \ asset_config["cdn"] end |
#compress?(what) ⇒ Boolean
121 122 123 124 |
# File 'lib/bunto/assets/env.rb', line 121 def compress?(what) !!asset_config["compress"] \ .fetch(what, false) end |
#dev? ⇒ Boolean
115 116 117 |
# File 'lib/bunto/assets/env.rb', line 115 def dev? %W(development test).include?(Bunto.env) end |
#digest? ⇒ Boolean
134 135 136 |
# File 'lib/bunto/assets/env.rb', line 134 def digest? !!asset_config["digest"] end |
#excludes ⇒ Object
21 22 23 24 25 |
# File 'lib/bunto/assets/env.rb', line 21 def excludes excludes = Set.new excludes << strip_path(in_cache_dir) excludes end |
#extra_assets ⇒ Object
Assets you tell us you want to always compile, even if you do not use them. Just like Rails this is probably normally used.
86 87 88 89 90 91 |
# File 'lib/bunto/assets/env.rb', line 86 def extra_assets assets = asset_config["assets"] ||= [] each_logical_path(*assets).map do |v| find_asset v end end |
#in_cache_dir(*paths) ⇒ Object
Make sure a path falls withint our cache dir.
68 69 70 71 |
# File 'lib/bunto/assets/env.rb', line 68 def in_cache_dir(*paths) cache_dir = asset_config["cache"] || ".asset-cache" bunto.in_source_dir(cache_dir, *paths) end |
#liquid_proxies ⇒ Object
60 61 62 |
# File 'lib/bunto/assets/env.rb', line 60 def liquid_proxies self.class.liquid_proxies end |
#prefix_path(path = nil) ⇒ Object
Prefix path prefixes the path with the baseurl and the cdn if it exists and is in the right mode to use it. Otherwise it will only use the baseurl and asset prefix. All of these can be adjusted.
144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/bunto/assets/env.rb', line 144 def prefix_path(path = nil) cdn = asset_config["cdn"] base_url = baseurl path_ = [] path_ << base_url unless base_url.empty? path_ << path unless path.nil? url = cdn && cdn?? File.join(cdn, *path_) : File.join(*path_) url.chomp("/") end |
#to_liquid_payload ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/bunto/assets/env.rb', line 37 def to_liquid_payload bunto.sprockets.all_unparsed_assets.each_with_object({}) do |(key, val), hash| hash[key] = Bunto::Assets::Liquid::Drop.new( val, bunto ) end end |
#write_all ⇒ Object
164 165 166 167 168 169 170 171 |
# File 'lib/bunto/assets/env.rb', line 164 def write_all past = self.class.past ||= Set.new (@used.any?? all_assets : past).each do |obj| if past.add(obj) && path = as_path(obj) obj.write_to path end end end |