Class: Pakunok::ManagedAsset
- Inherits:
-
Object
- Object
- Pakunok::ManagedAsset
- Defined in:
- lib/pakunok/pakunok.rb
Instance Attribute Summary collapse
-
#async ⇒ Object
Returns the value of attribute async.
-
#cdn ⇒ Object
Returns the value of attribute cdn.
-
#dependencies ⇒ Object
Returns the value of attribute dependencies.
-
#embedded ⇒ Object
Returns the value of attribute embedded.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #as_async ⇒ Object
- #asset_url(context) ⇒ Object
- #async? ⇒ Boolean
- #cdn_url(context) ⇒ Object
- #depends_on ⇒ Object
- #embed ⇒ Object
- #embedded? ⇒ Boolean
- #full_dependencies(visit_map = {}) ⇒ Object
-
#initialize(manager, path) ⇒ ManagedAsset
constructor
A new instance of ManagedAsset.
- #needs(*deps) ⇒ Object
- #replace_with(options) ⇒ Object
- #url(context) ⇒ Object
Constructor Details
#initialize(manager, path) ⇒ ManagedAsset
Returns a new instance of ManagedAsset.
69 70 71 72 73 74 |
# File 'lib/pakunok/pakunok.rb', line 69 def initialize(manager, path) @manager, @path = manager, path @async = false @embedded = false @dependencies = [] end |
Instance Attribute Details
#async ⇒ Object
Returns the value of attribute async.
67 68 69 |
# File 'lib/pakunok/pakunok.rb', line 67 def async @async end |
#cdn ⇒ Object
Returns the value of attribute cdn.
67 68 69 |
# File 'lib/pakunok/pakunok.rb', line 67 def cdn @cdn end |
#dependencies ⇒ Object
Returns the value of attribute dependencies.
67 68 69 |
# File 'lib/pakunok/pakunok.rb', line 67 def dependencies @dependencies end |
#embedded ⇒ Object
Returns the value of attribute embedded.
67 68 69 |
# File 'lib/pakunok/pakunok.rb', line 67 def @embedded end |
#path ⇒ Object
Returns the value of attribute path.
67 68 69 |
# File 'lib/pakunok/pakunok.rb', line 67 def path @path end |
Instance Method Details
#as_async ⇒ Object
93 94 95 96 |
# File 'lib/pakunok/pakunok.rb', line 93 def as_async @async = true return self end |
#asset_url(context) ⇒ Object
114 115 116 |
# File 'lib/pakunok/pakunok.rb', line 114 def asset_url(context) context.asset_path path end |
#async? ⇒ Boolean
98 |
# File 'lib/pakunok/pakunok.rb', line 98 def async?; @async end |
#cdn_url(context) ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/pakunok/pakunok.rb', line 106 def cdn_url(context) if cdn.match /^https?:\/\//i cdn else context.request.protocol + cdn end end |
#depends_on ⇒ Object
118 119 120 |
# File 'lib/pakunok/pakunok.rb', line 118 def depends_on full_dependencies.map {|asset| asset.path } end |
#embed ⇒ Object
83 84 85 86 |
# File 'lib/pakunok/pakunok.rb', line 83 def @embedded = true return self end |
#embedded? ⇒ Boolean
99 |
# File 'lib/pakunok/pakunok.rb', line 99 def ; @embedded end |
#full_dependencies(visit_map = {}) ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/pakunok/pakunok.rb', line 122 def full_dependencies(visit_map = {}) return [] if visit_map[self] visit_map[self] = true @dependencies.reverse.map do |asset| asset.full_dependencies(visit_map) + [asset] end.flatten - [self] end |
#needs(*deps) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/pakunok/pakunok.rb', line 76 def needs(*deps) deps.map {|path| @manager.asset(path) }.each do |asset| @dependencies.push asset end return self end |
#replace_with(options) ⇒ Object
88 89 90 91 |
# File 'lib/pakunok/pakunok.rb', line 88 def replace_with() @cdn = [:cdn] return self end |
#url(context) ⇒ Object
102 103 104 |
# File 'lib/pakunok/pakunok.rb', line 102 def url(context) cdn ? cdn_url(context) : asset_url(context) end |