ruby_mvc 0.0.1 → 0.0.2

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 (68) hide show
  1. data/README.md +14 -0
  2. data/lib/ruby_mvc.rb +3 -1
  3. data/lib/ruby_mvc/application.rb +52 -2
  4. data/lib/ruby_mvc/controllers.rb +28 -0
  5. data/lib/ruby_mvc/controllers/action.rb +93 -0
  6. data/lib/ruby_mvc/controllers/action_group.rb +70 -0
  7. data/lib/ruby_mvc/controllers/app_controller.rb +4 -2
  8. data/lib/ruby_mvc/controllers/rails_controller.rb +2 -0
  9. data/lib/ruby_mvc/models.rb +2 -0
  10. data/lib/ruby_mvc/models/ar_table_model.rb +133 -0
  11. data/lib/ruby_mvc/models/array_table_model.rb +81 -13
  12. data/lib/ruby_mvc/models/keyed_array_table_model.rb +1 -1
  13. data/lib/ruby_mvc/models/model.rb +129 -0
  14. data/lib/ruby_mvc/models/table_model.rb +107 -10
  15. data/lib/ruby_mvc/models/view_model_template.rb +140 -0
  16. data/lib/ruby_mvc/renderers.rb +1 -0
  17. data/lib/ruby_mvc/renderers/html4_table_model_renderer.rb +7 -6
  18. data/lib/ruby_mvc/renderers/hyperlink_cell_renderer.rb +47 -0
  19. data/lib/ruby_mvc/toolkit.rb +5 -1
  20. data/lib/ruby_mvc/toolkit/browser_history.rb +115 -0
  21. data/lib/ruby_mvc/toolkit/dialog.rb +12 -1
  22. data/lib/ruby_mvc/toolkit/frame.rb +3 -1
  23. data/lib/ruby_mvc/toolkit/grid_view.rb +46 -0
  24. data/lib/ruby_mvc/toolkit/messagebox.rb +32 -0
  25. data/lib/ruby_mvc/toolkit/peers/wxruby.rb +5 -0
  26. data/lib/ruby_mvc/toolkit/peers/wxruby/app.rb +23 -2
  27. data/lib/ruby_mvc/toolkit/peers/wxruby/common.rb +11 -1
  28. data/lib/ruby_mvc/toolkit/peers/wxruby/dialog.rb +82 -0
  29. data/lib/ruby_mvc/toolkit/peers/wxruby/form_builder.rb +108 -0
  30. data/lib/ruby_mvc/toolkit/peers/wxruby/frame.rb +85 -1
  31. data/lib/ruby_mvc/toolkit/peers/wxruby/grid_model.rb +79 -0
  32. data/lib/ruby_mvc/toolkit/peers/wxruby/grid_view.rb +117 -0
  33. data/lib/ruby_mvc/toolkit/peers/wxruby/messagebox.rb +58 -0
  34. data/lib/ruby_mvc/toolkit/peers/wxruby/web_view.rb +40 -10
  35. data/lib/ruby_mvc/toolkit/property_change_notifier.rb +46 -0
  36. data/lib/ruby_mvc/toolkit/signal_handler.rb +149 -0
  37. data/lib/ruby_mvc/toolkit/web_view.rb +1 -1
  38. data/lib/ruby_mvc/toolkit/widget.rb +13 -6
  39. data/lib/ruby_mvc/views.rb +8 -59
  40. data/lib/ruby_mvc/views/{ar_type_list.rb → ar_form_view.rb} +10 -13
  41. data/lib/ruby_mvc/views/ar_support.rb +29 -0
  42. data/lib/ruby_mvc/views/ar_type_editor.rb +17 -28
  43. data/lib/ruby_mvc/views/ar_web_model_view.rb +59 -0
  44. data/lib/ruby_mvc/views/ar_web_type_list.rb +44 -0
  45. data/lib/ruby_mvc/views/browser_view.rb +185 -0
  46. data/lib/ruby_mvc/views/form_view.rb +111 -0
  47. data/lib/ruby_mvc/views/grid_table_view.rb +96 -0
  48. data/lib/ruby_mvc/views/table_view.rb +0 -39
  49. data/lib/ruby_mvc/views/view.rb +121 -0
  50. data/lib/ruby_mvc/views/web_content_table_view.rb +40 -0
  51. data/lib/ruby_mvc/views/{web_view.rb → web_content_view.rb} +17 -28
  52. data/lib/ruby_mvc/views/web_model_view.rb +67 -0
  53. data/ruby_mvc.gemspec +1 -1
  54. data/sample/browser_view.rb +57 -0
  55. data/sample/form.rb +59 -0
  56. data/sample/form2.rb +63 -0
  57. data/sample/grid_table_view.rb +68 -0
  58. data/sample/grid_view.rb +44 -0
  59. data/sample/grid_view2.rb +57 -0
  60. data/sample/test.html +1 -0
  61. data/sample/test2.html +33 -0
  62. data/sample/web_view.rb +4 -0
  63. data/test/unit/models/test_array_table_model.rb +19 -3
  64. data/test/unit/models/test_keyed_array_table_model.rb +3 -2
  65. data/test/unit/models/test_model.rb +88 -0
  66. metadata +39 -20
  67. data/lib/ruby_mvc/toolkit/notification.rb +0 -202
  68. data/lib/ruby_mvc/views/ar_model_editor.rb +0 -84
