bowline 0.4.6 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/Rakefile +1 -0
  2. data/TODO +11 -0
  3. data/VERSION +1 -1
  4. data/assets/bowline.js +194 -0
  5. data/assets/json2.js +479 -0
  6. data/assets/osx/Info.plist.erb +45 -0
  7. data/assets/osx/bowline.png +0 -0
  8. data/assets/osx/makeicns +0 -0
  9. data/bowline.gemspec +47 -11
  10. data/lib/bowline.rb +35 -15
  11. data/lib/bowline/binders.rb +168 -131
  12. data/lib/bowline/commands/build.rb +3 -0
  13. data/lib/bowline/commands/generate.rb +3 -1
  14. data/lib/bowline/commands/run.rb +7 -4
  15. data/lib/bowline/desktop.rb +26 -0
  16. data/lib/bowline/desktop/app.rb +9 -0
  17. data/lib/bowline/desktop/bridge.rb +97 -0
  18. data/lib/bowline/desktop/clipboard.rb +9 -0
  19. data/lib/bowline/desktop/dialog.rb +28 -0
  20. data/lib/bowline/desktop/dock.rb +9 -0
  21. data/lib/bowline/desktop/host.rb +10 -0
  22. data/lib/bowline/desktop/js.rb +92 -0
  23. data/lib/bowline/desktop/misc.rb +9 -0
  24. data/lib/bowline/desktop/network.rb +7 -0
  25. data/lib/bowline/desktop/proxy.rb +94 -0
  26. data/lib/bowline/desktop/sound.rb +8 -0
  27. data/lib/bowline/desktop/window.rb +31 -0
  28. data/lib/bowline/desktop/window_manager.rb +72 -0
  29. data/lib/bowline/desktop/window_methods.rb +70 -0
  30. data/lib/bowline/generators.rb +3 -2
  31. data/lib/bowline/generators/application.rb +8 -5
  32. data/lib/bowline/generators/binder.rb +10 -6
  33. data/lib/bowline/generators/model.rb +9 -0
  34. data/lib/bowline/generators/window.rb +28 -0
  35. data/lib/bowline/helpers.rb +0 -3
  36. data/lib/bowline/initializer.rb +65 -11
  37. data/lib/bowline/library.rb +31 -0
  38. data/lib/bowline/local_model.rb +116 -0
  39. data/lib/bowline/logging.rb +23 -0
  40. data/lib/bowline/platform.rb +73 -0
  41. data/lib/bowline/tasks/app.rake +80 -148
  42. data/lib/bowline/tasks/libs.rake +59 -0
  43. data/lib/bowline/version.rb +2 -2
  44. data/lib/bowline/watcher.rb +91 -0
  45. data/templates/binder.rb +2 -8
  46. data/templates/config/environment.rb +3 -2
  47. data/templates/main_window.rb +7 -0
  48. data/templates/model.rb +1 -1
  49. data/templates/public/index.html +2 -1
  50. data/templates/script/build +3 -0
  51. data/templates/script/generate +3 -0
  52. data/templates/script/init +0 -16
  53. data/templates/window.rb +3 -0
  54. data/vendor/pathname.rb +1099 -0
  55. data/vendor/progressbar.rb +236 -0
  56. metadata +48 -9
  57. data/assets/jquery.bowline.js +0 -156
  58. data/lib/bowline/async.rb +0 -29
  59. data/lib/bowline/binders/collection.rb +0 -59
  60. data/lib/bowline/binders/singleton.rb +0 -31
  61. data/lib/bowline/jquery.rb +0 -31
  62. data/lib/bowline/observer.rb +0 -66
  63. data/lib/bowline/window.rb +0 -19
