Class: DynamicAssets::Reference
- Inherits:
-
Object
- Object
- DynamicAssets::Reference
show all
- Defined in:
- lib/dynamic_assets/reference.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attrs = {}) ⇒ Reference
Returns a new instance of Reference.
21
22
23
24
|
# File 'lib/dynamic_assets/reference.rb', line 21
def initialize(attrs = {})
@name = attrs[:name]
@member_names = attrs[:member_names]
end
|
Instance Attribute Details
Returns the value of attribute name.
7
8
9
|
# File 'lib/dynamic_assets/reference.rb', line 7
def name
@name
end
|
Class Method Details
.new_for_type(type, attrs = {}) ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/dynamic_assets/reference.rb', line 13
def self.new_for_type(type, attrs = {})
case type
when :stylesheets then StylesheetReference
when :javascripts then JavascriptReference
else raise "unknown type: #{type}"
end.new attrs
end
|
Instance Method Details
#content(context, for_signature = false) ⇒ Object
54
55
56
57
58
59
|
# File 'lib/dynamic_assets/reference.rb', line 54
def content(context, for_signature = false)
@context = context
s = combine_content for_signature
s = minify s if DynamicAssets::Manager.minify? && !for_signature
s
end
|
31
32
33
|
# File 'lib/dynamic_assets/reference.rb', line 31
def formats
raise "subclasses of #{self.class} should implement this method to return an array of formats"
end
|
#member_names ⇒ Object
39
40
41
|
# File 'lib/dynamic_assets/reference.rb', line 39
def member_names
@member_names ||= [name]
end
|
#member_names=(some_names) ⇒ Object
35
36
37
|
# File 'lib/dynamic_assets/reference.rb', line 35
def member_names=(some_names)
@member_names = some_names
end
|
#member_root ⇒ Object
47
48
49
50
51
52
|
# File 'lib/dynamic_assets/reference.rb', line 47
def member_root
return @member_root if @member_root
possible_roots = ["#{Rails.root}/app/assets/#{type.to_s}", "#{Rails.root}/app/views/#{type.to_s}"]
@member_root = File.find_existing(possible_roots) || possible_roots.first
end
|
#minify(content_string) ⇒ Object
72
73
74
|
# File 'lib/dynamic_assets/reference.rb', line 72
def minify(content_string)
raise "subclasses of #{self.class} should implement this method"
end
|
43
44
45
|
# File 'lib/dynamic_assets/reference.rb', line 43
def paths
member_names.map { |member_name| path_for_member_name member_name }
end
|
#signature(context) ⇒ Object
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/dynamic_assets/reference.rb', line 61
def signature(context)
(ENV['ASSET_VERSION'] || "") + Digest::SHA1.hexdigest(content(context, true))
end
|