bowline 0.6.3 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,93 @@
1
+ var SuperClass = function(parent){
2
+ var result = function(){
3
+ this.init.apply(this, arguments);
4
+ };
5
+
6
+ result.prototype.init = function(){};
7
+
8
+ if (parent){
9
+ for(var i in parent){
10
+ result[i] = SuperClass.clone(parent[i]);
11
+ }
12
+
13
+ for(var i in parent.prototype){
14
+ result.prototype[i] = SuperClass.clone(parent.prototype[i]);
15
+ }
16
+
17
+ result.parent = parent;
18
+ result.prototype.parent = parent.prototype;
19
+
20
+ result._super = function(){
21
+ var parent = this.parent;
22
+
23
+ var key = this.findProperty(arguments.callee.caller);
24
+ var method = parent[key];
25
+
26
+ if (!method) return;
27
+
28
+ var oldParent = parent;
29
+ var oldFindProperty = this.findProperty;
30
+
31
+ // In case parent method calls super
32
+ this.findProperty = $.proxy(this.findProperty, parent);
33
+ this.parent = parent.parent;
34
+ var value = method.apply(this, arguments);
35
+
36
+ // Reset functions refs
37
+ this.findProperty = oldFindProperty;
38
+ this.parent = oldParent;
39
+
40
+ return value;
41
+ };
42
+ result.prototype._super = result._super;
43
+ }
44
+
45
+ result.fn = result.prototype;
46
+ result.fn._class = result;
47
+
48
+ result.findProperty = function(val){
49
+ for(var key in this)
50
+ if(this[key] == val) return key;
51
+ };
52
+ result.fn.findProperty = result.findProperty;
53
+
54
+ result.extend = function(obj){
55
+ var extended = obj.extended;
56
+ delete obj.extended;
57
+ for(var i in obj){
58
+ result[i] = obj[i];
59
+ }
60
+
61
+ if (extended) extended(result)
62
+ };
63
+
64
+ result.include = function(obj){
65
+ var included = obj.included;
66
+ delete obj.included;
67
+ for(var i in obj){
68
+ result.fn[i] = obj[i];
69
+ }
70
+
71
+ if (included) included(result)
72
+ };
73
+
74
+ result.aliasMethod = function(newName, oldName){
75
+ this[newName] = this[oldName];
76
+ };
77
+ result.fn.aliasMethod = result.aliasMethod;
78
+
79
+ result.aliasMethodChain = function(method, name){
80
+ this.aliasMethod(method + "Without" + name, method);
81
+ this.aliasMethod(method, method + "With" + name);
82
+ };
83
+ result.fn.aliasMethodChain = result.aliasMethodChain;
84
+
85
+ return result;
86
+ };
87
+
88
+ SuperClass.clone = function(obj){
89
+ if (typeof obj == "function") return obj;
90
+ if (typeof obj != "object") return obj;
91
+ if (jQuery.isArray(obj)) return jQuery.extend([], obj);
92
+ return jQuery.extend({}, obj);
93
+ };
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bowline}
8
- s.version = "0.6.3"
8
+ s.version = "0.9.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alex MacCaw"]
12
- s.date = %q{2010-04-06}
12
+ s.date = %q{2010-05-21}
13
13
  s.default_executable = %q{bowline-gen}
14
14
  s.description = %q{Ruby/JS GUI framework}
15
15
  s.email = %q{alex@leadthinking.com}
@@ -26,19 +26,15 @@ Gem::Specification.new do |s|
26
26
  "Rakefile",
27
27
  "TODO",
28
28
  "VERSION",
29
- "assets/animations.css",
29
+ "assets/application.js",
30
+ "assets/bowline.chain.js",
30
31
  "assets/bowline.js",
31
- "assets/bowline.menu.js",
32
- "assets/bowline.state.js",
33
- "assets/bowline.test.js",
34
- "assets/bowline.view.js",
35
32
  "assets/jquery.chain.js",
36
- "assets/jquery.dataset.js",
37
33
  "assets/jquery.js",
38
- "assets/json2.js",
39
34
  "assets/osx/Info.plist.erb",