@@ -0,0 +1,31 @@
1
+ module Bowline
2
+ module Library
3
+ RUBY_LIB_VERSION = "1.9.1"
4
+ RUBY_ARCHLIB_PLATFORM = "i386-darwin9.8.0"
5
+ PROJECT_URL = "http://bowline.s3.amazonaws.com/#{Platform.type}"
6
+ DESKTOP_URL = "#{PROJECT_URL}/bowline-desktop"
7
+ RUBYLIB_URL = "#{PROJECT_URL}/rubylib.zip"
8
+
9
+ def path
10
+ File.expand_path(
11
+ File.join(Gem.user_home, ".bowline")
12
+ )
13
+ end
14
+ module_function :path
15
+
16
+ def desktop_path
17
+ File.join(path, "bowline-desktop")
18
+ end
19
+ module_function :desktop_path
20
+
21
+ def rubylib_path
22
+ File.join(path, "rubylib")
23
+ end
24
+ module_function :rubylib_path
25
+
26
+ def downloaded?
27
+ File.exist?(desktop_path) && File.directory?(rubylib_path)
28
+ end
29
+ module_function :downloaded?
30
+ end
31
+ end
@@ -0,0 +1,116 @@
1
+ module Bowline
2
+ class LocalModel
3
+ extend Watcher::Base
4
+
5
+ watch :before_save, :after_save,
6
+ :before_create, :after_create,
7
+ :before_update, :after_update,
8
+ :before_destroy, :after_destroy
9
+
10
+ @@records = []
11
+
12
+ class << self
13
+ def populate(array)
14
+ array.each {|r| create(r) }
15
+ end
16
+
17
+ def find(id)
18
+ @@records.find {|r| r.id == id } || raise('Unknown Record')
19
+ end
20
+ alias :[] :find
21
+
22
+ def first
23
+ @@records[0]
24
+ end
25
+
26
+ def last
27
+ @@records[-1]
28
+ end
29
+
30
+ def count
31
+ @@records.length
32
+ end
33
+
34
+ def all
35
+ @@records
36
+ end
37
+
38
+ def destroy(id)
39
+ find(id).destroy
40
+ end
41
+
42
+ def destroy_all
43
+ @@records.dup.each {|r| r.destroy }
44
+ end
45
+
46
+ def delete_all
47
+ @@records.clear
48
+ end
49
+
50
+ def create(atts = {})
51
+ rec = self.new(atts)
52
+ rec.save && rec
53
+ end
54
+ end
55
+
56
+ attr_reader :attributes
57
+
58
+ def initialize(atts = {})
59
+ @attributes = {}.with_indifferent_access
60
+ @attributes.replace(atts)
61
+ @attributes[:id] ||= __id__
62
+ @new_record = true
63
+ end
64
+
65
+ # Override __id__
66
+ def id
67
+ @attributes[:id]
68
+ end
69
+
70
+ def update(atts)
71
+ run_callbacks(:before_save)
72
+ run_callbacks(:before_update)
73
+ attributes.merge!(atts)
74
+ run_callbacks(:after_save)
75
+ run_callbacks(:after_update)
76
+ true
77
+ end
78
+
79
+ def save
80
+ run_callbacks(:before_save)
81
+ if @new_record
82
+ run_callbacks(:before_create)
83
+ @@records << self
84
+ run_callbacks(:after_create)
85
+ @new_record = false
86
+ end
87
+ run_callbacks(:after_save)
88
+ true
89
+ end
90
+
91
+ def destroy
92
+ run_callbacks(:before_destroy)
93
+ @@records.delete(self)
94
+ run_callbacks(:after_destroy)
95
+ true
96
+ end
97
+
98
+ def method_missing(method_symbol, *arguments) #:nodoc:
99
+ method_name = method_symbol.to_s
100
+
101
+ case method_name.last
102
+ when "="
103
+ attributes[method_name.first(-1)] = arguments.first
104
+ when "?"
105
+ attributes[method_name.first(-1)]
106
+ else
107
+ attributes.has_key?(method_name) ? attributes[method_name] : super
108
+ end
109
+ end
110
+
111
+ private
112
+ def run_callbacks(callback)
113
+ self.class.watcher.call(callback)
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,23 @@
1
+ module Bowline
2
+ # To be included in classes to allow some basic logging
3
+ module Logging
4
+ def trace(msg=nil)
5
+ Bowline.logger.info(msg)
6
+ end
7
+ module_function :trace
8
+ public :trace
9
+
10
+ def debug(msg=nil)
11
+ Bowline.logger.debug(msg)
12
+ end
13
+ module_function :debug
14
+ public :debug
15
+
16
+ # Log an error backtrace if debugging is activated
17
+ def log_error(e=$!)
18
+ debug "#{e}\n\t" + e.backtrace.join("\n\t")
19
+ end
20
+ module_function :log_error
21
+ public :log_error
22
+ end
23
+ end
@@ -0,0 +1,73 @@
1
+ # naive platform detection for Ruby
2
+ # Based on code by Matt Mower <self@mattmower.com>
3
+ # http://matt.blogs.it/gems/ruby/platform.rb
4
+
5
+ module Bowline
6
+ module Platform
7
+ if RUBY_PLATFORM =~ /darwin/i
8
+ OS = :unix
9
+ IMPL = :macosx
10
+ elsif RUBY_PLATFORM =~ /linux/i
11
+ OS = :unix
12
+ IMPL = :linux
13
+ elsif RUBY_PLATFORM =~ /freebsd/i
14
+ OS = :unix
15
+ IMPL = :freebsd
16
+ elsif RUBY_PLATFORM =~ /netbsd/i
17
+ OS = :unix
18
+ IMPL = :netbsd
19
+ elsif RUBY_PLATFORM =~ /mswin/i
20
+ OS = :win32
21
+ IMPL = :mswin
22
+ elsif RUBY_PLATFORM =~ /cygwin/i
23
+ OS = :unix
24
+ IMPL = :cygwin
25
+ elsif RUBY_PLATFORM =~ /mingw/i
26
+ OS = :win32
27
+ IMPL = :mingw
28
+ elsif RUBY_PLATFORM =~ /bccwin/i
29
+ OS = :win32
30
+ IMPL = :bccwin
31
+ else
32
+ OS = :unknown
33
+ IMPL = :unknown
34
+ end
35
+
36
+ if RUBY_PLATFORM =~ /(i\d86)/i
37
+ ARCH = :x86
38
+ elsif RUBY_PLATFORM =~ /ia64/i
39
+ ARCH = :ia64
40
+ elsif RUBY_PLATFORM =~ /powerpc/i
41
+ ARCH = :powerpc
42
+ elsif RUBY_PLATFORM =~ /alpha/i
43
+ ARCH = :alpha
44
+ else
45
+ ARCH = :unknown
46
+ end
47
+
48
+ def osx?
49
+ IMPL == :macosx
50
+ end
51
+ module_function :osx?
52
+
53
+ def linux?
54
+ IMPL == :linux
55
+ end
56
+ module_function :linux?
57
+
58
+ def win32?
59
+ OS == :win32
60
+ end
61
+ module_function :win32?
62
+
63
+ # Return OS type:
64
+ # Bowline::Platform.type # => :osx
65
+ def type
66
+ return :osx if osx?
67
+ return :linux if linux?
68
+ return :win32 if win32?
69
+ raise "Unknown platform"
70
+ end
71
+ module_function :type
72
+ end
73
+ end
@@ -1,159 +1,91 @@
1
1
  require 'fileutils'
