Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

refactoring. removed namedspace and load path mess

  • Loading branch information...
commit 28242e3f3503fe1a602362d666b3e5b0195a1660 1 parent d4c311b
Patrick phuesler authored
1  Rakefile
@@ -2,7 +2,6 @@ gem 'hoe', '>= 2.3.2'
2 2 require 'hoe'
3 3 gem 'newgem', '>= 1.5.0'
4 4 require 'newgem'
5   -require './lib/choctop'
6 5
7 6 Hoe.plugin :newgem
8 7
4 features/support/env.rb
... ... @@ -1,10 +1,12 @@
1   -require File.dirname(__FILE__) + "/../../lib/choctop"
  1 +# require File.dirname(__FILE__) + "/../../lib/choctop"
2 2
3 3 require "rubygems"
4 4 require 'cucumber'
5 5 require 'spec'
6 6
7 7 require "activesupport"
  8 +$:.unshift(File.dirname(__FILE__) + '/../../lib')
  9 +require 'choctop'
8 10
9 11 Before do
10 12 @tmp_root = File.dirname(__FILE__) + "/../../tmp"
16 lib/choctop.rb
... ... @@ -1,6 +1,3 @@
1   -$:.unshift(File.dirname(__FILE__)) unless
2   - $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3   -
4 1 require "fileutils"
5 2 require "yaml"
6 3 require "builder"
@@ -10,10 +7,16 @@
10 7 require "active_support"
11 8 require "RedCloth"
12 9
  10 +require 'choctop/appcast'
  11 +require 'choctop/dmg'
  12 +
13 13 class ChocTop
  14 + include Appcast
  15 + include Dmg
  16 +
14 17 VERSION = '0.11.0'
15 18
16   - attr_accessor :build_opts
  19 + attr_writer :build_opts
17 20 def build_opts
18 21 @build_opts ||= ''
19 22 end
@@ -311,7 +314,4 @@ def define_tasks
311 314 puts configure_dmg_window
312 315 end
313 316 end
314   -end
315   -require "choctop/appcast"
316   -require "choctop/dmg"
317   -
  317 +end
5 lib/choctop/appcast.rb
... ... @@ -1,4 +1,4 @@
1   -module ChocTop::Appcast
  1 +module Appcast
2 2 def make_build
3 3 if skip_build
4 4 puts "Skipping build task..."
@@ -120,5 +120,4 @@ def private_key
120 120 def dsa_signature
121 121 @dsa_signature ||= `openssl dgst -sha1 -binary < "#{pkg}" | openssl dgst -dss1 -sign "#{private_key}" | openssl enc -base64`
122 122 end
123   -end
124   -ChocTop.send(:include, ChocTop::Appcast)
  123 +end
40 lib/choctop/dmg.rb
... ... @@ -1,4 +1,4 @@
1   -module ChocTop::Dmg
  1 +module Dmg
2 2 def prepare_files
3 3 self.files = files.inject({}) do |files, file|
4 4 path_or_helper, options = file
@@ -14,7 +14,7 @@ def prepare_files
14 14 files
15 15 end
16 16 end
17   -
  17 +
18 18 def copy_files
19 19 FileUtils.rm_r(src_folder) if File.exists? src_folder
20 20 FileUtils.mkdir_p(src_folder)
@@ -22,7 +22,7 @@ def copy_files
22 22 FileUtils.cp_r(path, src_folder)
23 23 end
24 24 end
25   -
  25 +
26 26 def make_dmg
27 27 prepare_files
28 28 copy_files
@@ -40,28 +40,28 @@ def make_dmg
40 40 configure_applications_icon if include_applications_icon?
41 41 configure_dmg_window
42 42 end
43   -
  43 +
44 44 def volume_background
45 45 ".background/background#{File.extname(background_file)}"
46 46 end
47   -
  47 +
48 48 def window_position
49 49 [50, 100]
50 50 end
51   -
  51 +
52 52 def window_bounds
53 53 window_position +
54 54 window_position.zip(background_bounds).map { |w, b| w + b }
55 55 end
56   -
  56 +
57 57 def background_bounds
58 58 return [400, 300] unless background_file
59 59 background = OSX::NSImage.alloc.initByReferencingFile(background_file).size.to_a
60 60 [background.first, background.last + statusbar_height]
61 61 end
62   -
  62 +
63 63 def statusbar_height; 20; end
64   -
  64 +
65 65 def configure_volume_icon
66 66 if volume_icon
67 67 FileUtils.cp(volume_icon, "#{volume_path}/.VolumeIcon.icns")
@@ -110,7 +110,7 @@ def configure_dmg_window
110 110 run_applescript(script)
111 111 sh "SetFile -a V '#{target_background}'" if background_file
112 112 end
113   -
  113 +
