lib/chocbomb/tools/dmg.rb in chocbomb-0.0.0 vs lib/chocbomb/tools/dmg.rb in chocbomb-0.0.1
- old
+ new
@@ -4,11 +4,11 @@
module Tools
class DMG
attr_accessor :chocbomb
def initialize(cb)
@chocbomb = cb
- @files = {}
+ @files_for_dmg = {}
end
def self.detach(cb)
self.new(cb).detach
end
@@ -31,12 +31,12 @@
p e
end
end
end
- def make
- @files = chocbomb.files.inject({}) do |files, file|
+ def make
+ @files_for_dmg = chocbomb.files.inject({}) do |files, file|
path_or_helper, options = file
path = case path_or_helper
when Symbol
chocbomb.send path_or_helper
when Proc
@@ -46,17 +46,22 @@
end
if path && File.exists?(path)
files[path] = options
options[:name] ||= File.basename(path)
end
+ if path =~ %r{\.webloc$}
+ files[path] = options
+ options[:name] ||= File.basename(path)
+ options[:link] = true
+ end
files
end
-
+
FileUtils.rm_r(chocbomb.dmg_src_folder) if File.exists? chocbomb.dmg_src_folder
FileUtils.mkdir_p(chocbomb.dmg_src_folder)
- @files.each do |path, options|
+ @files_for_dmg.each do |path, options|
if options[:link]
webloc = <<-WEBLOC.gsub(/^ /, '')
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
@@ -65,12 +70,12 @@
<string>#{options[:url]}</string>
</dict>
</plist>
WEBLOC
- target = File.join(dmg_src_folder, options[:name])
- File.new(target).print webloc
+ target = File.join(chocbomb.dmg_src_folder, options[:name])
+ File.open(target, 'w').write(webloc)
else
target = File.join(chocbomb.dmg_src_folder, options[:name])
FileUtils.copy_entry(path, target)
if options[:exclude]
exclude_list = options[:exclude].is_a?(Array) ? options[:exclude] : [options[:exclude].to_s]
@@ -164,10 +169,10 @@
return [400, 300] unless chocbomb.background_file
return ChocBomb::Tools::Images.size(chocbomb.background_file)
end
def set_position_of_files
- @files.map do |file_options|
+ @files_for_dmg.map do |file_options|
path, options = file_options
target = options[:name]
position = options[:position].join(", ")
%Q{set position of item "#{target}" to {#{position}}}
end.join("\n")
\ No newline at end of file