2
+ require 'erb'
3
+ require 'rbconfig'
4
+
2
5
  namespace :app do
3
- task :configure => :environment do
4
- config_path = File.join(APP_ROOT, 'config')
5
- conf = Bowline.configuration
6
-
7
- # Titanium complains about whitespace
8
- manifest = <<-EOF
9
- #appname:#{conf.name}
10
- #appid:#{conf.id}
11
- #publisher:#{conf.publisher}
12
- #image:public/logo.png
13
- #url:#{conf.url}
14
- #guid:0e70684a-dd4b-4d97-9396-6bc01ba10a4e
15
- #desc:#{conf.description}
16
- #type:desktop
17
- runtime:0.4.4
18
- api:0.4.4
19
- tiapp:0.4.4
20
- tifilesystem:0.4.4
21
- tiplatform:0.4.4
22
- tiui:0.4.4
23
- javascript:0.4.4
24
- ruby:0.4.4
25
- tidatabase:0.4.4
26
- tidesktop:0.4.4
27
- tigrowl:0.4.4
28
- timedia:0.4.4
29
- timonkey:0.4.4
30
- tinetwork:0.4.4
31
- tinotification:0.4.4
32
- tiprocess:0.4.4
33
- EOF
34
-
35
- conf.publisher ||= 'Bowline'
36
- conf.copyright ||= "Copyright © #{Time.now.year}"
37
-
38
- tiapp = <<-EOF
39
- <?xml version='1.0' encoding='UTF-8'?>
40
- <ti:app xmlns:ti='http://ti.appcelerator.org'>
41
- <id>#{conf.id}</id>
42
- <name>#{conf.name}</name>
43
- <version>#{conf.version}</version>
44
- <publisher>#{conf.publisher}</publisher>
45
- <url>#{conf.url}</url>
46
- <icon>public/icon.png</icon>
47
- <copyright>#{conf.copyright}</copyright>
48
- <window>
49
- <id>initial</id>
50
- <title>#{conf.name}</title>
51
- <url>app://public/index.html</url>
52
- <width>700</width>
53
- <max-width>3000</max-width>
54
- <min-width>0</min-width>
55
- <height>800</height>
56
- <max-height>3000</max-height>
57
- <min-height>0</min-height>
58
- <fullscreen>false</fullscreen>
59
- <resizable>true</resizable>
60
- <chrome scrollbars="true">true</chrome>
61
- <maximizable>true</maximizable>
62
- <minimizable>true</minimizable>
63
- <closeable>true</closeable>
64
- </window>
65
- </ti:app>
66
- EOF
67
-
68
- FileUtils.cd(config_path) do
69
- File.open('manifest', 'w+') {|f| f.write manifest }
70
- File.open('tiapp.xml', 'w+') {|f| f.write tiapp }
71
- end
72
- end
73
-
74
- desc "Bundles up app into executables"
75
- task :bundle do
76
- build_path = File.join(APP_ROOT, 'build')
77
- app_path = File.join(build_path, 'app')
78
- config_path = File.join(APP_ROOT, 'config')
79
-
80
- tiapp = File.join(config_path, 'tiapp.xml')
81
- manifest = File.join(config_path, 'manifest')
82
- env = File.join(config_path, 'environment.rb')
6
+ namespace :build do
7
+ task :osx => :environment do
8
+ unless Bowline::Library.downloaded?
9
+ Rake::Task["libs:download"].invoke
10
+ end
11
+
12
+ config = Bowline.configuration
13
+ assets_path = File.join(Bowline.assets_path, "osx")
14
+ build_path = File.join(APP_ROOT, "build")
15
+ app_path = File.join(build_path, "#{config.name}.app")
16
+ FileUtils.rm_rf(app_path)
17
+ contents_path = File.join(app_path, "Contents")
18
+ FileUtils.mkdir_p(contents_path)
19
+ FileUtils.cd(contents_path) do
20
+ config_name = config.name
21
+ config_id = config.id
22
+ config_icon = "#{config.name}.icns"
83
23
 
