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,45 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleDevelopmentRegion</key>
6
+ <string>English</string>
7
+ <key>CFBundleExecutable</key>
8
+ <string><%= config_name %></string>
9
+ <key>CFBundleIconFile</key>
10
+ <string><%= config_icon %></string>
11
+ <key>CFBundleIdentifier</key>
12
+ <string><%= config_id %></string>
13
+ <key>CFBundleInfoDictionaryVersion</key>
14
+ <string>6.0</string>
15
+ <key>CFBundleName</key>
16
+ <string><%= config_name %></string>
17
+ <key>CFBundlePackageType</key>
18
+ <string>APPL</string>
19
+ <key>CFBundleSignature</key>
20
+ <string>WRUN</string>
21
+ <key>CFBundleVersion</key>
22
+ <string>0.8.0</string>
23
+ <key>CFBundleDocumentTypes</key>
24
+ <array>
25
+ <dict>
26
+ <key>CFBundleTypeExtensions</key>
27
+ <array>
28
+ <string>*</string>
29
+ </array>
30
+ <key>CFBundleTypeMIMETypes</key>
31
+ <array>
32
+ <string>*/*</string>
33
+ </array>
34
+ <key>CFBundleTypeName</key>
35
+ <string>Any</string>
36
+ <key>CFBundleTypeRole</key>
37
+ <string>Viewer</string>
38
+ <key>LSTypeIsPackage</key>
39
+ <false/>
40
+ <key>NSPersistentStoreTypeKey</key>
41
+ <string>Binary</string>
42
+ </dict>
43
+ </array>
44
+ </dict>
45
+ </plist>
Binary file
Binary file
data/bowline.gemspec CHANGED
@@ -1,18 +1,22 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
1
4
  # -*- encoding: utf-8 -*-
2
5
 
3
6
  Gem::Specification.new do |s|
4
7
  s.name = %q{bowline}
5
- s.version = "0.4.6"
8
+ s.version = "0.5.0"
6
9
 
7
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
11
  s.authors = ["Alex MacCaw"]
9
- s.date = %q{2009-08-05}
12
+ s.date = %q{2009-12-20}
10
13
  s.default_executable = %q{bowline-gen}
11
14
  s.description = %q{Ruby/JS GUI framework}
12
15
  s.email = %q{alex@leadthinking.com}
13
16
  s.executables = ["bowline-gen"]
14
17
  s.extra_rdoc_files = [
15
- "README.txt"
18
+ "README.txt",
19
+ "TODO"
16
20
  ]
17
21
  s.files = [
18
22
  ".gitignore",
@@ -20,10 +24,15 @@ Gem::Specification.new do |s|
20
24
  "MIT-LICENSE",
21
25
  "README.txt",
22
26
  "Rakefile",
27
+ "TODO",
23
28
  "VERSION",
24
- "assets/jquery.bowline.js",
29
+ "assets/bowline.js",
25
30
  "assets/jquery.chain.js",
26
31
  "assets/jquery.js",
32
+ "assets/json2.js",
33
+ "assets/osx/Info.plist.erb",
34
+ "assets/osx/bowline.png",
35
+ "assets/osx/makeicns",
27
36
  "bin/bowline-gen",
28
37
  "bowline.gemspec",
29
38
  "examples/account.rb",
@@ -32,10 +41,8 @@ Gem::Specification.new do |s|
32
41
  "examples/twitter.html",
33
42
  "examples/users.rb",
34
43
  "lib/bowline.rb",
35
- "lib/bowline/async.rb",
36
44
  "lib/bowline/binders.rb",
37
- "lib/bowline/binders/collection.rb",
38
- "lib/bowline/binders/singleton.rb",
45
+ "lib/bowline/commands/build.rb",
39
46
  "lib/bowline/commands/console.rb",
40
47
  "lib/bowline/commands/generate.rb",
41
48
  "lib/bowline/commands/run.rb",
@@ -47,6 +54,21 @@ Gem::Specification.new do |s|
47
54
  "lib/bowline/dependencies/lib/dependencies/dependency.rb",
48
55
  "lib/bowline/dependencies/lib/dependencies/repository.rb",
49
56
  "lib/bowline/dependencies/lib/ext/rubygems.rb",
57
+ "lib/bowline/desktop.rb",
58
+ "lib/bowline/desktop/app.rb",
59
+ "lib/bowline/desktop/bridge.rb",
60
+ "lib/bowline/desktop/clipboard.rb",
61
+ "lib/bowline/desktop/dialog.rb",
62
+ "lib/bowline/desktop/dock.rb",
63
+ "lib/bowline/desktop/host.rb",
64
+ "lib/bowline/desktop/js.rb",
65
+ "lib/bowline/desktop/misc.rb",
66
+ "lib/bowline/desktop/network.rb",
67
+ "lib/bowline/desktop/proxy.rb",
68
+ "lib/bowline/desktop/sound.rb",
69
+ "lib/bowline/desktop/window.rb",
70
+ "lib/bowline/desktop/window_manager.rb",
71
+ "lib/bowline/desktop/window_methods.rb",
50
72
  "lib/bowline/ext/array.rb",
51
73
  "lib/bowline/ext/class.rb",
52
74
  "lib/bowline/ext/object.rb",
@@ -57,18 +79,22 @@ Gem::Specification.new do |s|
57
79
  "lib/bowline/generators/helper.rb",
58
80
  "lib/bowline/generators/migration.rb",
59
81
  "lib/bowline/generators/model.rb",
82
+ "lib/bowline/generators/window.rb",
60
83
  "lib/bowline/helpers.rb",
61
84
  "lib/bowline/initializer.rb",
62
- "lib/bowline/jquery.rb",
63
- "lib/bowline/observer.rb",
85
+ "lib/bowline/library.rb",
86
+ "lib/bowline/local_model.rb",
87
+ "lib/bowline/logging.rb",
88
+ "lib/bowline/platform.rb",
64
89
  "lib/bowline/tasks/app.rake",
65
90
  "lib/bowline/tasks/bowline.rb",
66
91
  "lib/bowline/tasks/database.rake",
67
92
  "lib/bowline/tasks/gems.rake",
93
+ "lib/bowline/tasks/libs.rake",
68
94
  "lib/bowline/tasks/log.rake",
69
95
  "lib/bowline/tasks/misc.rake",
70
96
  "lib/bowline/version.rb",
71
- "lib/bowline/window.rb",
97
+ "lib/bowline/watcher.rb",
72
98
  "templates/Rakefile",
73
99
  "templates/binder.rb",
74
100
  "templates/config/application.yml",
@@ -77,15 +103,21 @@ Gem::Specification.new do |s|
77
103
  "templates/config/environment.rb",
78
104
  "templates/gitignore",
79
105
  "templates/helper.rb",
106
+ "templates/main_window.rb",
80
107
  "templates/migration.rb",
81
108
  "templates/model.rb",
82
109
  "templates/public/icon.png",
83
110
  "templates/public/index.html",
84
111
  "templates/public/javascripts/application.js",
85
112
  "templates/public/stylesheets/application.css",
113
+ "templates/script/build",
86
114
  "templates/script/console",
115
+ "templates/script/generate",
87
116
  "templates/script/init",
88
- "templates/script/run"
117
+ "templates/script/run",
118
+ "templates/window.rb",
119
+ "vendor/pathname.rb",
120
+ "vendor/progressbar.rb"
89
121
  ]
90
122
  s.homepage = %q{http://github.com/maccman/bowline}
91
123
  s.rdoc_options = ["--charset=UTF-8"]
@@ -105,12 +137,16 @@ Gem::Specification.new do |s|
105
137
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
106
138
  s.add_runtime_dependency(%q<templater>, [">= 0.3.2"])
107
139
  s.add_runtime_dependency(%q<activesupport>, [">= 2.3.2"])
140
+ s.add_runtime_dependency(%q<rubyzip2>, [">= 2.0.1"])
108
141
  else
109
142
  s.add_dependency(%q<templater>, [">= 0.3.2"])
110
143
  s.add_dependency(%q<activesupport>, [">= 2.3.2"])
144
+ s.add_dependency(%q<rubyzip2>, [">= 2.0.1"])
111
145
  end
112
146
  else
113
147
  s.add_dependency(%q<templater>, [">= 0.3.2"])
114
148
  s.add_dependency(%q<activesupport>, [">= 2.3.2"])
149
+ s.add_dependency(%q<rubyzip2>, [">= 2.0.1"])
115
150
  end
116
151
  end
152
+
data/lib/bowline.rb CHANGED
@@ -1,21 +1,24 @@
1
1
  Thread.abort_on_exception = true
2
2
 
3
3
  module Bowline
4
- # The raw JavaScript window object
5
- def self.js
6
- Window.new
4
+ def lib_path
5
+ File.expand_path(
6
+ File.join(File.dirname(__FILE__), *%w[..])
7
+ )
7
8
  end
9
+ module_function :lib_path
8
10
 
9
- # Change which page we're on
10
- def self.show_view(name)
11
- js.location = "app://public/#{name}.html"
11
+ def assets_path
12
+ File.join(lib_path, "assets")
12
13
  end
14
+ module_function :assets_path
13
15
 
14
- class Base
16
+ module Base
15
17
  end
16
18
  end
17
19
 
18
20
  $LOAD_PATH << File.dirname(__FILE__)
21
+ $LOAD_PATH << File.join(Bowline.lib_path, "vendor")
19
22
 
20
23
  require 'bowline/version'
21
24
 
@@ -24,15 +27,32 @@ require 'bowline/ext/array'
24
27
  require 'bowline/ext/class'
25
28
  require 'bowline/ext/string'
26
29
 
27
- require 'bowline/window'
28
- require 'bowline/async'
30
+ require 'bowline/logging'
31
+ require 'bowline/watcher'
32
+ require 'bowline/local_model'
33
+
34
+ require 'bowline/platform'
35
+ require 'bowline/library'
36
+
37
+ require 'bowline/desktop'
38
+ require 'bowline/desktop/app'
39
+ require 'bowline/desktop/bridge'
40
+ require 'bowline/desktop/clipboard'
41
+ require 'bowline/desktop/dialog'
42
+ require 'bowline/desktop/dock'
43
+ require 'bowline/desktop/host'
44
+ require 'bowline/desktop/misc'
45
+ require 'bowline/desktop/network'
46
+ require 'bowline/desktop/sound'
47
+ require 'bowline/desktop/window_methods'
48
+ require 'bowline/desktop/window'
49
+ require 'bowline/desktop/js'
50
+ require 'bowline/desktop/proxy'
51
+ require 'bowline/desktop/bridge'
52
+ require 'bowline/desktop/window_manager.rb'
53
+
29
54
  require 'bowline/helpers'
30
55
  require 'bowline/dependencies/lib/dependencies'
31
56
  require 'bowline/initializer'
32
57
 
33
- require 'bowline/jquery'
34
- require 'bowline/observer'
35
-
36
- require 'bowline/binders'
37
- require 'bowline/binders/collection'
38
- require 'bowline/binders/singleton'
58
+ require 'bowline/binders'
@@ -1,165 +1,202 @@
1
1
  module Bowline
2
2
  module Binders
3
3
  class Base
4
- class << self
5
- # See Bowline::js
6
- def js
7
- Bowline::js
8
- end
4
+ extend Bowline::Watcher::Base
5
+ extend Bowline::Desktop::Bridge::ClassMethods
6
+ js_expose
9
7
 
10
- # Equivalent of the 'jQuery' function
11
- def jquery
12
- @@jquery ||= JQuery.new
8
+ class << self
9
+ def windows
10
+ @windows ||= []
13
11
  end
14
-
15
- # See the Observer class
16
- def observer
17
- @observer ||= Observer.new
12
+
13
+ # Called by JS when first bound
14
+ def setup(window)
15
+ self.windows << window
16
+ self.items = all
17
+ true
18
18
  end
19
19
 
20
- # See Bowline::logger
21
- def logger
22
- Bowline::logger
20
+ def js_invoke(window, method, *args)
21
+ if method == :setup
22
+ setup(window)
23
+ else
24
+ send(method, *args)
25
+ end
23
26
  end
24
-
25
- # See Bowline::show_view
26
- def show_view(*args)
27
- Bowline::show_view(*args)
27
+
28
+ def instance_invoke(id, meth, *args) #:nodoc:
29
+ self.new(id).send(meth, *args)
28
30
  end
29
31
 
30
- def params
31
- @params
32
+ def find(id)
33
+ klass.find(id)
32
34
  end
33
-
34
- def params=(p) #:nodoc:
35
- case p
36
- when String
37
- # Params comes in a string (since it's a
38
- # serialized form) - we need to make it into
39
- # a nestled hash. Stolen from Ramaze
40
- m = proc {|_,o,n|o.merge(n,&m)}
41
- @params = params.inject({}) do |hash, (key, value)|
42
- parts = key.split(/[\]\[]+/)
43
- hash.merge(parts.reverse.inject(value) { |x, i| {i => x} }, &m)
44
- end
45
- else
46
- @params = p
47
- end
35
+
36
+ def all
37
+ klass.all
48
38
  end
49
39
 
50
- def elements
51
- @elements
40
+ def items=(items) #:nodoc:
41
+ bowline.populate(name, items.to_js).call
52
42
  end
53
43
 
54
- def setup(d) #:nodoc:
55
- @elements ||= []
56
- @elements << d
57
- self.item_sync!
44
+ def created(item) #:nodoc:
45
+ bowline.created(
46
+ name,
47
+ item.id,
48
+ item.to_js
49
+ ).call
58
50
  end
59
51
 
60
- def trigger(event, data = nil)
61
- @elements ||= []
62
- @elements.map {|e|
63
- e.trigger(format_event(event), data)
64
- }
52
+ def updated(item) #:nodoc:
53
+ bowline.updated(
54
+ name,
55
+ item.id,
56
+ item.to_js
57
+ ).call
65
58
  end
66
59
 
67
- def loading(&block)
68
- trigger(:loading, true)
69
- yield
70
- trigger(:loading, false)
60
+ def removed(item) #:nodoc:
61
+ bowline.removed(
62
+ name,
63
+ item.id
64
+ ).call
71
65
  end
66
+
67
+ protected
68
+ # Associate the binder with a model
69
+ # to setup callbacks so changes to the
70
+ # model are automatically reflected in
71
+ # the view. Usage:
72
+ # expose Post
73
+ #
74
+ # When the exposed class is created/updated/deleted
75
+ # the binder's callbacks are executed and the view
76
+ # updated accordingly.
77
+ #
78
+ # klass needs to respond to:
79
+ # * all
80
+ # * find(id)
81
+ # * after_create(method)
82
+ # * after_update(method)
83
+ # * after_destroy(method)
84
+ #
85
+ # klass instance needs to respond to:
86
+ # * id
87
+ #
88
+ # You can override .to_js on the model instance
89
+ # in order to return specific attributes for the view
90
+ def expose(klass)
91
+ @klass = klass
92
+ @klass.after_create(method(:created))
93
+ @klass.after_update(method(:updated))
94
+ @klass.after_destroy(method(:removed))
95
+ end
96
+
97
+ # Returns class set by the 'expose' method
98
+ def klass
99
+ @klass || raise("klass not set - see expose method")
100
+ end
101
+
102
+ # JavaScript proxy to the page:
103
+ # page.myFunc(1,2,3).call
104
+ def page
105
+ Bowline::Desktop::Proxy.new(
106
+ windows.length == 1 ? windows.first : windows
107
+ )
108
+ end
109
+
110
+ # JavaScript proxy to the Bowline object:
111
+ # bowline.log("msg").call
112
+ def bowline
113
+ page.Bowline
114
+ end
72
115
 
73
- def instance(el) #:nodoc:
74
- self.new(el).method(:send)
75
- end
76
-
77
- def inherited(child) #:nodoc:
78
- return if self == Bowline::Binders::Base
79
- return if child == Bowline::Binders::Singleton
80
- return if child == Bowline::Binders::Collection
81
- name = child.name.underscore
82
- name = name.split('/').last
83
- js.send("bowline_#{name}_setup=", child.method(:setup))
84
- js.send("bowline_#{name}_instance=", child.method(:instance))
85
- js.send("bowline_#{name}=", child.method(:send))
86
- end
116
+ # Javascript proxy to jQuery:
117
+ # jquery.getJSON("http://example.com")
118
+ def jquery
119
+ page.jQuery
120
+ end
87
121
 
88
- def format_event(name) #:nodoc:
89
- name.is_a?(Array) ?
90
- name.join('.') :
91
- name.to_s
92
- end
122
+ # See Bowline::logger
123
+ def logger
124
+ Bowline::logger
125
+ end
126
+
127
+ # Trigger events on all elements
128
+ # bound to this binder:
129
+ # trigger(:reload, {:key => :value})
130
+ def trigger(event, data = nil)
131
+ bowline.trigger(
132
+ name,
133
+ format_event(event),
134
+ data
135
+ ).call
136
+ end
137
+
138
+ # Helper method to trigger a loading
139
+ # event either side of a block:
140
+ # loading {
141
+ # # Slow code, e.g. http call
142
+ # }
143
+ def loading(&block)
144
+ trigger(:loading, true)
145
+ yield
146
+ trigger(:loading, false)
147
+ end
148
+
149
+ def format_event(name) #:nodoc:
150
+ name.is_a?(Array) ?
151
+ name.join('.') :
152
+ name.to_s
153
+ end
93
154
  end
94
155
 
95
156
  attr_reader :element
96
157
  attr_reader :item
97
-
98
- def initialize(element, *args) #:nodoc:
99
- # jQuery element
100
- @element = element
101
- # Calling chain.js 'item' function
102
- @item = element.item()
103
- if @item
104
- # If possible, find Ruby object
105
- @item = self.class.find(@item._id.to_i)
106
- end
107
- end
108
-
109
- # Trigger jQuery events on this element
110
- def trigger(event, data = nil)
111
- self.element.trigger(
112
- self.class.format_event(event),
113
- data
114
- )
115
- end
116
-
117
- # Raw DOM element
118
- def dom
119
- self.element[0]
120
- end
121
-
122
- # Shortcut methods
123
-
124
- # See self.class.show_view
125
- def show_view(*args)
126
- self.class.show_view(*args)
158
+
159
+ # Instance of an element on the view.
160
+ #
161
+ # item.destroy
162
+ # element.highlight.call
163
+ def initialize(id, *args) #:nodoc:
164
+ @element = self.class.bowline.element(
165
+ self.class.name, id
166
+ )
167
+ @item = self.class.find(id)
127
168
  end
169
+
170
+ protected
171
+ # Trigger jQuery events on this element:
172
+ # trigger(:highlight)
173
+ def trigger(event, data = nil)
174
+ element.trigger(
175
+ self.class.format_event(event),
176
+ data
177
+ ).call
178
+ end
179
+
180
+ # Remove element from the view
181
+ def remove!
182
+ self.class.removed(item)
183
+ end
128
184
 
129
- # See self.class.js
130
- def js
131
- self.class.js
132
- end
133
- alias :page :js
185
+ # Shortcut methods
134
186
 
135
- # See self.class.jquery
136
- def jquery
137
- self.class.jquery
138
- end
187
+ # See self.class.js
188
+ def page
189
+ self.class.page
190
+ end
139
191
 
140
- # See self.class.observer
141
- def observer
142
- self.class.observer
143
- end
192
+ # See self.class.jquery
193
+ def jquery
194
+ self.class.jquery
195
+ end
144
196
 
145
- # See self.class.logger
146
- def logger
147
- self.class.logger
148
- end
149
-
150
- private
151
- # This is just a unique identifier
152
- # for the item - and isn't
153
- # used in the dom
154
- def item_id
155
- if item.respond_to?(:dom_id)
156
- item.dom_id
157
- else
158
- [
159
- item.id,
160
- self.class.name.underscore
161
- ].join("_")
162
- end
197
+ # See self.class.logger
198
+ def logger
199
+ self.class.logger
163
200
  end
164
201
  end
165
202
  end