@@ -0,0 +1,96 @@
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: grid_table_view.rb
21
+ # Created: Sun 1 Jan 2012 17:08:34 CET
22
+ #
23
+ #####################################################################
24
+ #++
25
+
26
+ module RubyMVC
27
+ module Views
28
+
29
+ # This class is used to provide a default binding between
30
+ # a table model instance and a GridView.
31
+
32
+ class GridTableView < PeerView
33
+ widget Toolkit::GridView
34
+
35
+ # This signal is triggered when the row edit action is
36
+ # triggered via either a double-click on the row or when
37
+ # either the toolbar or menu item is triggered. Arguments
38
+ # are the sender view, the view model, the row index and
39
+ # the row model to be edited
40
+
41
+ signal "row-edit"
42
+
43
+ def initialize(model, options = {}, &block)
44
+ super(options, &block)
45
+
46
+ # initialize the default state of the peer widget
47
+ widget.model = model
48
+ widget.editable = options[:editable]
49
+
50
+ # Create the actions for the model
51
+ action(:new, :label => "New row", :icon => :stock_new) do
52
+ model.insert_rows(-1, model.create_rows)
53
+ idx = model.size - 1
54
+ signal_emit("row-edit", self, model, idx, model[idx])
55
+ end
56
+
57
+ action(:delete,
58
+ :label => "Delete",
59
+ :enable => :select_multi,
60
+ :icon => :stock_delete
61
+ ) do
62
+ puts "rows: #{widget.selected_rows.inspect}"
63
+ widget.selected_rows.reverse_each do |i|
64
+ model.remove_row(i)
65
+ end
66
+ end
67
+
68
+ action(:edit,
69
+ :label => "Edit...",
70
+ :enable => :select_single,
71
+ :icon => :stock_edit
72
+ ) do
73
+ idx = widget.selected_rows.first
74
+ row = model[idx]
75
+ signal_emit("row-edit", self, model, idx, row)
76
+ end
77
+
78
+ widget.signal_connect("row-selection-changed") do |s, m, rows|
79
+ puts "selection changed: #{rows.inspect}"
80
+ @actions.each do |a|
81
+ a.selection(s, m, rows)
82
+ end
83
+ end
84
+
85
+ widget.signal_connect("row-activated") do |s, m, r, k|
86
+ row = model[r]
87
+ signal_emit("row-edit", self, model, r, row)
88
+ end
89
+
90
+ puts "self.class.signals: #{self.class.signals.keys.inspect}"
91
+ puts "widget.class.signals: #{widget.class.signals.keys.inspect}"
92
+ end
93
+ end
94
+
95
+ end
96
+ end
@@ -26,11 +26,6 @@
26
26
  module RubyMVC
27
27
  module Views
28
28
 
29
- # This class provides a basic TableView control based
30
- # loosely on the Archistry JavaScript TreeGrid API. It
31
- # requires that the data to be displayed be supplied as a
32
- # TableModel instance.
33
-
34
29
  class TableView < View