84
- if !File.exists?(tiapp) ||
85
- !File.exists?(manifest)
86
- Rake::Task['app:configure'].invoke
87
- elsif File.mtime(tiapp) < File.mtime(env)
88
- puts "You may need to run 'rake app:configure'"
89
- end
90
-
91
- FileUtils.rm_rf(app_path)
92
- FileUtils.makedirs(app_path)
93
-
94
- FileUtils.cp(tiapp, app_path)
95
- FileUtils.cp(manifest, app_path)
96
-
97
- dirs = Dir[File.join(APP_ROOT, '**')]
98
- dirs.delete(build_path)
99
- dirs.delete(File.join(APP_ROOT, 'log'))
100
- dirs.delete(File.join(APP_ROOT, 'tmp'))
101
- dirs.delete(File.join(APP_ROOT, 'db'))
102
- dirs.delete_if {|i| i =~ /\.svn|\.DS_Store/ }
103
-
104
- FileUtils.cd(app_path) do
105
- FileUtils.makedirs('Resources')
106
- FileUtils.cp_r(dirs, 'Resources')
107
- schema_path = File.join(APP_ROOT, 'db', 'schema.rb')
108
- if File.exists?(schema_path)
24
+ info_plist_path = File.join(assets_path, "Info.plist.erb")
25
+ info_plist = ERB.new(File.read(info_plist_path)).result(binding)
26
+ File.open("Info.plist", "w+") {|f| f.write info_plist }
27
+
28
+ FileUtils.mkdir("Resources")
29
+ FileUtils.cd("Resources") do
30
+ FileUtils.mkdir("English.lproj")
31
+
32
+ # Make icon
33
+ makeicns = File.join(assets_path, "makeicns")
34
+ if config.icon
35
+ makeicns_in = File.join(APP_ROOT, config.icon)
36
+ else
37
+ makeicns_in = File.join(assets_path, "bowline.png")
38
+ end
39
+ makeicns_out = File.expand_path(File.join("English.lproj", config_icon))
40
+ puts "#{makeicns} -in #{makeicns_in} -out #{makeicns_out}"
41
+ `#{makeicns} -in #{makeicns_in} -out #{makeicns_out}`
42
+
43
+ # Copy App
44
+ dirs = Dir[File.join(APP_ROOT, '**')]
45
+ dirs.delete(build_path)
46
+ dirs.delete(File.join(APP_ROOT, 'log'))
47
+ dirs.delete(File.join(APP_ROOT, 'tmp'))
48
+ dirs.delete(File.join(APP_ROOT, 'db', 'migrate'))
49
+ dirs.delete_if {|i| i =~ /\.svn|\.DS_Store/ }
50
+ FileUtils.cp_r(dirs, '.')
51
+
52
+ # Copy Bowline
53
+ bowline_dir = File.join("vendor", "bowline")
54
+ FileUtils.rm_rf(bowline_dir)
55
+ FileUtils.cp_r(
56
+ Pathname.new(Bowline.lib_path).realpath,
57
+ bowline_dir
58
+ )
59
+
60
+ # Copy RB libs - TODO
61
+ FileUtils.mkdir_p(config.rubylib_path)
62
+ FileUtils.cp_r(Bowline::Library.rubylib_path, config.rubylib_path)
63
+ end
64
+
65
+ # Copy Binary
66
+ FileUtils.mkdir("MacOS")
109
67
  FileUtils.cp(
110
- schema_path,
111
- File.join('Resources', 'db')
68
+ Bowline::Library.desktop_path,
69
+ File.join("MacOS", config.name)
112
70
  )
