Browse files

refactoring. removed namedspace and load path mess

  • Loading branch information...
1 parent d4c311b commit 28242e3f3503fe1a602362d666b3e5b0195a1660 @phuesler phuesler committed Apr 21, 2010
Showing with 38 additions and 43 deletions.
  1. +0 −1 Rakefile
  2. +3 −1 features/support/env.rb
  3. +8 −8 lib/choctop.rb
  4. +2 −3 lib/choctop/appcast.rb
  5. +19 −21 lib/choctop/dmg.rb
  6. +5 −6 spec/choctop_spec.rb
  7. +1 −3 spec/dmg_spec.rb
View
1 Rakefile
@@ -2,7 +2,6 @@ gem 'hoe', '>= 2.3.2'
require 'hoe'
gem 'newgem', '>= 1.5.0'
require 'newgem'
-require './lib/choctop'
Hoe.plugin :newgem
View
4 features/support/env.rb
@@ -1,10 +1,12 @@
-require File.dirname(__FILE__) + "/../../lib/choctop"
+# require File.dirname(__FILE__) + "/../../lib/choctop"
require "rubygems"
require 'cucumber'
require 'spec'
require "activesupport"
+$:.unshift(File.dirname(__FILE__) + '/../../lib')
+require 'choctop'
Before do
@tmp_root = File.dirname(__FILE__) + "/../../tmp"
View
16 lib/choctop.rb
@@ -1,6 +1,3 @@
-$:.unshift(File.dirname(__FILE__)) unless
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
-
require "fileutils"
require "yaml"
require "builder"
@@ -10,10 +7,16 @@
require "active_support"
require "RedCloth"
+require 'choctop/appcast'
+require 'choctop/dmg'
+
class ChocTop
+ include Appcast
+ include Dmg
+
VERSION = '0.11.0'
- attr_accessor :build_opts
+ attr_writer :build_opts
def build_opts
@build_opts ||= ''
end
@@ -311,7 +314,4 @@ def define_tasks
puts configure_dmg_window
end
end
-end
-require "choctop/appcast"
-require "choctop/dmg"
-
+end
View
5 lib/choctop/appcast.rb
@@ -1,4 +1,4 @@
-module ChocTop::Appcast
+module Appcast
def make_build
if skip_build
puts "Skipping build task..."
@@ -120,5 +120,4 @@ def private_key
def dsa_signature
@dsa_signature ||= `openssl dgst -sha1 -binary < "#{pkg}" | openssl dgst -dss1 -sign "#{private_key}" | openssl enc -base64`
end
-end
-ChocTop.send(:include, ChocTop::Appcast)
+end
View
40 lib/choctop/dmg.rb
@@ -1,4 +1,4 @@
-module ChocTop::Dmg
+module Dmg
def prepare_files
self.files = files.inject({}) do |files, file|
path_or_helper, options = file
@@ -14,15 +14,15 @@ def prepare_files
files
end
end
-
+
def copy_files
FileUtils.rm_r(src_folder) if File.exists? src_folder
FileUtils.mkdir_p(src_folder)
files.each do |path, options|
FileUtils.cp_r(path, src_folder)
end
end
-
+
def make_dmg
prepare_files
copy_files
@@ -40,28 +40,28 @@ def make_dmg
configure_applications_icon if include_applications_icon?
configure_dmg_window
end
-
+
def volume_background
".background/background#{File.extname(background_file)}"
end
-
+
def window_position
[50, 100]
end
-
+
def window_bounds
window_position +
window_position.zip(background_bounds).map { |w, b| w + b }
end
-
+
def background_bounds
return [400, 300] unless background_file
background = OSX::NSImage.alloc.initByReferencingFile(background_file).size.to_a
[background.first, background.last + statusbar_height]
end
-
+
def statusbar_height; 20; end
-
+
def configure_volume_icon
if volume_icon
FileUtils.cp(volume_icon, "#{volume_path}/.VolumeIcon.icns")
@@ -110,7 +110,7 @@ def configure_dmg_window
run_applescript(script)
sh "SetFile -a V '#{target_background}'" if background_file
end
-
+
def set_position_of_files
files.map do |file_options|
path, options = file_options
@@ -119,19 +119,19 @@ def set_position_of_files
%Q{set position of item "#{target}" to {#{position}}}
end.join("\n")
end
-
+
def set_position_of_shortcuts
if include_applications_icon?
%Q{set position of item applications_folder to {#{applications_icon_position.join(", ")}}}
else
""
end
end
-
+
def include_applications_icon?
target =~ /.app$/
end
-
+
def configure_applications_icon
run_applescript <<-SCRIPT.gsub(/^ /, ''), "apps_icon_script"
tell application "Finder"
@@ -148,7 +148,7 @@ def configure_applications_icon
OSX::NSWorkspace.sharedWorkspace.setIcon_forFile_options(image, applications_path, nil)
end
end
-
+
def detach_dmg
mounted_paths = `hdiutil info | grep '#{volume_path}' | grep "Apple_HFS"`.split("\n").map { |e| e.split(" ").first }
mounted_paths.each do |path|
@@ -159,22 +159,22 @@ def detach_dmg
end
end
end
-
+
def convert_dmg_readonly
tmp_path = "/tmp/rw.dmg"
FileUtils.mv(pkg, tmp_path)
sh "hdiutil convert '#{tmp_path}' -format UDZO -imagekey zlib-level=9 -o '#{pkg}'"
end
-
+
def add_eula
# TODO support EULA
# hdiutil unflatten $@
# /Developer/Tools/DeRez -useDF SLAResources.rsrc > build/temp/sla.r
# /Developer/Tools/Rez -a build/temp/sla.r -o $@
# hdiutil flatten $@
-
+
end
-
+
def run_applescript(applescript, tmp_file = "choctop-script")
File.open(scriptfile = "/tmp/#{tmp_file}", "w") do |f|
f << applescript
@@ -188,6 +188,4 @@ def run_applescript(applescript, tmp_file = "choctop-script")
end
applescript
end
-end
-ChocTop.send(:include, ChocTop::Dmg)
-
+end
View
11 spec/choctop_spec.rb
@@ -1,7 +1,6 @@
require File.dirname(__FILE__) + '/spec_helper.rb'
describe ChocTop do
- attr_reader :choctop
describe "default" do
before(:each) do
@@ -11,23 +10,23 @@
end
it "should get name from Info.plist['CFBundleExecutable']" do
- choctop.name.should == 'SampleApp'
+ @choctop.name.should == 'SampleApp'
end
it "should get version from Info.plist['CFBundleVersion']" do
- choctop.version.should == '0.1.0'
+ @choctop.version.should == '0.1.0'
end
it "should derive host from Info.plist['SUFeedURL']" do
- choctop.host.should == 'mocra.com'
+ @choctop.host.should == 'mocra.com'
end
it "should derive base_url from Info.plist['SUFeedURL']" do
- choctop.base_url.should == 'http://mocra.com/sample_app'
+ @choctop.base_url.should == 'http://mocra.com/sample_app'
end
it "should derive appcast_filename from Info.plist['SUFeedURL']" do
- choctop.appcast_filename.should == 'my_feed.xml'
+ @choctop.appcast_filename.should == 'my_feed.xml'
end
it "should default the appcast_filename to my_feed.xml" do
View
4 spec/dmg_spec.rb
@@ -1,8 +1,6 @@
require File.dirname(__FILE__) + '/spec_helper.rb'
-describe ChocTop::Dmg do
- attr_reader :choctop
-
+describe Dmg do
before(:each) do
@project_path = File.dirname(__FILE__) + "/../features/fixtures/SampleApp"
FileUtils.chdir(@project_path) do

0 comments on commit 28242e3

Please sign in to comment.