40
35
  "assets/osx/bowline.png",
41
36
  "assets/osx/makeicns",
37
+ "assets/superclass.js",
42
38
  "bin/bowline-gen",
43
39
  "bowline.gemspec",
44
40
  "examples/example.js",
@@ -150,18 +146,21 @@ Gem::Specification.new do |s|
150
146
  s.add_runtime_dependency(%q<templater>, [">= 0.3.2"])
151
147
  s.add_runtime_dependency(%q<activesupport>, [">= 3.0.0.beta"])
152
148
  s.add_runtime_dependency(%q<rubyzip2>, [">= 2.0.1"])
153
- s.add_runtime_dependency(%q<supermodel>, [">= 0"])
149
+ s.add_runtime_dependency(%q<bundler08>, [">= 0.8.5"])
150
+ s.add_runtime_dependency(%q<supermodel>, [">= 0.1.3"])
154
151
  else
155
152
  s.add_dependency(%q<templater>, [">= 0.3.2"])
156
153
  s.add_dependency(%q<activesupport>, [">= 3.0.0.beta"])
157
154
  s.add_dependency(%q<rubyzip2>, [">= 2.0.1"])
158
- s.add_dependency(%q<supermodel>, [">= 0"])
155
+ s.add_dependency(%q<bundler08>, [">= 0.8.5"])
156
+ s.add_dependency(%q<supermodel>, [">= 0.1.3"])
159
157
  end
160
158
  else
161
159
  s.add_dependency(%q<templater>, [">= 0.3.2"])
162
160
  s.add_dependency(%q<activesupport>, [">= 3.0.0.beta"])
163
161
  s.add_dependency(%q<rubyzip2>, [">= 2.0.1"])
164
- s.add_dependency(%q<supermodel>, [">= 0"])
162
+ s.add_dependency(%q<bundler08>, [">= 0.8.5"])
163
+ s.add_dependency(%q<supermodel>, [">= 0.1.3"])
165
164
  end
166
165
  end
167
166
 
@@ -1,4 +1,4 @@
1
- $('#users').bowlineBind('UsersBinder');
1
+ $('#users').bowlineChain('UsersBinder');
2
2
 
3
3
  // invoke collection method
4
4
  // This will invoke UserBinder.admins and fill #users with admins
@@ -6,12 +6,11 @@
6
6
  <link rel="stylesheet" href="stylesheets/application.css" type="text/css" charset="utf-8">
7
7
  <script src="javascripts/jquery.js" type="text/javascript" charset="utf-8"></script>
8
8
  <script src="javascripts/jquery.chain.js" type="text/javascript" charset="utf-8"></script>
9
- <script src="javascripts/json2.js" type="text/javascript" charset="utf-8"></script>
10
9
  <script src="javascripts/bowline.js" type="text/javascript" charset="utf-8"></script>
11
10
  <script src="javascripts/application.js" type="text/javascript" charset="utf-8"></script>
12
11
  <script type="text/javascript" charset="utf-8">
