ruby_mvc 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/LICENSE +19 -0
  2. data/README.md +69 -0
  3. data/lib/ruby_mvc.rb +33 -0
  4. data/lib/ruby_mvc/application.rb +53 -0
  5. data/lib/ruby_mvc/controllers/app_controller.rb +93 -0
  6. data/lib/ruby_mvc/controllers/rails_controller.rb +71 -0
  7. data/lib/ruby_mvc/models.rb +28 -0
  8. data/lib/ruby_mvc/models/array_table_model.rb +59 -0
  9. data/lib/ruby_mvc/models/keyed_array_table_model.rb +83 -0
  10. data/lib/ruby_mvc/models/table_model.rb +42 -0
  11. data/lib/ruby_mvc/module.rb +35 -0
  12. data/lib/ruby_mvc/renderers.rb +26 -0
  13. data/lib/ruby_mvc/renderers/html4_table_model_renderer.rb +100 -0
  14. data/lib/ruby_mvc/toolkit.rb +31 -0
  15. data/lib/ruby_mvc/toolkit/app.rb +32 -0
  16. data/lib/ruby_mvc/toolkit/dialog.rb +31 -0
  17. data/lib/ruby_mvc/toolkit/frame.rb +34 -0
  18. data/lib/ruby_mvc/toolkit/notification.rb +202 -0
  19. data/lib/ruby_mvc/toolkit/peers/wxruby.rb +31 -0
  20. data/lib/ruby_mvc/toolkit/peers/wxruby/app.rb +44 -0
  21. data/lib/ruby_mvc/toolkit/peers/wxruby/box_layout.rb +48 -0
  22. data/lib/ruby_mvc/toolkit/peers/wxruby/common.rb +72 -0
  23. data/lib/ruby_mvc/toolkit/peers/wxruby/frame.rb +49 -0
  24. data/lib/ruby_mvc/toolkit/peers/wxruby/web_view.rb +87 -0
  25. data/lib/ruby_mvc/toolkit/web_view.rb +60 -0
  26. data/lib/ruby_mvc/toolkit/widget.rb +108 -0
  27. data/lib/ruby_mvc/views.rb +85 -0
  28. data/lib/ruby_mvc/views/ar_model_editor.rb +84 -0
  29. data/lib/ruby_mvc/views/ar_type_editor.rb +65 -0
  30. data/lib/ruby_mvc/views/ar_type_list.rb +45 -0
  31. data/lib/ruby_mvc/views/table_view.rb +96 -0
  32. data/lib/ruby_mvc/views/web_view.rb +65 -0
  33. data/lib/ruby_mvc/wx.rb +26 -0
  34. data/ruby_mvc.gemspec +37 -0
  35. data/sample/frame.rb +28 -0
  36. data/sample/mvc.rb +29 -0
  37. data/sample/test.html +118 -0
  38. data/sample/web_view.rb +34 -0
  39. data/test/unit/models/test_array_table_model.rb +56 -0
  40. data/test/unit/models/test_keyed_array_table_model.rb +54 -0
  41. data/test/unit/test_array_table_model.rb +38 -0
  42. metadata +107 -0