35
30
  def initialize(model, options = {}, &block)
36
31
  super(options, &block)
@@ -41,12 +36,6 @@ module Views
41
36
  # information in the table model.
42
37
 
43
38
  def load(model, options = {}, &block)
44
- cols = columns(model, options)
45
- defw = "#{100 / cols.size}%"
46
- build_header(model, cols, defw, options)
47
- stack(:width => "100%") do
48
- model.each { |row| build_row(cols, row, defw) }
49
- end
50
39
  end
51
40
 
52
41
  protected
@@ -62,34 +51,6 @@ module Views
62
51
  end
63
52
  end
64
53
  end
65
-
66
- def build_header(model, cols, defw, options)
67
- if options[:headers] != false
68
- stack(:width => "100%") do
69
- flow do
70
- cols.each do |col|
71
- flow(:width => defw) do
72
- para col[:label], :weight => "bold", :align => "center"
73
- end
74
- end
75
- end
76
- end
77
- end
78
- end
79
-
80
- def build_row(cols, row, defw)
81
- flow do
82
- cols.each do |col|
83
- flow(:width => defw) do
84
- if(r = col[:renderer])
85
- r.render(self, row, col)
86
- else
87
- para row[col[:key]], col[:style]
88
- end
89
- end
90
- end
91
- end
92
- end
93
54
  end
94
55
 
95
56
  end
@@ -0,0 +1,121 @@
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: view.rb
21
+ # Created: Sat 19 Nov 2011 11:28:08 GMT
22
+ #
23
+ #####################################################################
24
+ #++
25
+
26
+ module RubyMVC
27
+ module Views
28
+
29
+ class View < RubyMVC::Toolkit::AbstractWidget
30
+ attr_reader :actions
31
+ attr_accessor :controller
32
+
33
+ def initialize(options = {})
34
+ @actions = ActionGroup.new
35
+ @options = options
36
+ self.controller = options[:controller]
37
+ (options[:actions] || []).each { |a| @actions << a }
38
+ end
39
+
40
+ protected
41
+ def action(key, options = {}, &block)
42
+ a = Action.new(key, options, &block)
43
+ @actions << a
44
+ a
45
+ end
46
+ end
47
+
48
+ class PeerView < View
49
+ def self.widget_def(targ = nil)
50
+ if targ == nil
51
+ @widget_def
52
+ else
53
+ if (x = targ.widget_def).nil?
54
+ if targ != RubyMVC::Views::PeerView
55
+ self.widget_def(targ.superclass)
56
+ end
57
+ else
58
+ x
59
+ end
60
+ end
61
+ end
62
+
63
+ def self.create_widget(klass, options = {})
64
+ w = self.widget_def(klass)
65
+ args = (w[:args].clone << options)
66
+ block = w[:block]
67
+ args[0].new(*args[1..-1], &block)
68
+ end
69
+
70
+ class << self
71
+ # This method is used to define the primary widget
72
+ # class through which this view may be added to other
73
+ # widgets.
74
+
75
+ def widget(*args, &block)
76
+ puts "Set widget for #{self}: #{args.inspect}"
77
+ @widget_def = { :args => args, :block => block }
78
+ end
79
+ end
80
+
81
+ def peer
82
+ @widget.peer
83
+ end
84
+
85
+ # This method is used to retrieve a reference to the
86
+ # parent frame
87
+ attr_accessor :frame
88
+
89
+ attr_accessor :widget
90
+ def initialize(options = {})
91
+ super
92
+ @widget = PeerView.create_widget(self.class, options)
93
+ end
94
+
95
+ # This method is required to ensure that concrete views
96
+ # appropriately manage signal registration
97
+
98
+ def signal_connect(signal, &b)
99
+ puts "Widget class: #{@widget.class}"
100
+ if @widget.class.valid_signal? signal
101
+ @widget.signal_connect(signal, &b)
102
+ else
103
+ puts "super"
104
+ super
105
+ end
106
+ end
107
+
108
+ def signal_disconnect(signal, &b)
109
+ if @widget.class.valid_signal? signal
110
+ @widget.signal_connect(signal, &b)
111
+ else
112
+ super
113
+ end
114
+ end
115
+
116
+ def method_missing(m, *a, &b)
117
+ @widget.send(m, *a, &b)
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,40 @@
1
+ #--
2
+ ######################################################################
3
+ #
4
+ # Copyright 2011-2012 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_content_table_view.rb
21
+ # Created: Tue 3 Jan 2012 00:48:54 CET
22
+ #
23
+ #####################################################################
24
+ #++
25
+
26
+ module RubyMVC
27
+ module Views
28
+
29
+ # This is a WebContentView used to render table model
30
+ # instances as HTML
31
+
32
+ class WebContentTableView < WebContentView
33
+ def render
34
+ r = @options[:renderer] || Renderers::Html4TableModelRenderer
35
+ r.render(@model, @options)
36
+ end
37
+ end
38
+
39
+ end
40
+ end
@@ -17,8 +17,8 @@
17
17
  # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