13
12
  jQuery(function($){
14
- var tweets = $('#tweets').bowlineBind('TweetsBinder');
13
+ var tweets = $('#tweets').bowlineChain('TweetsBinder');
15
14
 
16
15
  $('#updateSubmit').click(function(){
17
16
  tweets.invoke('update', $('#updateText').val());
@@ -9,15 +9,25 @@ module Bowline
9
9
  @instance ||= create
10
10
  end
11
11
 
12
- def marshal_records(record = nil)
12
+ def marshal_records=(record)
13
13
  self.instance.load(record.attributes) if record
14
14
  self.instance
15
15
  end
16
16
 
17
+ def marshal_records
18
+ self.instance
19
+ end
20
+
17
21
  def load!(path)
18
22
  self.instance.load_path(path)
19
23
  self.instance
20
24
  end
25
+
26
+ def reset!
27
+ @instance = nil
28
+ end
29
+ alias_method :destroy_all, :reset!
30
+ alias_method :delete_all, :reset!
21
31
  end
22
32
 
23
33
  def load_path(path)
@@ -55,6 +55,17 @@ module Bowline
55
55
  # </script>
56
56
  #
57
57
  # For more documentation on Bowline's JavaScript API, see bowline.js
58
+
59
+ def active(binder = nil) #:nodoc:
60
+ @active ||= []
61
+ if binder
62
+ @active << binder
63
+ @active.uniq!
64
+ end
65
+ @active
66
+ end
67
+ module_function :active
68
+
58
69
  class Base
59
70
  extend Bowline::Watcher::Base
60
71
  extend Bowline::Desktop::Bridge::ClassMethods
@@ -66,11 +77,11 @@ module Bowline
66
77
  if block_given?
67
78
  Thread.new(callback_proc) do |proc|
68
79
  begin
69
- self.callback_proc = proc
70
- yield
71
- rescue => e
72
- Bowline::Logging.log_error(e)
73
- end
80
+ self.callback_proc = proc
81
+ yield
82
+ rescue => e
83
+ Bowline::Logging.log_error(e)
84
+ end
74
85
  end
75
86
  else
76
87
  methods.each do |method|
@@ -89,7 +100,7 @@ module Bowline
89
100
  include Async
90
101
  class << self; extend Async; end
91
102
 
92
- class << self
103
+ class << self
93
104
  def callback_proc(proc = nil) #:nodoc:
94
105
  Thread.current[:callback] = proc if proc
95
106
  Thread.current[:callback]
@@ -115,19 +126,27 @@ module Bowline
115
126
  end
116
127
 
117
128
  # An array of window currently bound.
118
- def windows
129
+ def windows(window = nil)
119
130
  @windows ||= []
131
+ if window
132
+ @windows << window
133
+ @windows.uniq!
134
+ end
135
+ @windows
120
136
  end
121
137
 
122
138
  def setup(window) #:nodoc:
123
- self.windows << window
124
- self.windows.uniq!
125
- if initial_items = initial
126
- self.items = initial_items
127
- end
139
+ Binders.active(self)
140
+ windows(window)
141
+ populate
128
142
  callback(true)
129
143
  end
130
144
 
145
+ # Populate initial items
146
+ def populate(items = initial)
147
+ self.items = items if items
148
+ end
149
+
131
150
  # Called by a window's JavaScript whenever that window is bound to this Binder.
132
151
  # This method populates the window's HTML with all bound class' records.
133
152
  # Override this if you don't want to send all the class' records to the window.
@@ -74,7 +74,7 @@ module Bowline
74
74
  object = klass.constantize
75
75
  end
76
76
 
77
- trace "JS invoking: #{klass}.#{method_name}(#{args.join(',')})"
77
+ debug "JS invoking: #{klass}.#{method_name}(#{args.join(',')})"
78
78
 
79
79
  if object.respond_to?(:js_exposed?) &&
80
80
  object.js_exposed?(method_name)
@@ -20,7 +20,7 @@ module Bowline
20
20
 
21
21
  def call
22
22
  if Desktop.enabled?
23
- trace "JS eval on #{window}: #{script}"
23
+ debug "JS eval on #{window}: #{script}"
24
24
  if multiple_windows?
25
25
  windows.each {|w| w.run_script(script) }
26
26
  raise "Can't return from multiple windows" if prok
@@ -30,7 +30,7 @@ module Bowline
30
30
  end
31
31
  result
32
32
  else
33
- trace "Pseudo JS eval on #{window}: #{script}"
33
+ debug "Pseudo JS eval on #{window}: #{script}"
34
34
  prok.call(nil) if prok
35
35
  end
36
36
  end
@@ -51,7 +51,7 @@ module Bowline
51
51
  JSON.parse(str)
52
52
  end
53
53
  rescue => e
54
- trace "Parsing: #{str}"
54
+ debug "Parsing: #{str}"
55
55
  raise e
56
56
  end
57
57
  end
@@ -63,9 +63,9 @@ module Bowline
63
63
  # Internal ID for the window.
64
64
 
65
65
  ##
66
- # :singleton-method: dealocated?
67
- # Returns true if the window has been dealocated.
68
- # Calling methods on dealocated windows has no effect.
66
+ # :singleton-method: deallocated?
67
+ # Returns true if the window has been deallocated.
68
+ # Calling methods on deallocated windows has no effect.
69
69
  # Instead, you'll need to create a new instance.
70
70
 
71
71
  ##
@@ -49,7 +49,11 @@ module Bowline
49
49
  end
50
50
 
51
51
  def allocated?
52
- !!@window
52
+ !deallocated?
53
+ end
54
+
55
+ def deallocated?
56
+ !@window || @window.deallocated?
53
57
  end
54
58
 
55
59
  # Call this method to allocate a new window.
@@ -57,7 +61,7 @@ module Bowline
57
61
  # or after it has been closed.
58
62
  def setup!
59
63
  return unless Desktop.enabled?
60
- return if @window && !@window.dealocated?
64
+ return if allocated?
61
65
  if self.name == "MainWindow"
62
66
  @window = MainWindow.get
63
67
  else
@@ -69,6 +73,7 @@ module Bowline
69
73
  Bowline::Desktop::Bridge.call(self, str)
70
74
  }
71
75
  @window.script_callback = @script_callback
76
+ true
72
77
  end
73
78
 
74
79
  # Evaluate JavaScript in this window. Pass
@@ -65,7 +65,7 @@ module Bowline
65
65
 
66
66
  # Window was shut; setup!
67
67
  # needs to be called again
68
- def dealocated?
68
+ def deallocated?
69
69
  id == -1
70
70
  end
71
71
 
@@ -6,23 +6,22 @@ module Templater
6
6
  module Actions
7
7
  class Touch < Action
8
8
 
9
- def initialize(generator, name, destination, options={})
10
- self.generator = generator
11
- self.name = name
9
+ def initialize(generator, destination, options={})
10
+ self.generator = generator
12
11
  self.destination = destination
13
- self.options = options
12
+ self.options = options
14
13
  end
15
14
 
16
15
  def render
17
16
  ''
18
17
  end
19
-
18
+
20
19
  def exists?
21
- ::File.exists?(destination)
20
+ false
22
21
  end
23
22
 
24
23
  def identical?
25
- exists?
24
+ false
26
25
  end
27
26
 
28
27
  def invoke!
@@ -30,12 +29,39 @@ module Templater
30
29
  ::FileUtils.touch(destination)
31
30
  callback(:after)
32
31
  end
32
+
33
+ end # Touch
33
34
 
34
- def revoke!
35
- ::FileUtils.rm_rf(::File.expand_path(destination))
35
+ class Chmod < Action
36
+
37
+ attr_accessor :mode
38
+
39
+ def initialize(generator, destination, options={})
40
+ self.generator = generator
41
+ self.destination = destination
42
+ self.options = options
43
+ self.mode = self.options[:mode] || 0755
36
44
  end
37
45
 
38
- end # Touch
46
+ def render
47
+ ''
48
+ end
49
+
50
+ def exists?
51
+ false
52
+ end
53
+
54
+ def identical?
55
+ false
56
+ end
57
+
58
+ def invoke!
59
+ callback(:before)
60
+ ::FileUtils.chmod_R(self.mode, destination)
61
+ callback(:after)
62
+ end
63
+
64
+ end # Chmod
39
65
  end # Actions
40
66
  end # Templater
41
67
 
@@ -64,9 +90,15 @@ module Bowline
64
90
  "#!/usr/bin/env #{RbConfig::CONFIG["RUBY_INSTALL_NAME"]}"
65
91
  end
66
92
 
67
- def self.touch(name, destination)
68
- empty_directories << Templater::ActionDescription.new(name) do |generator|
69
- Templater::Actions::Touch.new(generator, name, destination)
93
+ def self.touch(destination, options = {})
94
+ empty_directories << Templater::ActionDescription.new("touch") do |generator|
95
+ Templater::Actions::Touch.new(generator, destination, options)
96
+ end
97
+ end
98
+
99
+ def self.chmod(destination, options = {})
100
+ files << Templater::ActionDescription.new("chmod") do |generator|
101
+ Templater::Actions::Chmod.new(generator, destination, options)
70
102
  end
71
103
  end
72
104