Class: Distil::Product
- Inherits:
-
Object
show all
- Defined in:
- lib/distil/product.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(project, language, variant = nil) ⇒ Product
Returns a new instance of Product.
12
13
14
15
16
17
18
19
|
# File 'lib/distil/product.rb', line 12
def initialize(project, language, variant=nil)
@project= project
@language= language ? language.to_s : language
@files= []
@libraries= []
@assets= Set.new
@variant= variant
end
|
Instance Attribute Details
#assets ⇒ Object
Returns the value of attribute assets.
10
11
12
|
# File 'lib/distil/product.rb', line 10
def assets
@assets
end
|
#files ⇒ Object
Returns the value of attribute files.
10
11
12
|
# File 'lib/distil/product.rb', line 10
def files
@files
end
|
#language ⇒ Object
Returns the value of attribute language.
10
11
12
|
# File 'lib/distil/product.rb', line 10
def language
@language
end
|
#libraries ⇒ Object
Returns the value of attribute libraries.
10
11
12
|
# File 'lib/distil/product.rb', line 10
def libraries
@libraries
end
|
#project ⇒ Object
Returns the value of attribute project.
10
11
12
|
# File 'lib/distil/product.rb', line 10
def project
@project
end
|
#variant ⇒ Object
Returns the value of attribute variant.
10
11
12
|
# File 'lib/distil/product.rb', line 10
def variant
@variant
end
|
Instance Method Details
#build ⇒ Object
74
75
76
77
78
79
80
81
|
# File 'lib/distil/product.rb', line 74
def build
return if up_to_date?
FileUtils.mkdir_p(File.dirname(output_path))
self.send "build_#{variant}"
minimise
gzip
end
|
#clean ⇒ Object
83
84
85
86
87
88
|
# File 'lib/distil/product.rb', line 83
def clean
FileUtils.rm output_path if File.exists?(output_path)
return unless RELEASE_VARIANT==variant
FileUtils.rm minimised_filename if File.exists?(minimised_filename)
FileUtils.rm gzip_filename if File.exists?(gzip_filename)
end
|
#filename ⇒ Object
31
32
33
34
35
36
|
# File 'lib/distil/product.rb', line 31
def filename
filename= "#{project.name}"
filename << "-#{language}" if language
filename << "-#{variant}" if variants.length>1
filename << ".#{content_type}"
end
|
#gzip ⇒ Object
108
109
110
111
112
113
|
# File 'lib/distil/product.rb', line 108
def gzip
return unless RELEASE_VARIANT==variant
Zlib::GzipWriter.open(gzip_filename) do |gz|
gz.write File.read(minimised_filename)
end
end
|
#gzip_filename ⇒ Object
104
105
106
|
# File 'lib/distil/product.rb', line 104
def gzip_filename
@gzip_filename ||= "#{minimised_filename}.gz"
end
|
#handles_file?(file) ⇒ Boolean
42
43
44
45
46
|
# File 'lib/distil/product.rb', line 42
def handles_file?(file)
return (file.extension==content_type) &&
(language.nil? || file.language.nil? || file.language==language)
end
|
#include_file(file) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/distil/product.rb', line 48
def include_file(file)
if file.is_a?(Library)
return true if @libraries.include?(file)
@libraries << file
return true
end
return true if @files.include?(file)
if handles_file?(file)
@files << file
@assets.merge(file.assets) if file.assets
end
end
|
#minimise ⇒ Object
99
100
101
102
|
# File 'lib/distil/product.rb', line 99
def minimise
return unless RELEASE_VARIANT==variant
system("java -jar #{COMPRESSOR} --type #{content_type} -o \"#{minimised_filename}\" \"#{output_path}\"")
end
|
#minimised_filename ⇒ Object
90
91
92
93
94
95
96
97
|
# File 'lib/distil/product.rb', line 90
def minimised_filename
@minimised_filename if @minimised_filename
minimised_filename= "#{project.name}"
minimised_filename << "-#{language}" if language
minimised_filename << ".#{content_type}"
@minimised_filename= File.join(project.output_path, minimised_filename)
end
|
21
22
23
24
25
26
27
28
29
|
# File 'lib/distil/product.rb', line 21
def
return @notice_comment if @notice_comment
notice_text= project.notice_text
return @notice_command= "" if !notice_text || notice_text.empty?
@notice_comment= "/*!\n "
@notice_comment<< project.notice_text.split("\n").join("\n ")
@notice_comment<< "\n */\n"
end
|
#output_path ⇒ Object
38
39
40
|
# File 'lib/distil/product.rb', line 38
def output_path
@output_path ||= File.join(project.output_path, filename)
end
|
#up_to_date? ⇒ Boolean
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/distil/product.rb', line 63
def up_to_date?
count= files.length
return true if 0==@files.length
return false unless File.exists?(output_path)
product_last_modified= File.stat(output_path).mtime
files.each { |f|
return false if f.last_modified > product_last_modified
}
true
end
|