forked from ncuesta/dropzonejs-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
executable file
·78 lines (62 loc) · 2.86 KB
/
Rakefile
File metadata and controls
executable file
·78 lines (62 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env rake
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
Bundler::GemHelper.install_tasks
require 'open-uri'
require 'octokit'
require 'dropzonejs-rails'
desc 'Get latest dropzone js build'
task :get do
puts "Fetching dropzone v#{DropzonejsRails::DROPZONE_VERSION}..."
download_dropzone_file 'dropzone.js', 'vendor/assets/javascripts/dropzone.js'
download_dropzone_file 'css/basic.css', 'vendor/assets/stylesheets/dropzone/basic.css.scss'
download_dropzone_file 'css/dropzone.css', 'vendor/assets/stylesheets/dropzone/dropzone.css.scss'
download_dropzone_file 'images/spritemap.png', 'vendor/assets/images/dropzone/spritemap.png'
download_dropzone_file 'images/spritemap@2x.png', 'vendor/assets/images/dropzone/spritemap@2x.png'
puts "Fixing image paths..."
fix_image_links 'vendor/assets/stylesheets/dropzone/basic.css.scss'
fix_image_links 'vendor/assets/stylesheets/dropzone/dropzone.css.scss'
puts "Done."
end
desc 'Find the latest dropzone js version and get it'
task :check do
latest_version = Octokit.tags('enyo/dropzone').first.name.gsub(/[^\d\.]/, '')
if latest_version != DropzonejsRails::DROPZONE_VERSION
version = File.join(File.dirname(__FILE__), 'lib', 'dropzonejs-rails', 'version.rb')
sed version, {
/DROPZONE_VERSION\s+=\s+'#{DropzonejsRails::DROPZONE_VERSION}'/ => "DROPZONE_VERSION = '#{latest_version}'",
/\sVERSION\s+=\s+'#{DropzonejsRails::VERSION}'/ => " VERSION = '#{new_version}'"
}
readme = File.join(File.dirname(__FILE__), 'README.md')
sed readme, { /\*\*Dropzone v#{DropzonejsRails::DROPZONE_VERSION}\*\*/ => "**Dropzone v#{latest_version}**" }
puts "A new version of dropzone (v#{latest_version}) has been found, and the source files have been accordingly updated.\nYou may now run: `rake get` to get it."
else
puts "The bundled version of dropzone (v#{DropzonejsRails::DROPZONE_VERSION}) already is the latest one."
end
end
def download_dropzone_file(source_file, target_file)
source = "https://raw.github.com/enyo/dropzone/v#{DropzonejsRails::DROPZONE_VERSION}/downloads/#{source_file}"
target = DropzonejsRails::Engine.root.join(target_file)
File.open(target, 'wb+') { |f| f << open(source, 'rb').read }
end
def fix_image_links(css_file)
file_name = DropzonejsRails::Engine.root.join(css_file)
original_css = File.read(file_name)
fixed_css = original_css.gsub(/url\(\"\.\.\/images\/(.+\.png)\"\)/, 'image-path("dropzone/\1")')
File.open(file_name, 'w') { |file| file << fixed_css }
end
def sed(filename, replacements)
contents = File.read(filename)
replacements.each_pair do |pattern, replacement|
contents.gsub!(pattern, replacement)
end
File.write filename, contents
end
def new_version
parts = DropzonejsRails::VERSION.split('.')
parts[2] = parts[2].to_i + 1
parts.join '.'
end