@@ -0,0 +1,31 @@
1
+ #--
2
+ ######################################################################
3
+ #
4
+ # Copyright 2011 Andrew S. Townley
5
+ #
6
+ # Permission to use, copy, modify, and disribute this software for
7
+ # any purpose with or without fee is hereby granted, provided that
8
+ # the above copyright notices and this permission notice appear in
9
+ # all copies.
10
+ #
11
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL
12
+ # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
13
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
14
+ # AUTHORS BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT OR
15
+ # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16
+ # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
17
+ # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
18
+ # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
+ #
20
+ # File: wxruby.rb
21
+ # Created: Wed 23 Nov 2011 10:35:20 GMT
22
+ #
23
+ #####################################################################
24
+ #++
25
+
26
+ require 'wx'
27
+
28
+ require 'ruby_mvc/toolkit/peers/wxruby/common'
29
+ require 'ruby_mvc/toolkit/peers/wxruby/app'
30
+ require 'ruby_mvc/toolkit/peers/wxruby/frame'
31
+ require 'ruby_mvc/toolkit/peers/wxruby/web_view'
@@ -0,0 +1,44 @@
1
+ #--
2
+ ######################################################################
3
+ #
4
+ # Copyright 2011 Andrew S. Townley
5
+ #
6
+ # Permission to use, copy, modify, and disribute this software for
7
+ # any purpose with or without fee is hereby granted, provided that
8
+ # the above copyright notices and this permission notice appear in
9
+ # all copies.
10
+ #
11
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL
12
+ # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
13
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
14
+ # AUTHORS BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT OR
15
+ # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16
+ # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
17
+ # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
18
+ # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
+ #
20
+ # File: app.rb
21
+ # Created: Wed 23 Nov 2011 11:53:28 GMT
22
+ #
23
+ #####################################################################
24
+ #++
25
+
26
+ module RubyMVC
27
+ module Toolkit
28
+ module WxRuby
29
+ class App < Wx::App
30
+ Toolkit::App.peer_class = self
31
+
32
+ def initialize(&block)
33
+ super
34
+ @block = block
35
+ main_loop
36
+ end
37
+
38
+ def on_init
39
+ @block.call
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,48 @@
1
+ #--
2
+ ######################################################################
3
+ #
4
+ # Copyright 2011 Andrew S. Townley
5
+ #
6
+ # Permission to use, copy, modify, and disribute this software for
7
+ # any purpose with or without fee is hereby granted, provided that
8
+ # the above copyright notices and this permission notice appear in
9
+ # all copies.
10
+ #
11
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL
12
+ # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
13
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
14
+ # AUTHORS BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT OR
15
+ # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16
+ # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
17
+ # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
18
+ # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
+ #
20
+ # File: box_layout.rb
21
+ # Created: Wed 23 Nov 2011 13:41:15 GMT
22
+ #
23
+ #####################################################################
24
+ #++
25
+
26
+ module RubyMVC
27
+ module Toolkit
28
+ module WxRuby
29
+ class BoxLayout
30
+ Toolkit::BoxLayout.peer_class = self
31
+
32
+ def initialize(options)
33
+ @options = options
34
+ case(options[:axis])
35
+ when :horizontal, :x, :x_axis
36
+ @widget = Wx::BoxSizer.new(Wx::HORIZONTAL)
37
+ else
38
+ @widget = Wx::BoxSizer.new(Wx::VERTICAL)
39
+ end
40
+ end
41
+
42
+ def add(child, options = {})
43
+ @widget.add
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,72 @@
1
+ #--
2
+ ######################################################################
3
+ #
4
+ # Copyright 2011 Andrew S. Townley
5
+ #
6
+ # Permission to use, copy, modify, and disribute this software for
7
+ # any purpose with or without fee is hereby granted, provided that
8
+ # the above copyright notices and this permission notice appear in
9
+ # all copies.
10
+ #
11
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL
12
+ # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
13
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
14
+ # AUTHORS BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT OR
15
+ # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16
+ # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
17
+ # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
18
+ # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
+ #
20
+ # File: common.rb
21
+ # Created: Wed 23 Nov 2011 10:46:35 GMT
22
+ #
23
+ #####################################################################
24
+ #++
25
+
26
+ module RubyMVC
27
+ module Toolkit
28
+ module WxRuby
29
+
30
+ # This method is a hack to deal with the parenting
31
+ # issues around the way wxWindows requires a parent for
32
+ # all child windows, and other toolkits don't.
33
+
34
+ def self.default_parent
35
+ @@parent ||= 1
36
+ if 1 == @@parent
37
+ @@parent = Wx::Frame.new(nil, :size => [40, 40])
38
+ class << @@parent
39
+ def should_prevent_app_exit
40
+ false
41
+ end
42
+ end
43
+ end
44
+ @@parent
45
+ end
46
+
47
+ # This method is used to retrieve the parent window from
48
+ # the options, or it will use the default parent window.
49
+
50
+ def self.parent(options = {})
51
+ if (p = options[:parent]) && (p = p.peer)
52
+ p
53
+ else
54
+ default_parent
55
+ end
56
+ end
57
+
58
+ # This module has some common things that map between
59
+ # controls in the WxRuby universe
60
+
61
+ module Common
62
+ def title
63
+ get_title
64
+ end
65
+
66
+ def title=(title)
67
+ set_title(title)
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,49 @@
1
+ #--
2
+ ######################################################################
3
+ #
4
+ # Copyright 2011 Andrew S. Townley
5
+ #
6
+ # Permission to use, copy, modify, and disribute this software for
7
+ # any purpose with or without fee is hereby granted, provided that
8
+ # the above copyright notices and this permission notice appear in
9
+ # all copies.
10
+ #
11
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL
12
+ # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
13
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
14
+ # AUTHORS BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT OR
15
+ # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16
+ # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
17
+ # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
18
+ # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
+ #
20
+ # File: frame.rb
21
+ # Created: Wed 23 Nov 2011 10:46:44 GMT
22
+ #
23
+ #####################################################################
24
+ #++
25
+
26
+ module RubyMVC
27
+ module Toolkit
28
+ module WxRuby
29
+ class Frame < Wx::Frame
30
+ include Common
31
+ Toolkit::Frame.peer_class = self
32
+
33
+ def initialize(options)
34
+ opts = {}
35
+ opts[:title] = options[:title]
36
+ opts[:size] = [ options[:width], options[:height] ]
37
+ super(options[:parent], opts)
38
+ end
39
+
40
+ # This method is used to add a child to the existing
41
+ # frame.
42
+
43
+ def add(child, options = {})
44
+ child.peer.reparent(self)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,87 @@
1
+ #--
2
+ ######################################################################
3
+ #
4
+ # Copyright 2011 Andrew S. Townley
5
+ #
6
+ # Permission to use, copy, modify, and disribute this software for
7
+ # any purpose with or without fee is hereby granted, provided that
8
+ # the above copyright notices and this permission notice appear in
9
+ # all copies.
10
+ #
11
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL
12
+ # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
13
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
14
+ # AUTHORS BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT OR
15
+ # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16
+ # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
17
+ # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
18
+ # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
+ #
20
+ # File: html_view.rb
21
+ # Created: Wed 23 Nov 2011 12:43:10 GMT
22
+ #
23
+ #####################################################################
24
+ #++
25
+
26
+ module RubyMVC
27
+ module Toolkit
28
+ module WxRuby
29
+ class WebView < Wx::HtmlWindow
30
+ include Toolkit::SignalHandler
31
+ include Common
32
+ Toolkit::WebView.peer_class = self
33
+
34
+ def initialize(options = {}, &block)
35
+ super(WxRuby.parent(options))
36
+ set_background_colour(Wx::WHITE)
37
+ end
38
+
39
+ attr_reader :location
40
+
41
+ def can_go_back?
42
+ history_can_back
43
+ end
44
+
45
+ def can_go_forward?
46
+ history_can_forward
47
+ end
48
+
49
+ def go_back
50
+ history_back
51
+ end
52
+
53
+ def go_forward
54
+ history_forward
55
+ end
56
+
57
+ def open(uri)
58
+ @location = uri
59
+ load_page(uri)
60
+ end
61
+
62
+ def stop_loading
63
+ # apparently, we can't do this
64
+ end
65
+
66
+ def reload
67
+ open(location)
68
+ end
69
+
70
+ def load_html(html, base_uri = nil)
71
+ # FIXME: this isn't quite right...
72
+ set_page(html)
73
+ @location = base_uri
74
+ end
75
+
76
+ #--
77
+ # wxRuby event handlers
78
+ #++
79
+
80
+ def on_link_clicked(link)
81
+ signal_emit("navigation-requested", self, link.href, link.target)
82
+ end
83
+
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,60 @@
1
+ #--
2
+ ######################################################################
3
+ #
4
+ # Copyright 2011 Andrew S. Townley
5
+ #
6
+ # Permission to use, copy, modify, and disribute this software for
7
+ # any purpose with or without fee is hereby granted, provided that
8
+ # the above copyright notices and this permission notice appear in
9
+ # all copies.
10
+ #
11
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL
12
+ # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
13
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
14
+ # AUTHORS BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT OR
15
+ # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16
+ # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
17
+ # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
18
+ # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
+ #
20
+ # File: web_view.rb
21
+ # Created: Wed 23 Nov 2011 12:54:26 GMT
22
+ #
23
+ #####################################################################
24
+ #++
25
+
26
+ module RubyMVC
27
+ module Toolkit
28
+
29
+ # This class provides a web/HTML view whose API is
30
+ # modelled on WebKit
31
+
32
+ class WebView < Widget
33
+ api_method :load_html
34
+ api_methods :can_go_back?, :go_back
35
+ api_methods :can_go_forward?, :go_forward
36
+ api_methods :open, :reload, :go_home, :location
37
+ api_methods :stop_loading, :is_loading?
38
+
39
+ # This signal is emitted when the user requests
40
+ # navigation to another web resource.
41
+
42
+ signal "navigation-requested", :vetoable => true
43
+
44
+ # This signal is emitted when the title of the content
45
+ # in the view changes
46
+
47
+ signal "title-changed"
48
+
49
+ # This signal is emitted when the page begins to load
50
+
51
+ signal "load-started"
52
+
53
+ # This signal is emitted when the page load has
54
+ # completed.
55
+
56
+ signal "load-finished"
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,108 @@
1
+ #--
2
+ ######################################################################
3
+ #
4
+ # Copyright 2011 Andrew S. Townley
5
+ #
6
+ # Permission to use, copy, modify, and disribute this software for
7
+ # any purpose with or without fee is hereby granted, provided that
8
+ # the above copyright notices and this permission notice appear in
9
+ # all copies.
10
+ #
11
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL
12
+ # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
13
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
14
+ # AUTHORS BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT OR
15
+ # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16
+ # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
17
+ # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
18
+ # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
+ #
20
+ # File: widget.rb
21
+ # Created: Wed 23 Nov 2011 10:34:52 GMT
22
+ #
23
+ #####################################################################
24
+ #++
25
+
26
+ module RubyMVC
27
+ module Toolkit
28
+
29
+ # This class defines the base toolkit widget class. Each
30
+ # widget has one - and only one - UI peer that is
31
+ # registered automatically when the UI peer is loaded.
32
+
33
+ class Widget
34
+ include SignalHandler
35
+ extend SignalHandler::ClassMethods
36
+
37
+ class << self
38
+ attr_accessor :peer_class
39
+
40
+ # This method is used to manage the API methods
41
+ # available to the toolkit widgets. Methods listed
42
+ # here will be forwarded to the peer class if they
43
+ # aren't defined by the toolkit widget subclass.
44
+
45
+ def api_methods(*args)
46
+ if !@api
47
+ @api = []
48
+ if self.superclass.respond_to? :api_methods
49
+ @api.concat(self.superclass.api_methods)
50
+ end
51
+ end
52
+ @api.concat(args) if args.size > 0
53
+ @api
54
+ end
55
+ alias :api_method :api_methods
56
+ end
57
+
58
+ attr_reader :peer
59
+ api_methods :show, :hide
60
+
61
+ def initialize(*args, &block)
62
+ if pc = self.class.peer_class
63
+ @peer = pc.new(*args, &block)
64
+ connect_peer_signals
65
+ else
66
+ raise RuntimeError, "no peer class registered for #{self.class}"
67
+ end
68
+ end
69
+
70
+ # This method will forward only those registered API
71
+ # methods to the peer class. Doing it this way ensures
72
+ # that we don't leak APIs from the peers into
73
+ # applications, but that we can still be efficient in
74
+ # how we manage the implementations.
75
+ #
76
+ # FIXME: there may be performance implications...
77
+
78
+ def method_missing(method, *args, &block)
79
+ if (self.class.api_methods || []).include? method
80
+ @peer.send(method, *args, &block)
81
+ else
82
+ super
83
+ end
84
+ end
85
+
86
+ protected
87
+
88
+ # This method is used to ensure that the signals defined
89
+ # for the widget are appropriately connected to the new
90
+ # peer instance when it's created.
91
+ #
92
+ # The normal mechanism is to simply forward the signal
93
+ # to the registered listeners on the toolkit widget. It
94
+ # is assumed that the peer classes send the appropriate
95
+ # arguments to the signal handlers.
96
+
97
+ def connect_peer_signals
98
+ self.class.signals.each do |s, opts|
99
+ puts "connecting signal '#{s}' to #{peer}"
100
+ peer.signal_connect(s) do |*args|
101
+ args[0] = self
102
+ signal_emit(s, *args)
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end