smart_asset 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  class SmartAsset
2
- VERSION = "0.3.4" unless defined?(::SmartAsset::VERSION)
2
+ VERSION = "0.4.0" unless defined?(::SmartAsset::VERSION)
3
3
  end
data/lib/smart_asset.rb CHANGED
@@ -30,7 +30,15 @@ class SmartAsset
30
30
  dest = @dest[type]
31
31
  dir = "#{@pub}/#{@sources[type]}"
32
32
  ext = ext_from_type type
33
+ version = {}
34
+
35
+ # Read version yaml
36
+ if File.exists?(version_path = "#{dest}/#{type}.yml")
37
+ version = YAML::load(File.read(version_path))
38
+ end
39
+
33
40
  FileUtils.mkdir_p dest
41
+
34
42
  (@config[type] || {}).each do |package, files|
35
43
  next if ENV['PACKAGE'] && ENV['PACKAGE'] != package
36
44
  if files
@@ -49,7 +57,9 @@ class SmartAsset
49
57
  modified = modified.sort.last
50
58
  next unless modified
51
59
 
52
- unless File.exists?(output = "#{dest}/#{modified}_#{package}.#{ext}")
60
+ # If package changed or package file doesn't exist
61
+ output = "#{dest}/#{modified}_#{package}.#{ext}"
62
+ if version[package] != files || !File.exists?(output)
53
63
  data = []
54
64
 
55
65
  # Join files in package
@@ -83,6 +93,19 @@ class SmartAsset
83
93
  end
84
94
  end
85
95
  end
96
+
97
+ # Delete removed packages
98
+ (version.keys - (@config[type] || {}).keys).each do |package|
99
+ Dir["#{dest}/*[0-9]_#{package}.#{ext}"].each do |old|
100
+ FileUtils.rm old
101
+ end
102
+ end
103
+
104
+ # Write version yaml file
105
+ if @config[type]
106
+ puts version_path
107
+ File.open(version_path, 'w') { |f| f.write(YAML::dump(@config[type])) }
108
+ end
86
109
  end
87
110
 
88
111
  def load_config(root, relative_config=nil)
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 3
8
7
  - 4
9
- version: 0.3.4
8
+ - 0
9
+ version: 0.4.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Winton Welsh
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-09 00:00:00 -08:00
17
+ date: 2010-12-10 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency