bowline 0.4.6 → 0.5.0

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 (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,72 @@
1
+ module Bowline
2
+ module Desktop
3
+ class WindowManager
4
+ extend Bridge::ClassMethods
5
+ js_expose
6
+
7
+ extend Bowline::Watcher::Base
8
+ watch :on_load
9
+
10
+ class << self
11
+ def windows
12
+ subclasses.map(&:constantize)
13
+ end
14
+
15
+ def shown_windows
16
+ windows.select(&:shown?)
17
+ end
18
+
19
+ def allocated_windows
20
+ windows.select(&:allocated?)
21
+ end
22
+
23
+ # Methods for subclasses:
24
+
25
+ def window
26
+ @window
27
+ end
28
+
29
+ def allocated?
30
+ !!@window
31
+ end
32
+
33
+ def setup
34
+ return unless Desktop.enabled?
35
+ return if @window && !@window.dealocated?
36
+ if self.name == "MainWindow"
37
+ @window = MainWindow.get
38
+ else
39
+ @window = Window.new
40
+ end
41
+ end
42
+
43
+ def eval(*args, &block)
44
+ JS.eval(window, *args, &block)
45
+ end
46
+
47
+ def page
48
+ Proxy.new(window)
49
+ end
50
+
51
+ def loaded?
52
+ @loaded
53
+ end
54
+
55
+ def loaded! # :nodoc:
56
+ @loaded = true
57
+ watcher.call(:on_load)
58
+ true
59
+ end
60
+
61
+ # Delegate most methods to Window
62
+ def method_missing(sym, *args)
63
+ if window && window.respond_to?(sym)
64
+ return window.send(sym, *args)
65
+ end
66
+ # Window won't be around if Bowline::Desktop isn't enabled
67
+ Bowline::Desktop.enabled? ? super : nil
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,70 @@
1
+ module Bowline
2
+ module Desktop
3
+ module WindowMethods
4
+ def center(direction = nil)
5
+ direction =
6
+ case direction
7
+ when :both then Window::BOTH
8
+ when :horizontal then Window::HORIZONTAL
9
+ when :vertical then Window::VERTICAL
10
+ when :center then Window::CENTRE_ON_SCREEN
11
+ else
12
+ Window::BOTH
13
+ end
14
+ _center(direction)
15
+ end
16
+
17
+ def file=(path)
18
+ if path.is_a?(Symbol)
19
+ path = File.join(APP_ROOT, "public", path.to_s)
20
+ end
21
+ if File.extname(path).blank?
22
+ path += ".html"
23
+ end
24
+ path = File.expand_path(path, APP_ROOT)
25
+ self._file = path
26
+ end
27
+ alias :load_file :file=
28
+
29
+ def select_dir(options = {})
30
+ flags = 0
31
+ flags |= Window::FD_OPEN if options[:open]
32
+ flags |= Window::FD_SAVE if options[:save]
33
+ flags |= Window::FD_OVERWRITE_PROMPT if options[:overwrite_prompt]
34
+ flags |= Window::FD_FILE_MUST_EXIST if options[:file_must_exist]
35
+ _select_dir(
36
+ options[:message],
37
+ options[:default_path],
38
+ options[:default_filename],
39
+ options[:default_extension],
40
+ options[:wildcard],
41
+ flags
42
+ )
43
+ end
44
+
45
+ def select_dir(options = {})
46
+ _select_dir(options[:message], options[:default_path])
47
+ end
48
+
49
+ def width=(w)
50
+ set_size(w, -1)
51
+ end
52
+
53
+ def height=(h)
54
+ set_size(h, -1)
55
+ end
56
+
57
+ # Window was shut; setup!
58
+ # needs to be called again
59
+ def dealocated?
60
+ id == -1
61
+ end
62
+
63
+ # The methods won't exist on window
64
+ # if Bowline::Desktop isn't enabled
65
+ def method_missing(sym, *args)
66
+ Bowline::Desktop.enabled? ? raise : nil
67
+ end
68
+ end
69
+ end
70
+ end
@@ -55,6 +55,7 @@ end
55
55
 
56
56
  require "bowline/generators/application"
57
57
  require "bowline/generators/binder"
58
- require "bowline/generators/model"
59
58
  require "bowline/generators/helper"
60
- require "bowline/generators/migration"
59
+ require "bowline/generators/migration"
60
+ require "bowline/generators/model"
61
+ require "bowline/generators/window"
@@ -40,16 +40,19 @@ module Bowline::Generators
40
40
 
41
41
  glob! "script"
42
42
 
43
- file :jquery, "../assets/jquery.js", "public/javascripts/jquery.js"
44
- file :chainjs, "../assets/jquery.chain.js", "public/javascripts/jquery.chain.js"
45
- file :bowlinejs, "../assets/jquery.bowline.js", "public/javascripts/jquery.bowline.js"
43
+ file :jquery, "../assets/jquery.js", "public/javascripts/jquery.js"
44
+ file :chainjs, "../assets/jquery.chain.js", "public/javascripts/jquery.chain.js"
45
+ file :json2js, "../assets/json2.js", "public/javascripts/json2.js"
46
+ file :bowlinejs, "../assets/bowline.js", "public/javascripts/bowline.js"
46
47
 
47
48
  empty_directory :app, "app"
48
49
  empty_directory :models, "app/models"
49
50
  empty_directory :binders, "app/binders"
50
- empty_directory :binders, "app/helpers"
51
- empty_directory :config, "config"
51
+ empty_directory :helpers, "app/helpers"
52
+ empty_directory :windows, "app/windows"
53
+ file :mainwindow, "main_window.rb", "app/windows"
52
54
 
55
+ empty_directory :config, "config"
53
56
  template :environment, "config/environment.rb", "config/environment.rb"
54
57
  ["application.yml", "database.yml", "boot.rb"].each {|action|
55
58
  action = File.join('config', action)
@@ -1,20 +1,24 @@
1
1
  module Bowline::Generators
2
2
  class BinderGenerator < NamedGenerator
3
3
  desc <<-DESC
4
- Generates a new binder, either a collection one, or a singleton one.
4
+ Generates a new binder.
5
5
  DESC
6
6
 
7
+ alias :plain_class_name :class_name
7
8
  def class_name
8
- super + " < Bowline::Binders::#{type.to_s.camel_case}"
9
+ super + "Binder < Bowline::Binders::Base"
9
10
  end
10
11
 
11
- def modules
12
- ['Binders']
12
+ def expose_name
13
+ plain_class_name.singularize
13
14
  end
14
15
 
15
- first_argument :name, :required => true, :desc => "binder name"
16
- option :type, :desc => "Binder type (collection/singleton)", :default => "collection"
16
+ def file_name
17
+ super + "_binder"
18
+ end
17
19
 
20
+ first_argument :name, :required => true, :desc => "binder name"
21
+
18
22
  template :binder do |template|
19
23
  template.source = "binder.rb"
20
24
  template.destination = "app/binders/#{file_name}.rb"
@@ -4,11 +4,20 @@ module Bowline::Generators
4
4
  Generates a new model.
5
5
  DESC
6
6
 
7
+ def class_name
8
+ if local
9
+ super + " < Bowline::LocalModel"
10
+ else
11
+ super + " < ActiveRecord::Base"
12
+ end
13
+ end
14
+
7
15
  def modules
8
16
  []
9
17
  end
10
18
 
11
19
  first_argument :name, :required => true, :desc => "model name"
20
+ second_argument :local, :required => false
12
21
 
13
22
  template :model do |template|
14
23
  template.source = "model.rb"
@@ -0,0 +1,28 @@
1
+ module Bowline::Generators
2
+ class WindowGenerator < NamedGenerator
3
+ desc <<-DESC
4
+ Generates a new window.
5
+ DESC
6
+
7
+ def modules
8
+ []
9
+ end
10
+
11
+ def class_name
12
+ "#{self.name.camel_case}Window"
13
+ end
14
+
15
+ def file_name
16
+ "#{name}_window"
17
+ end
18
+
19
+ first_argument :name, :required => true, :desc => "window name"
20
+
21
+ template :helper do |template|
22
+ template.source = "window.rb"
23
+ template.destination = "app/windows/#{file_name}.rb"
24
+ end
25
+ end
26
+
27
+ add :window, WindowGenerator
28
+ end
@@ -1,7 +1,4 @@
1
1
  module Bowline
2
2
  module Helpers
3
- def self.init
4
- Bowline.js.send("bowline_helper=", method(:send))
5
- end
6
3
  end
7
4
  end
@@ -1,5 +1,3 @@
1
- require 'logger'
2
- require 'set'
3
1
  require 'pathname'
4
2
 
5
3
  module Bowline
@@ -60,6 +58,27 @@ module Bowline
60
58
  @loaded_plugins = []
61
59
  end
62
60
 
61
+ def initialize_ruby
62
+ ruby_path = File.join(configuration.rubylib_path)
63
+ unless File.directory?(ruby_path)
64
+ ruby_path = Bowline::Library.rubylib_path
65
+ return unless File.directory?(ruby_path)
66
+ end
67
+ version = Library::RUBY_LIB_VERSION
68
+ platform = Library::RUBY_ARCHLIB_PLATFORM
69
+ $: << File.join(ruby_path, version) # RUBY_LIB
70
+ $: << File.join(ruby_path, version, platform) # RUBY_ARCHLIB
71
+ $: << File.join(ruby_path, "site_path") # RUBY_SITE_LIB
72
+ $: << File.join(ruby_path, "site_path", version) # RUBY_SITE_LIB2
73
+ $: << File.join(ruby_path, "site_ruby", version, platform) # RUBY_SITE_ARCHLIB
74
+ $: << File.join(ruby_path, "vendor_ruby") # RUBY_VENDOR_LIB
75
+ $: << File.join(ruby_path, "vendor_ruby", version) # RUBY_VENDOR_LIB2
76
+ $: << File.join(ruby_path, "vendor_ruby", version, platform) # RUBY_VENDOR_ARCHLIB
77
+ require File.join(*%w[enc encdb])
78
+ require File.join(*%w[enc trans transdb])
79
+ $:.uniq!
80
+ end
81
+
63
82
  def require_frameworks
64
83
  configuration.frameworks.each { |framework| require(framework.to_s) }
65
84
  end
@@ -218,7 +237,6 @@ module Bowline
218
237
  helpers = configuration.helpers
219
238
  helpers = helpers.map(&:constantize)
220
239
  helpers.each {|h| Helpers.module_eval { extend h } }
221
- Helpers.init
222
240
  end
223
241
 
224
242
  def load_application_classes
@@ -262,14 +280,25 @@ module Bowline
262
280
  end
263
281
 
264
282
  def initialize_js
265
- Bowline.js.bowline_loaded
283
+ return unless Bowline::Desktop.enabled?
284
+ Bowline::Desktop::JS.setup
285
+ Bowline::Desktop::Bridge.setup
286
+ end
287
+
288
+ def initialize_windows
289
+ return unless Bowline::Desktop.enabled?
290
+ MainWindow.setup
291
+ MainWindow.name = configuration.name
292
+ MainWindow.file = configuration.index_path
266
293
  end
267
294
 
268
295
  def process
269
296
  Bowline.configuration = configuration
270
297
 
298
+ initialize_ruby
271
299
  set_load_path
272
300
  initialize_gems
301
+ load_gems
273
302
 
274
303
  require_frameworks
275
304
  set_autoload_paths
@@ -290,7 +319,6 @@ module Bowline
290
319
  initialize_name
291
320
  load_app_config
292
321
 
293
- load_gems
294
322
  load_plugins
295
323
 
296
324
  load_application_initializers
@@ -301,6 +329,7 @@ module Bowline
301
329
  load_application_helpers
302
330
 
303
331
  initialize_js
332
+ initialize_windows
304
333
 
305
334
  Bowline.initialized = true
306
335
  end
@@ -406,6 +435,8 @@ module Bowline
406
435
 
407
436
  attr_accessor :gem_path
408
437
 
438
+ attr_accessor :rubylib_path
439
+
409
440
  # Sets the default +time_zone+. Setting this will enable +time_zone+
410
441
  # awareness for Active Record models and set the Active Record default
411
442
  # timezone to <tt>:utc</tt>.
@@ -417,16 +448,18 @@ module Bowline
417
448
 
418
449
  attr_accessor :initializer_glob
419
450
 
451
+ attr_accessor :index_path
452
+
420
453
  attr_accessor :name
421
454
  attr_accessor :id
422
455
  attr_accessor :version
423
456
  attr_accessor :description
424
- attr_accessor :publisher
425
457
  attr_accessor :url
426
458
  attr_accessor :icon
427
- attr_accessor :sdk
459
+
460
+ attr_accessor :publisher
428
461
  attr_accessor :copyright
429
-
462
+
430
463
  # Create a new Configuration instance, initialized with the default values.
431
464
  def initialize
432
465
  set_root_path!
@@ -444,9 +477,13 @@ module Bowline
444
477
  self.app_config_file = default_app_config_file
445
478
  self.gems = default_gems
446
479
  self.gem_path = default_gem_path
480
+ self.rubylib_path = default_rubylib_path
447
481
  self.plugin_glob = default_plugin_glob
448
482
  self.helper_glob = default_helper_glob
449
483
  self.initializer_glob = default_initalizer_glob
484
+ self.index_path = default_index_path
485
+ self.publisher = default_publisher
486
+ self.copyright = default_copyright
450
487
 
451
488
  for framework in default_frameworks
452
489
  self.send("#{framework}=", Bowline::OrderedOptions.new)
@@ -518,6 +555,7 @@ module Bowline
518
555
  app/models
519
556
  app/remote
520
557
  app/helpers
558
+ app/windows
521
559
  lib
522
560
  vendor
523
561
  ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
@@ -536,6 +574,7 @@ module Bowline
536
574
  app/models
537
575
  app/remote
538
576
  app/helpers
577
+ app/windows
539
578
  ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
540
579
  end
541
580
 
@@ -570,14 +609,17 @@ module Bowline
570
609
  def default_gems
571
610
  gems = []
572
611
  gems << Dependencies::Dependency.new(
573
- "bowline", Bowline::Version::STRING, :lib => false
612
+ "activesupport", :lib => "active_support"
574
613
  )
575
- gems << Dependencies::Dependency.new("activesupport")
576
614
  gems
577
615
  end
578
616
 
617
+ def default_rubylib_path
618
+ File.join(root_path, *%w{ vendor rubylib })
619
+ end
620
+
579
621
  def default_gem_path
580
- File.join(root_path, *%w{ vendor gems })
622
+ File.join(root_path, *%w{ vendor gems })
581
623
  end
582
624
 
583
625
  def default_plugin_glob
@@ -591,6 +633,18 @@ module Bowline
591
633
  def default_initalizer_glob
592
634
  File.join(root_path, *%w{ config initializers **/*.rb })
593
635
  end
636
+
637
+ def default_index_path
638
+ File.join(root_path, *%w{ public index.html })
639
+ end
640
+
641
+ def default_publisher
642
+ "Bowline"
643
+ end
644
+
645
+ def default_copyright
646
+ "Copyright #{Time.now.year}"
647
+ end
594
648
  end
595
649
  end
596
650