114 114 def set_position_of_files
115 115 files.map do |file_options|
116 116 path, options = file_options
@@ -119,7 +119,7 @@ def set_position_of_files
119 119 %Q{set position of item "#{target}" to {#{position}}}
120 120 end.join("\n")
121 121 end
122   -
  122 +
123 123 def set_position_of_shortcuts
124 124 if include_applications_icon?
125 125 %Q{set position of item applications_folder to {#{applications_icon_position.join(", ")}}}
@@ -127,11 +127,11 @@ def set_position_of_shortcuts
127 127 ""
128 128 end
129 129 end
130   -
  130 +
131 131 def include_applications_icon?
132 132 target =~ /.app$/
133 133 end
134   -
  134 +
135 135 def configure_applications_icon
136 136 run_applescript <<-SCRIPT.gsub(/^ /, ''), "apps_icon_script"
137 137 tell application "Finder"
@@ -148,7 +148,7 @@ def configure_applications_icon
148 148 OSX::NSWorkspace.sharedWorkspace.setIcon_forFile_options(image, applications_path, nil)
149 149 end
150 150 end
151   -
  151 +
152 152 def detach_dmg
153 153 mounted_paths = `hdiutil info | grep '#{volume_path}' | grep "Apple_HFS"`.split("\n").map { |e| e.split(" ").first }
154 154 mounted_paths.each do |path|
@@ -159,22 +159,22 @@ def detach_dmg
159 159 end
160 160 end
161 161 end
162   -
  162 +
163 163 def convert_dmg_readonly
164 164 tmp_path = "/tmp/rw.dmg"
165 165 FileUtils.mv(pkg, tmp_path)
166 166 sh "hdiutil convert '#{tmp_path}' -format UDZO -imagekey zlib-level=9 -o '#{pkg}'"
167 167 end
168   -
  168 +
169 169 def add_eula
170 170 # TODO support EULA
171 171 # hdiutil unflatten $@
172 172 # /Developer/Tools/DeRez -useDF SLAResources.rsrc > build/temp/sla.r
173 173 # /Developer/Tools/Rez -a build/temp/sla.r -o $@
174 174 # hdiutil flatten $@
175   -
  175 +
176 176 end
177   -
  177 +
178 178 def run_applescript(applescript, tmp_file = "choctop-script")
179 179 File.open(scriptfile = "/tmp/#{tmp_file}", "w") do |f|
180 180 f << applescript
@@ -188,6 +188,4 @@ def run_applescript(applescript, tmp_file = "choctop-script")
188 188 end
189 189 applescript
190 190 end
191   -end
192   -ChocTop.send(:include, ChocTop::Dmg)
193   -
  191 +end
11 spec/choctop_spec.rb
... ... @@ -1,7 +1,6 @@
1 1 require File.dirname(__FILE__) + '/spec_helper.rb'
2 2
3 3 describe ChocTop do
4   - attr_reader :choctop
5 4
6 5 describe "default" do
7 6 before(:each) do
@@ -11,23 +10,23 @@
11 10 end
12 11
13 12 it "should get name from Info.plist['CFBundleExecutable']" do
14   - choctop.name.should == 'SampleApp'
  13 + @choctop.name.should == 'SampleApp'
15 14 end
16 15
17 16 it "should get version from Info.plist['CFBundleVersion']" do
18   - choctop.version.should == '0.1.0'
  17 + @choctop.version.should == '0.1.0'
19 18 end
20 19
21 20 it "should derive host from Info.plist['SUFeedURL']" do
22   - choctop.host.should == 'mocra.com'
  21 + @choctop.host.should == 'mocra.com'
23 22 end
24 23
25 24 it "should derive base_url from Info.plist['SUFeedURL']" do
26   - choctop.base_url.should == 'http://mocra.com/sample_app'
  25 + @choctop.base_url.should == 'http://mocra.com/sample_app'
27 26 end
28 27
29 28 it "should derive appcast_filename from Info.plist['SUFeedURL']" do
30   - choctop.appcast_filename.should == 'my_feed.xml'
  29 + @choctop.appcast_filename.should == 'my_feed.xml'
31 30 end
32 31
33 32 it "should default the appcast_filename to my_feed.xml" do
4 spec/dmg_spec.rb
... ... @@ -1,8 +1,6 @@
1 1 require File.dirname(__FILE__) + '/spec_helper.rb'
2 2
3   -describe ChocTop::Dmg do
4   - attr_reader :choctop
5   -
  3 +describe Dmg do
6 4 before(:each) do
7 5 @project_path = File.dirname(__FILE__) + "/../features/fixtures/SampleApp"
8 6 FileUtils.chdir(@project_path) do

0 comments on commit 28242e3

Please sign in to comment.
Something went wrong with that request. Please try again.