18
18
  # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
19
  #
20
- # File: web_view.rb
21
- # Created: Wed 23 Nov 2011 17:08:02 GMT
20
+ # File: web_content_view.rb
21
+ # Created: Tue 3 Jan 2012 00:41:51 CET
22
22
  #
23
23
  #####################################################################
24
24
  #++
@@ -26,38 +26,27 @@
26
26
  module RubyMVC
27
27
  module Views
28
28
 
29
- # This is a more sophisticated view control vs. the standard
30
- # toolkit widget.
29
+ # WebContentView instances are used to render models as web
30
+ # content to be displayed in either the Toolkit::WebView or
31
+ # the Views::BrowserView instances.
31
32
 
32
- class WebView < View
33
- widget Toolkit::WebView
33
+ class WebContentView < View
34
+ attr_reader :uri
34
35
 
35
- # This method is used to load the view with the
36
- # information in the table model.
36
+ def initialize(model, options = {})
37
+ super(options)
38
+ @model = model
39
+ @uri = options[:uri]
40
+ end
37
41
 
38
- def load(model, options = {}, &block)
39
- cols = columns(model, options)
40
- if r = options[:renderer]
41
- html = r.render(model, cols, options[:renderer_options])
42
- puts "HTML:\n#{html}"
43
- widget.load_html(html)
44
- else
45
- raise ArgumentError,"renderer not specified"
46
- end
42
+ def render
47
43
  end
44
+ end
48
45
 
49
- protected
50
- # This method extracts or creates the column model for the
51
- # view.
46
+ # This view is used to render a simple model instance
52
47
 
53
- def columns(model, options)
54
- if cols = options[:columns]
55
- cols
56
- else
57
- cols = model.keys.collect do |k|
58
- { :key => k.to_sym, :label => "#{k.capitalize}" }
59
- end
60
- end
48
+ class SimpleWebModelView < WebContentView
49
+ def render
61
50
  end
62
51
  end
63
52
 
@@ -0,0 +1,67 @@
1
+ #--
2
+ ######################################################################
3
+ #
4
+ # Copyright 2011-2012 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: ar_web_row_view.rb
21
+ # Created: Mon 9 Jan 2012 15:56:18 GMT
22
+ #
23
+ #####################################################################
24
+ #++
25
+
26
+ module RubyMVC
27
+ module Views
28
+
29
+ class WebModelView < WebContentView
30
+ include Tagz
31
+
32
+ def initialize(row, options = {})
33
+ if options.is_a? Hash
34
+ @template = options[:template]
35
+ else
36
+ @template = options
37
+ options = {}
38
+ end
39
+ super((@template ? @template.apply(row) : row), options)
40
+ end
41
+
42
+ def render
43
+ render_properties
44
+ end
45
+
46
+ protected
47
+ def render_properties
48
+ tagz {
49
+ table_(:border => 0, :cellspacing => 3) {
50
+ @model.labels.each do |l|
51
+ k = l[:key]
52
+ tr_ {
53
+ th_(:valign => "top", :align => "left") {
54
+ strong_ l[:label]
55
+ }
56
+ td_(:align => "top") {
57
+ @model[k]
58
+ }
59
+ }
60
+ end
61
+ }
62
+ }
63
+ end
64
+ end
65
+
66
+ end
67
+ end