113
71
  end
72
+ FileUtils.chmod_R(0755, app_path)
73
+ FileUtils.chmod(0644, File.join(contents_path, "Info.plist"))
114
74
  end
115
- end
116
-
117
- desc "Use the Titanium SDK to build the app"
118
- task :build do
119
- build_path = File.join(APP_ROOT, 'build')
120
- app_path = File.join(build_path, 'app')
121
75
 
122
- ti_path = ENV['TIPATH'] ? ENV['TIPATH'].dup : begin
123
- if RUBY_PLATFORM =~ /darwin/
124
- '/Library/Application Support/Titanium'
125
- elsif RUBY_PLATFORM =~ /win/
126
- 'C:/ProgramData/Titanium'
127
- elsif RUBY_PLATFORM =~ /linux/
128
- '/opt/titanium'
129
- else
130
- raise "Unknown platform"
131
- end
76
+ task :linux => :environment do
77
+ # Build debian package
78
+ raise "Unimplemented"
132
79
  end
133
-
134
- unless File.directory?(ti_path)
135
- raise "Titanium SDK not found, " \
136
- "install the SDK or " \
137
- "specify the ENV variable TIPATH"
80
+
81
+ task :win32 => :environment do
82
+ # Use Inno Setup
83
+ raise "Unimplemented"
138
84
  end
139
-
140
- ti_lib_path = Dir[File.join(ti_path, "sdk", "*", "*")][-1]
141
-
142
- # Space in osx path
143
- ti_path.gsub!(' ', '\ ')
144
- ti_lib_path.gsub!(' ', '\ ')
145
-
146
- command = ['python']
147
- command << File.join(ti_lib_path, "tibuild.py")
148
- command << "-d #{build_path}"
149
- command << "-s #{ti_path}"
150
- command << "-r" if ENV['TIRUN']
151
- command << "-a #{ti_lib_path}"
152
- command << app_path
153
-
154
- exec(command.join(' '))
155
85
  end
156
- end
157
-
158
- desc "Bundle and build app"
159
- task :app => ["app:bundle", "app:build"]
86
+
87
+ desc "Build app"
88
+ task :build do
89
+ Rake::Task["app:build:#{Bowline::Platform.type}"].invoke
90
+ end
91
+ end