rucola 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. data/ChangeLog +628 -0
  2. data/History.txt +4 -0
  3. data/License.txt +20 -0
  4. data/Manifest.txt +106 -0
  5. data/README.txt +126 -0
  6. data/Rakefile +32 -0
  7. data/TODO +28 -0
  8. data/app_generators/rucola/USAGE +6 -0
  9. data/app_generators/rucola/rucola_generator.rb +112 -0
  10. data/app_generators/rucola/templates/Rakefile.erb +12 -0
  11. data/app_generators/rucola/templates/Rakefile.erb.old +156 -0
  12. data/app_generators/rucola/templates/app/controllers/application_controller.rb +22 -0
  13. data/app_generators/rucola/templates/config/Info.plist.erb +28 -0
  14. data/app_generators/rucola/templates/config/boot.rb +2 -0
  15. data/app_generators/rucola/templates/config/environment.rb +11 -0
  16. data/app_generators/rucola/templates/config/environments/debug.rb +3 -0
  17. data/app_generators/rucola/templates/config/environments/release.rb +3 -0
  18. data/app_generators/rucola/templates/config/environments/test.rb +3 -0
  19. data/app_generators/rucola/templates/config/ib_external_class_defs.yml +13 -0
  20. data/app_generators/rucola/templates/misc/English.lproj/InfoPlist.strings.erb +3 -0
  21. data/app_generators/rucola/templates/misc/English.lproj/MainMenu.nib/classes.nib +40 -0
  22. data/app_generators/rucola/templates/misc/English.lproj/MainMenu.nib/info.nib +18 -0
  23. data/app_generators/rucola/templates/misc/English.lproj/MainMenu.nib/keyedobjects.nib +0 -0
  24. data/app_generators/rucola/templates/misc/main.m.erb +15 -0
  25. data/app_generators/rucola/templates/misc/rb_main.rb.erb +13 -0
  26. data/app_generators/rucola/templates/project.pbxproj.erb +299 -0
  27. data/app_generators/rucola/templates/script/plugin +84 -0
  28. data/app_generators/rucola/templates/test/controllers/test_application_controller.rb +10 -0
  29. data/app_generators/rucola/templates/test/test_helper.rb +10 -0
  30. data/bin/rucola +12 -0
  31. data/config/hoe.rb +71 -0
  32. data/config/requirements.rb +17 -0
  33. data/lib/rucola.rb +3 -0
  34. data/lib/rucola/info_plist.rb +37 -0
  35. data/lib/rucola/initializer.rb +313 -0
  36. data/lib/rucola/nib.rb +99 -0
  37. data/lib/rucola/rucola_support.rb +9 -0
  38. data/lib/rucola/rucola_support/controllers.rb +2 -0
  39. data/lib/rucola/rucola_support/controllers/rc_controller.rb +7 -0
  40. data/lib/rucola/rucola_support/controllers/rc_window_controller.rb +12 -0
  41. data/lib/rucola/rucola_support/core_ext.rb +2 -0
  42. data/lib/rucola/rucola_support/core_ext/objc.rb +4 -0
  43. data/lib/rucola/rucola_support/core_ext/objc/nsobject.rb +22 -0
  44. data/lib/rucola/rucola_support/core_ext/ruby.rb +4 -0
  45. data/lib/rucola/rucola_support/core_ext/ruby/string.rb +21 -0
  46. data/lib/rucola/rucola_support/initialize_hooks.rb +21 -0
  47. data/lib/rucola/rucola_support/models.rb +1 -0
  48. data/lib/rucola/rucola_support/models/rc_document.rb +10 -0
  49. data/lib/rucola/rucola_support/notifications.rb +1 -0
  50. data/lib/rucola/rucola_support/notifications/notifications.rb +146 -0
  51. data/lib/rucola/rucola_support/rc_app.rb +101 -0
  52. data/lib/rucola/tasks/freeze.rake +44 -0
  53. data/lib/rucola/tasks/interface_builder.rake +80 -0
  54. data/lib/rucola/tasks/main.rake +29 -0
  55. data/lib/rucola/tasks/xcode.rake +43 -0
  56. data/lib/rucola/test_helper.rb +57 -0
  57. data/lib/rucola/version.rb +9 -0
  58. data/lib/rucola/xcode.rb +148 -0
  59. data/log/debug.log +0 -0
  60. data/rucola_generators/controller/USAGE +5 -0
  61. data/rucola_generators/controller/controller_generator.rb +84 -0
  62. data/rucola_generators/controller/templates/controller_template.rb.erb +5 -0
  63. data/rucola_generators/controller/templates/test_controller_template.rb.erb +10 -0
  64. data/rucola_generators/document_model/USAGE +5 -0
  65. data/rucola_generators/document_model/document_model_generator.rb +67 -0
  66. data/rucola_generators/document_model/templates/document_model_template.rb.erb +27 -0
  67. data/rucola_generators/document_model/templates/test_document_model_template.rb.erb +10 -0
  68. data/rucola_generators/window_controller/USAGE +6 -0
  69. data/rucola_generators/window_controller/templates/Window.nib/classes.nib.erb +35 -0
  70. data/rucola_generators/window_controller/templates/Window.nib/info.nib +16 -0
  71. data/rucola_generators/window_controller/templates/Window.nib/keyedobjects.nib +0 -0
  72. data/rucola_generators/window_controller/templates/test_window_controller_template.rb.erb +10 -0
  73. data/rucola_generators/window_controller/templates/window_controller_template.rb.erb +19 -0
  74. data/rucola_generators/window_controller/window_controller_generator.rb +74 -0
  75. data/script/destroy +14 -0
  76. data/script/generate +14 -0
  77. data/script/txt2html +74 -0
  78. data/setup.rb +1585 -0
  79. data/tasks/deployment.rake +27 -0
  80. data/tasks/environment.rake +7 -0
  81. data/tasks/website.rake +17 -0
  82. data/test/fixtures/Info.plist +28 -0
  83. data/test/fixtures/MainMenu.nib/classes.nib +32 -0
  84. data/test/fixtures/MainMenu.nib/info.nib +18 -0
  85. data/test/fixtures/MainMenu.nib/keyedobjects.nib +0 -0
  86. data/test/test_controller_generator.rb +75 -0
  87. data/test/test_core_ext.rb +15 -0
  88. data/test/test_document_model_generator.rb +64 -0
  89. data/test/test_generator_helper.rb +20 -0
  90. data/test/test_helper.rb +13 -0
  91. data/test/test_info_plist.rb +31 -0
  92. data/test/test_nib.rb +73 -0
  93. data/test/test_notifications.rb +75 -0
  94. data/test/test_objc_core_ext.rb +37 -0
  95. data/test/test_rc_app.rb +63 -0
  96. data/test/test_rc_document.rb +18 -0
  97. data/test/test_rc_window_controller.rb +13 -0
  98. data/test/test_rucola.rb +11 -0
  99. data/test/test_rucola_generator.rb +87 -0
  100. data/test/test_window_controller_generator.rb +50 -0
  101. data/test/test_xcode.rb +128 -0
  102. data/website/index.html +199 -0
  103. data/website/index.txt +126 -0
  104. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  105. data/website/stylesheets/screen.css +138 -0
  106. data/website/template.rhtml +48 -0
  107. metadata +189 -0
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fileutils'
4
+ require 'net/http'
5
+
6
+ RUCOLA_PLUGINS_URL = 'http://rucola.rubyforge.org/svn/extras/plugins/'
7
+ PLUGIN_DIR = 'vendor/plugins'
8
+
9
+ def get_plugin_index
10
+ return @rucola_plugins unless @rucola_plugins.nil?
11
+
12
+ rucola_plugin_index = Net::HTTP.get(URI.parse(RUCOLA_PLUGINS_URL + "plugin_index"))
13
+
14
+ @rucola_plugins = {}
15
+ rucola_plugin_index.each_line do |line|
16
+ next if line.chomp.empty?
17
+ plugin_name, plugin_description = line.chomp.split("\t")
18
+ @rucola_plugins[plugin_name] = plugin_description
19
+ end
20
+ @rucola_plugins
21
+ end
22
+
23
+ def list_plugins
24
+ rucola_plugins = get_plugin_index
25
+ puts "Available plugins from #{RUCOLA_PLUGINS_URL} are:\n\n"
26
+ puts "- " << rucola_plugins.map { |name, desc| "#{name}: #{desc}" }.sort.join("\n\n- ") << "\n\n"
27
+ exit
28
+ end
29
+
30
+ def install_plugin(plugin)
31
+ if plugin.nil?
32
+ puts "Please specify the name of the plugin or the url to install from.", ''
33
+ banner
34
+ end
35
+
36
+ unless plugin =~ /^[\w\+]+:\/\//
37
+ rucola_plugins = get_plugin_index
38
+ if rucola_plugins.has_key? plugin
39
+ url = RUCOLA_PLUGINS_URL + plugin
40
+ name = plugin
41
+ else
42
+ puts "No plugin was found for: #{plugin}", ''
43
+ list_plugins
44
+ end
45
+ else
46
+ url = plugin
47
+ name = url.split('/').last
48
+ end
49
+
50
+ # do a checkout
51
+ FileUtils.mkdir_p PLUGIN_DIR unless File.exists? PLUGIN_DIR
52
+ IO.popen("svn co #{url} #{PLUGIN_DIR}/#{name}") do |process|
53
+ process.each_line { |line| puts line }
54
+ end
55
+
56
+ # run install.rb if it exists
57
+ install_script = File.join(PLUGIN_DIR, name, 'install.rb')
58
+ if File.exists? install_script
59
+ puts "\n======================================================================================\n\n"
60
+ IO.popen("ruby #{install_script}") do |process|
61
+ process.each_line { |line| puts line }
62
+ end
63
+ puts ''
64
+ end
65
+ end
66
+
67
+ def banner
68
+ puts %{
69
+ Usage: #{__FILE__} [options]
70
+ Options:
71
+ list Lists all plugins from the Rucola plugin repository.
72
+ install PLUGIN Installs PLUGIN from the Rucola plugins repository or a specific svn url.
73
+ }.strip
74
+ exit
75
+ end
76
+
77
+ banner if ARGV.empty?
78
+ case ARGV[0]
79
+ when 'list' then list_plugins
80
+ when 'install' then install_plugin(ARGV[1])
81
+ else
82
+ puts "Unknown option: #{ARGV[0]}", ''
83
+ banner
84
+ end
@@ -0,0 +1,10 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ class TestApplicationController < Test::Unit::TestCase
4
+
5
+ def test_application_controller_initialization
6
+ application_controller = ApplicationController.alloc.init
7
+ assert_instance_of(ApplicationController, application_controller)
8
+ end
9
+
10
+ end
@@ -0,0 +1,10 @@
1
+ ENV['RUBYCOCOA_ENV'] = 'test'
2
+ ENV['RUBYCOCOA_ROOT'] = File.expand_path('../../', __FILE__)
3
+
4
+ require 'rubygems'
5
+ require "test/unit"
6
+ require "mocha"
7
+ require 'rucola'
8
+ require 'rucola/test_helper'
9
+
10
+ require File.expand_path('../../config/boot', __FILE__)
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'rubigen'
3
+
4
+ if %w(-v --version).include? ARGV.first
5
+ require 'newgem/version'
6
+ puts "#{File.basename($0)} #{Newgem::VERSION::STRING}"
7
+ exit(0)
8
+ end
9
+
10
+ require 'rubigen/scripts/generate'
11
+ RubiGen::Base.use_application_sources! :rucola
12
+ RubiGen::Scripts::Generate.new.run(ARGV, :generator => 'rucola')
@@ -0,0 +1,71 @@
1
+ require 'rucola/version'
2
+
3
+ AUTHOR = ['Eloy Duran', 'Justin Palmer'] # can also be an array of Authors
4
+ EMAIL = "e.duran@superalloy.nl"
5
+ DESCRIPTION = "Rucola is an extension for RubyCocoa. It has a application skeleton generator and builds an \"opinionated\" application layout, like the one known from rails. And comes with RubyCocoa specific rake tasks."
6
+ GEM_NAME = 'rucola' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'rucola' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+
11
+ @config_file = "~/.rubyforge/user-config.yml"
12
+ @config = nil
13
+ RUBYFORGE_USERNAME = "unknown"
14
+ def rubyforge_username
15
+ unless @config
16
+ begin
17
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
18
+ rescue
19
+ puts <<-EOS
20
+ ERROR: No rubyforge config file found: #{@config_file}
21
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
23
+ EOS
24
+ exit
25
+ end
26
+ end
27
+ RUBYFORGE_USERNAME.replace @config["username"]
28
+ end
29
+
30
+
31
+ REV = nil
32
+ # UNCOMMENT IF REQUIRED:
33
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
34
+ VERS = Rucola::VERSION::STRING + (REV ? ".#{REV}" : "")
35
+ RDOC_OPTS = ['--quiet', '--title', 'rucola documentation',
36
+ "--opname", "index.html",
37
+ "--line-numbers",
38
+ "--main", "README",
39
+ "--inline-source"]
40
+
41
+ class Hoe
42
+ def extra_deps
43
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
44
+ @extra_deps
45
+ end
46
+ end
47
+
48
+ # Generate all the Rake tasks
49
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
50
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
51
+ p.author = AUTHOR
52
+ p.description = DESCRIPTION
53
+ p.email = EMAIL
54
+ p.summary = DESCRIPTION
55
+ p.url = HOMEPATH
56
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
57
+ p.test_globs = ["test/**/test_*.rb"]
58
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
59
+
60
+ # == Optional
61
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\\n\\n")
62
+ p.extra_deps = ['rubigen', 'rubynode'] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
63
+
64
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
65
+
66
+ end
67
+
68
+ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
69
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
70
+ hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
71
+ hoe.rsync_args = '-av --delete --ignore-errors'
@@ -0,0 +1,17 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
16
+
17
+ require 'rucola'
@@ -0,0 +1,3 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'rucola/version'
3
+ require 'rucola/initializer'
@@ -0,0 +1,37 @@
1
+ require 'osx/cocoa'
2
+
3
+ module Rucola
4
+ class InfoPlist
5
+ def self.open(path)
6
+ new(path)
7
+ end
8
+
9
+ attr_reader :data
10
+
11
+ def initialize(path)
12
+ @path = path
13
+ @data = OSX::NSDictionary.dictionaryWithContentsOfFile(@path)
14
+ end
15
+
16
+ def document_types
17
+ @data['CFBundleDocumentTypes'] ||= []
18
+ @data['CFBundleDocumentTypes']
19
+ end
20
+
21
+ def add_document_type(name, extension, role, icon = '????', os_type = '????')
22
+ document_types.push({
23
+ 'NSDocumentClass' => name,
24
+ 'CFBundleTypeExtensions' => [extension],
25
+ 'CFBundleTypeRole' => role,
26
+ 'CFBundleTypeIconFile' => icon,
27
+ 'CFBundleTypeOSTypes' => [os_type],
28
+ 'CFBundleTypeName' => 'DocumentType'
29
+ })
30
+ end
31
+
32
+ def save
33
+ @data.writeToFile_atomically(@path, true)
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,313 @@
1
+ require 'osx/cocoa'
2
+ require 'pathname'
3
+
4
+ unless ENV['RUBYCOCOA_ENV'].nil?
5
+ RUBYCOCOA_ENV = ENV['RUBYCOCOA_ENV']
6
+ else
7
+ unless ENV['DYLD_LIBRARY_PATH'].nil?
8
+ env = ENV['DYLD_LIBRARY_PATH'].split('/').last.downcase
9
+ if %(debug release).include?(env)
10
+ RUBYCOCOA_ENV = env
11
+ else
12
+ RUBYCOCOA_ENV = 'debug'
13
+ end
14
+ else
15
+ RUBYCOCOA_ENV = 'release'
16
+ end
17
+ end
18
+
19
+ # ActiveRecord uses RAILS_ENV internally to figure out which environment key to parse in
20
+ # database.yml. Since we use the non-standard release and debug environments, we need to
21
+ # set this here
22
+ RAILS_ENV = RUBYCOCOA_ENV
23
+
24
+ unless ENV['RUBYCOCOA_ROOT'].nil?
25
+ # rake will set the RUBYCOCOA_ROOT for debugging purpose
26
+ RUBYCOCOA_ROOT = Pathname.new(ENV['RUBYCOCOA_ROOT'])
27
+ else
28
+ # We are running in debug from xcode, which doesn't set RUBYCOCOA_ROOT.
29
+ # Or we are simply running in release.
30
+ RUBYCOCOA_ROOT =
31
+ if RUBYCOCOA_ENV == 'debug'
32
+ Pathname.new(ENV['DYLD_LIBRARY_PATH'] + "../../../").cleanpath
33
+ else
34
+ Pathname.new(OSX::NSBundle.mainBundle.resourcePath.fileSystemRepresentation)
35
+ end
36
+ end
37
+
38
+ $:.unshift(RUBYCOCOA_ROOT)
39
+
40
+ module Rucola
41
+ # Are we building and running or just running this application by clicking on
42
+ # an executable.
43
+ def building_application?
44
+ ENV['DYLD_LIBRARY_PATH']
45
+ end
46
+ end
47
+
48
+
49
+ # Environment initialization scheme ported/derived from Rails' Initializer.
50
+ require 'erb'
51
+ module Rucola
52
+ # Rails-like Initializer responsible for processing configuration.
53
+ class Initializer
54
+ # The Configuration instance used by this Initializer instance.
55
+ attr_reader :configuration
56
+
57
+ # Load the config/boot.rb file.
58
+ def self.boot
59
+ require RUBYCOCOA_ROOT + 'config/boot'
60
+ end
61
+
62
+ # Run the initializer and start the application. The #process method is run by default which
63
+ # runs all the initialization routines. You can alternatively specify
64
+ # a command to run.
65
+ #
66
+ # OSX::Initializer.run(:set_load_path)
67
+ #
68
+ def self.run(command = :process, configuration = Configuration.new)
69
+ yield configuration if block_given?
70
+ initializer = new configuration
71
+ initializer.send(command)
72
+ start_app unless RUBYCOCOA_ENV == 'test'
73
+ end
74
+
75
+ # Starts the application.
76
+ def self.start_app
77
+ OSX.NSApplicationMain(0, nil)
78
+ end
79
+
80
+ # Create an initializer instance that references the given
81
+ # Configuration instance.
82
+ def initialize(configuration)
83
+ @configuration = configuration
84
+ end
85
+
86
+ # Step through the initialization routines, skipping the active_record
87
+ # routines if active_record isnt' being used.
88
+ def process
89
+ unless ENV['DYLD_LIBRARY_PATH'].nil?
90
+ set_load_path
91
+ copy_load_paths_for_release
92
+ end
93
+
94
+ require_rucola_support
95
+ require_frameworks
96
+ require_ruby_source_files
97
+ load_environment
98
+
99
+ if configuration.use_active_record?
100
+ initialize_database_directories
101
+ initialize_database
102
+ initialize_active_record_settings
103
+ end
104
+ end
105
+
106
+ # Requires all frameworks specified by the Configuration#objc_frameworks
107
+ # list. This is also responsible for including osx/active_record_proxy if
108
+ # use_active_record? is true
109
+ def require_frameworks
110
+ configuration.objc_frameworks.each { |framework| OSX.require_framework(framework) }
111
+ if configuration.use_active_record?
112
+ require 'active_support'
113
+ configuration.active_record = OrderedOptions.new
114
+ require 'active_record'
115
+ require 'osx/active_record_proxy'
116
+ end
117
+ end
118
+
119
+ # Loads the Rucola support library
120
+ def require_rucola_support
121
+ require Pathname.new(__FILE__).dirname + 'rucola_support'
122
+ end
123
+
124
+ # Recursively requires any ruby source file that it finds.
125
+ def require_ruby_source_files_in_dir_recursive(dir)
126
+ dir.children.each do |child|
127
+ if child.directory?
128
+ require_ruby_source_files_in_dir_recursive(child)
129
+ next
130
+ end
131
+ require child if child.basename.to_s =~ /\.rb$/
132
+ end
133
+ end
134
+
135
+ # Loops through the subdirectories of the app/ directory.
136
+ # It requires any ruby file in any of the subdirectories and registers
137
+ # the required file in the hash +@require_ruby_source_files+ with the name
138
+ # of the subdirectory as it's key.
139
+ #
140
+ # require_ruby_source_files # => {:models=>[], :views=>[], :controllers=>[#<Pathname:/src/SampleApp/app/controllers/ApplicationController.rb>]}
141
+ def require_ruby_source_files
142
+ Dir[RUBYCOCOA_ROOT + 'app/**/*.rb'].each do |f|
143
+ require f
144
+ end
145
+ end
146
+
147
+ def initialize_database_directories
148
+ return if configuration.environment == 'debug'
149
+ `mkdir -p '#{configuration.application_support_path}'` unless File.exists?(configuration.application_support_path)
150
+ end
151
+
152
+ def initialize_database
153
+ ActiveRecord::Base.configurations = configuration.database_configuration
154
+ ActiveRecord::Base.logger = Logger.new($stderr)
155
+ ActiveRecord::Base.colorize_logging = false
156
+ ActiveRecord::Base.establish_connection
157
+ ActiveRecord::Base.connection.initialize_schema_information
158
+ end
159
+
160
+ # Initializes active_record settings. The available settings map to the accessors
161
+ # of the ActiveRecord::Base class.
162
+ def initialize_active_record_settings
163
+ configuration.send('active_record').each do |setting, value|
164
+ ActiveRecord::Base.send("#{setting}=", value)
165
+ end
166
+ end
167
+
168
+ def load_application_initializers
169
+ Dir["#{configuration.root_path}/config/initializers/**/*.rb"].sort.each do |initializer|
170
+ load(initializer)
171
+ end
172
+ end
173
+
174
+ # Loads the environment specified by Configuration#environment_path, which
175
+ # can be debug or release
176
+ def load_environment
177
+ return if @environment_loaded
178
+ @environment_loaded = true
179
+
180
+ config = configuration
181
+ constants = self.class.constants
182
+ eval(IO.read(configuration.environment_path), binding, configuration.environment_path)
183
+
184
+ (self.class.constants - constants).each do |const|
185
+ Object.const_set(const, self.class.const_get(const))
186
+ end
187
+ end
188
+
189
+ # Set the paths from which your application will automatically load source files.
190
+ def set_load_path
191
+ load_paths = configuration.load_paths
192
+ load_paths.reverse_each { |dir| $LOAD_PATH.unshift(dir) if File.directory?(dir) } unless RUBYCOCOA_ENV == 'test' # FIXME: why??
193
+ $LOAD_PATH.uniq!
194
+ end
195
+
196
+ # Copy the default load paths to the resource directory for the application if
197
+ # we are building a release, otherwise we do nothing. When in debug mode, the
198
+ # files are loaded directly from your working directory.
199
+ #
200
+ # TODO: Remove debug database from released app if it exists.
201
+ def copy_load_paths_for_release
202
+ return if configuration.environment == 'debug'
203
+ configuration.load_paths.each do |path|
204
+ `cp -R #{path} #{RUBYCOCOA_ROOT}/#{File.basename(path)}` if File.directory?(path)
205
+ end
206
+ end
207
+
208
+ # Now is a good time to load the plugins, because
209
+ # this will give them the chance to alter the
210
+ # behaviour of Rucola before it starts.
211
+ RUBYCOCOA_PLUGINS_ROOT = RUBYCOCOA_ROOT + 'vendor/plugins'
212
+ @@required_plugins = [] # TODO: isn't used yet
213
+ if RUBYCOCOA_PLUGINS_ROOT.exist?
214
+ RUBYCOCOA_PLUGINS_ROOT.children.each do |plugin|
215
+ next unless plugin.directory?
216
+ @@required_plugins.push plugin
217
+ require plugin + 'init.rb'
218
+ end
219
+ end
220
+ end
221
+
222
+ class Configuration
223
+ # The applications base directory
224
+ attr_reader :root_path
225
+
226
+ # The path to the applications support directory
227
+ # <tt>~/Library/Application Support/AppName</tt>
228
+ attr_accessor :application_support_path
229
+
230
+ # List of Objective-C frameworks that should be required
231
+ attr_accessor :objc_frameworks
232
+
233
+ #Stub for setting options on ActiveRecord::Base
234
+ attr_accessor :active_record
235
+
236
+ # Should the active_record framework be loaded.
237
+ attr_accessor :use_active_record
238
+
239
+ # An array of additional paths to prepend to the load path. By default,
240
+ # all +models+, +config+, +controllers+ and +db+ paths are included in this list.
241
+ attr_accessor :load_paths
242
+
243
+ # The path to the database configuration file to use. (Defaults to
244
+ # <tt>config/database.yml</tt>.)
245
+ attr_accessor :database_configuration_file
246
+
247
+
248
+ def initialize
249
+ set_root_path!
250
+ set_application_support_path!
251
+
252
+ self.objc_frameworks = []
253
+ self.load_paths = default_load_paths
254
+ self.database_configuration_file = default_database_configuration_file
255
+ end
256
+
257
+ def set_root_path!
258
+ @root_path = Pathname.new(::RUBYCOCOA_ROOT).realpath.to_s
259
+ end
260
+
261
+ def set_application_support_path!
262
+ # TODO: we might want to set this to something in test mode.
263
+ return if RUBYCOCOA_ENV == 'test'
264
+
265
+ app_name = OSX::NSBundle.mainBundle.bundleIdentifier.to_s.scan(/\w+$/).first
266
+ user_app_support_path = File.join(OSX::NSSearchPathForDirectoriesInDomains(OSX::NSLibraryDirectory, OSX::NSUserDomainMask, true)[0].to_s, "Application Support")
267
+ @application_support_path = File.join(user_app_support_path, app_name)
268
+ end
269
+
270
+ # Returns the value of @use_active_record
271
+ def use_active_record?
272
+ @use_active_record
273
+ end
274
+
275
+ # Returns the value of RUBYCOCOA_ENV
276
+ def environment
277
+ ::RUBYCOCOA_ENV
278
+ end
279
+
280
+ # The path to the current environment's file (development.rb, etc.). By
281
+ # default the file is at <tt>config/environments/#{environment}.rb</tt>.
282
+ def environment_path
283
+ "#{root_path}/config/environments/#{environment}.rb"
284
+ end
285
+
286
+ # Loads and returns the contents of the #database_configuration_file. The
287
+ # contents of the file are processed via ERB before being sent through
288
+ # YAML::load.
289
+ def database_configuration
290
+ db_config = YAML::load(ERB.new(IO.read(database_configuration_file)).result)
291
+ db = db_config[environment]['database']
292
+ db_config[environment]['database'] = environment == 'release' ? "#{application_support_path}/#{db.split('/').last}" : "#{RUBYCOCOA_ROOT}/db/#{db.split('/').last}"
293
+ db_config
294
+ end
295
+
296
+ private
297
+ # Set the load paths, which specifies what directories should be copied over on release.
298
+ # We can't use RUBYCOCOA_ROOT here because when building for release the .app file is the
299
+ # root, instead we need the path to the working directory.
300
+ def default_load_paths
301
+ return if ENV['DYLD_LIBRARY_PATH'].nil?
302
+ paths = %w(
303
+ models
304
+ controllers
305
+ db
306
+ ).map {|dir| "#{Pathname.new(ENV['DYLD_LIBRARY_PATH'] + "../../../").cleanpath}/#{dir}" }.select { |dir| File.directory?(dir) }
307
+ end
308
+
309
+ def default_database_configuration_file
310
+ File.join(root_path, 'config', 'database.yml')
311
+ end
312
+ end
313
+ end