Class: Pakunok::ManagedAsset

Inherits:
Object
  • Object
show all
Defined in:
lib/pakunok/pakunok.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#asyncObject

Returns the value of attribute async.



67
68
69
# File 'lib/pakunok/pakunok.rb', line 67

def async
  @async
end

#cdnObject

Returns the value of attribute cdn.



67
68
69
# File 'lib/pakunok/pakunok.rb', line 67

def cdn
  @cdn
end

#dependenciesObject

Returns the value of attribute dependencies.



67
68
69
# File 'lib/pakunok/pakunok.rb', line 67

def dependencies
  @dependencies
end

#embeddedObject

Returns the value of attribute embedded.



67
68
69
# File 'lib/pakunok/pakunok.rb', line 67

def embedded
  @embedded
end

#pathObject

Returns the value of attribute path.



67
68
69
# File 'lib/pakunok/pakunok.rb', line 67

def path
  @path
end

Instance Method Details

#as_asyncObject



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

Returns:

  • (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_onObject



118
119
120
# File 'lib/pakunok/pakunok.rb', line 118

def depends_on
  full_dependencies.map {|asset| asset.path }
end

#embedObject



83
84
85
86
# File 'lib/pakunok/pakunok.rb', line 83

def embed
  @embedded = true
  return self
end

#embedded?Boolean

Returns:

  • (Boolean)


99
# File 'lib/pakunok/pakunok.rb', line 99

def embedded?;  @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(options)
  @cdn = options[: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