shoes_mvc 0.0.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.
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ ######################################################################
2
+ #
3
+ # Copyright 2011 Andrew S. Townley
4
+ #
5
+ # Permission to use, copy, modify, and disribute this software for
6
+ # any purpose with or without fee is hereby granted, provided that
7
+ # the above copyright notices and this permission notice appear in
8
+ # all copies.
9
+ #
10
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL
11
+ # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13
+ # AUTHORS BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT OR
14
+ # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
16
+ # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
17
+ # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18
+ #
19
+ ######################################################################
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+
2
+ README for Shoes MVC
3
+ ====================
4
+
5
+ This project provides a basic MVC framework on top of the Shoes
6
+ environment for those of us strange people who have done MVC so long
7
+ it's extremely difficult to think about applications other ways.
8
+
9
+ Installation
10
+ ============
11
+
12
+ At the moment, you have to build the gem from source and then install
13
+ into the local Shoes gem dir. I'm hoping to get this published on
14
+ rubygems.org as soon as I have something that kinda works.
15
+
16
+ $ gem build shoes_mvc.gemspec
17
+ $ gem install --install-dir $HOME/.shoes/+gem ./*.gem
@@ -0,0 +1,78 @@
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_controller.rb
21
+ # Created: Sat 19 Nov 2011 11:29:49 GMT
22
+ #
23
+ #####################################################################
24
+ #++
25
+
26
+ module ShoesMVC
27
+
28
+ # This controller is used to assist in writing Shoes
29
+ # applications for an existing Rails application. All of
30
+ # the models will be automatically loaded based on the
31
+ # directory configuration of the Rails environment, and the
32
+ # database connection environment will be used.
33
+
34
+ class AppController
35
+ # The controller is instantiated by an
36
+ # application-specific controller instance that passes
37
+ # through the location of the appication controller source
38
+ # file.
39
+ #
40
+ # By convention, the application is configured using an
41
+ # app.yml file in the same directory as the application
42
+ # controller.
43
+
44
+ def initialize(app, app_file)
45
+ @shoes = app
46
+ @config_file = File.expand_path(File.join(File.dirname(app_file), "../app.yml"))
47
+ if !File.exist? @config_file
48
+ @shoes.alert("Unable to locate configuration file.\nFile '#{@config_file}' not found.")
49
+ @shoes.exit
50
+ end
51
+
52
+ @config = YAML.load(File.new(@config_file))
53
+ setup
54
+ run
55
+ end
56
+
57
+ # This method is a placeholder for the actual
58
+ # initialization to be performed by the Shoes application
59
+ # itself. It is called automatically by the constructor
60
+ # of the application controller.
61
+
62
+ def run
63
+ end
64
+
65
+ protected
66
+ def config
67
+ @config || {}
68
+ end
69
+
70
+ # This method is called prior to calling the #run method
71
+ # to give the derived controller classes an opportunity to
72
+ # perform any specific initialization.
73
+
74
+ def setup
75
+ end
76
+ end
77
+
78
+ end
@@ -0,0 +1,71 @@
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: rails_controller.rb
21
+ # Created: Sat 19 Nov 2011 11:29:49 GMT
22
+ #
23
+ #####################################################################
24
+ #++
25
+
26
+ require 'active_record'
27
+
28
+ module ShoesMVC
29
+
30
+ # This controller is used to assist in writing Shoes
31
+ # applications for an existing Rails application. All of
32
+ # the models will be automatically loaded based on the
33
+ # directory configuration of the Rails environment, and the
34
+ # database connection environment will be used.
35
+ #
36
+ # This controller uses the following configuration settings
37
+ # to help it initialize itself:
38
+ #
39
+ # rails_app - the location of the app directory of the Rails
40
+ # application
41
+ #
42
+ # config - the default database configuration to use by
43
+ # the application
44
+
45
+ class RailsController < AppController
46
+ def setup
47
+ @rails_app = File.expand_path(File.join(
48
+ File.dirname(@config_file), config["rails_app"]))
49
+ connect_db
50
+ load_models
51
+ end
52
+
53
+ private
54
+ def connect_db
55
+ yml = File.expand_path(File.join(@rails_app, "../config/database.yml"))
56
+ dbconf = YAML.load(File.new(yml))
57
+ env = dbconf[config["config"]]
58
+
59
+ case(env["adapter"])
60
+ when "sqlite3"
61
+ env["database"] = File.join("#{@rails_app}/..", env["database"])
62
+ end
63
+ ActiveRecord::Base.establish_connection(env)
64
+ end
65
+
66
+ def load_models
67
+ Dir.glob(File.join(@rails_app, "models/*.rb")) { |m| require m }
68
+ end
69
+ end
70
+
71
+ end
@@ -0,0 +1,59 @@
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: array_table_model.rb
21
+ # Created: Sat 19 Nov 2011 19:56:17 GMT
22
+ #
23
+ #####################################################################
24
+ #++
25
+
26
+ module ShoesMVC
27
+ module Models
28
+
29
+ # This class implements the TableModel interface based on
30
+ # the data being stored in an array. The elements in the
31
+ # array must either be a Hash, or they must respond to the
32
+ # [] accessors for retrieving elements by key and implement
33
+ # a #keys method for indicating the properties in each row
34
+ # instance.
35
+
36
+ class ArrayTableModel < TableModel
37
+ def initialize(data)
38
+ @data = data
39
+ end
40
+
41
+ def keys
42
+ if @data && @data.size > 0
43
+ @data.keys
44
+ else
45
+ {}
46
+ end
47
+ end
48
+
49
+ def each(&block)
50
+ @data.each(&block)
51
+ end
52
+
53
+ def each_with_index(&block)
54
+ @data.each_with_index(&block)
55
+ end
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,83 @@
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: keyed_array_table_model.rb
21
+ # Created: Sat 19 Nov 2011 18:58:36 GMT
22
+ #
23
+ #####################################################################
24
+ #++
25
+
26
+ module ShoesMVC
27
+ module Models
28
+
29
+ class KeyedArrayTableModel < TableModel
30
+
31
+ # This class provides a row adapter for each row in the
32
+ # array so that it behaves effectively like a Hash
33
+ # instance, but which still allows the underlying array to
34
+ # be manipulated without problem.
35
+
36
+ class Row
37
+ # The instance is created with an array of strings or
38
+ # symbols used to denote the keys of the model. The keys
39
+ # MUST be specified in the order of the data elements in
40
+ # the data array. When the model is asked for the value
41
+ # for a given key, the value is retrieved from the data
42
+ # array by the position of the key in the keys array.
43
+
44
+ def initialize(keys, row)
45
+ @keys = keys
46
+ @row = row
47
+ end
48
+
49
+ def [](key)
50
+ @row[@keys[key.to_sym]]
51
+ end
52
+
53
+ def []=(key, val)
54
+ @row[@keys[key.to_sym]] = val
55
+ end
56
+ end
57
+
58
+ # This method is used to initialize the mo
59
+ def initialize(keys, data)
60
+ @keys = {}
61
+ keys.each_with_index { |x, i| @keys[x.to_sym] = i }
62
+ @data = data
63
+ end
64
+
65
+ def keys
66
+ @keys.keys
67
+ end
68
+
69
+ def each(&block)
70
+ @data.each do |x|
71
+ block.call(Row.new(@keys, x))
72
+ end
73
+ end
74
+
75
+ def each_with_index(&block)
76
+ @data.each_with_index do |x, i|
77
+ block.call(Row.new(@keys, x), i)
78
+ end
79
+ end
80
+ end
81
+
82
+ end
83
+ end
@@ -0,0 +1,42 @@
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: table_model.rb
21
+ # Created: Sat 19 Nov 2011 18:13:40 GMT
22
+ #
23
+ #####################################################################
24
+ #++
25
+
26
+ module ShoesMVC
27
+ module Models
28
+
29
+ # This class defines the behavior of a base TableModel API
30
+ # that is used by the TableView class. The model represents
31
+ # an ordered set of data rows which are "square" in that
32
+ # they are expected to all have the same number of columns.
33
+ #
34
+ # Logically, each of the elements in the table model is a
35
+ # row instance that provides keyed property access to the
36
+ # data in the model based on the [] method.
37
+
38
+ class TableModel
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,28 @@
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: models.rb
21
+ # Created: Sat 19 Nov 2011 19:50:32 GMT
22
+ #
23
+ #####################################################################
24
+ #++
25
+
26
+ require 'shoes_mvc/models/table_model'
27
+ require 'shoes_mvc/models/array_table_model'
28
+ require 'shoes_mvc/models/keyed_array_table_model'
@@ -0,0 +1,71 @@
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: ar_model_editor.rb
21
+ # Created: Sat 19 Nov 2011 11:26:37 GMT
22
+ #
23
+ #####################################################################
24
+ #++
25
+
26
+ module ShoesMVC
27
+ module Views
28
+
29
+ # This class is responsible for building a form for the
30
+ # given ActiveRecord model
31
+
32
+ class ActiveRecordModelEditor < Shoes::Widget
33
+ DEFAULTS = {
34
+ :label_width => 0.3
35
+ }.freeze
36
+
37
+ def initialize(model, options = {}, &block)
38
+ super(options, &block)
39
+ load(model, options, &block)
40
+ end
41
+
42
+ # This method is used to load the view with the
43
+ # information in the AR model.
44
+
45
+ def load(model, options = {}, &block)
46
+ lwidth = options[:label_width] || DEFAULTS[:label_width]
47
+
48
+ if(bg = options[:background])
49
+ background bg
50
+ end
51
+
52
+ stack :width => "100%" do
53
+ flow :width => "100%" do
54
+ model.attributes.keys.sort.each do |key|
55
+ value = model.attributes[key]
56
+ flow :width => lwidth, :margin_top => 2 do
57
+ para key, :weight => 'bold', :align => "right"
58
+ end
59
+ flow :width => 1 - lwidth do
60
+ edit_line model.attributes[key] do |e|
61
+ model.attributes[key] = e.text
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,92 @@
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: table_view.rb
21
+ # Created: Sat 19 Nov 2011 20:14:33 GMT
22
+ #
23
+ #####################################################################
24
+ #++
25
+
26
+ module ShoesMVC
27
+ module Views
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
+ class TableView < Shoes::Widget
35
+ def initialize(model, options = {}, &block)
36
+ super(options, &block)
37
+ load(model, options, &block)
38
+ end
39
+
40
+ # This method is used to load the view with the
41
+ # information in the table model.
42
+
43
+ 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
+ end
51
+
52
+ protected
53
+ # This method extracts or creates the column model for the
54
+ # view.
55
+
56
+ def columns(model, options)
57
+ if cols = options[:columns]
58
+ cols
59
+ else
60
+ cols = model.keys.collect do |k|
61
+ { :key => k.to_sym, :label => "#{k.capitalize}" }
62
+ end
63
+ end
64
+ 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
+ para row[col[:key]], col[:style]
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ end
92
+ end
@@ -0,0 +1,27 @@
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: views.rb
21
+ # Created: Sat 19 Nov 2011 11:28:08 GMT
22
+ #
23
+ #####################################################################
24
+ #++
25
+
26
+ require 'shoes_mvc/views/ar_model_editor'
27
+ require 'shoes_mvc/views/table_view'
data/lib/shoes_mvc.rb ADDED
@@ -0,0 +1,29 @@
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: shoes_mvc.rb
21
+ # Created: Sat 19 Nov 2011 11:24:19 GMT
22
+ #
23
+ ######################################################################
24
+ #++
25
+
26
+ require 'yaml'
27
+ require 'shoes_mvc/controllers/app_controller'
28
+ require 'shoes_mvc/models'
29
+ require 'shoes_mvc/views'
data/shoes_mvc.gemspec ADDED
@@ -0,0 +1,38 @@
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: shoes_mvc.gemspec
21
+ # Created: Sat 19 Nov 2011 11:45:06 GMT
22
+ #
23
+ ######################################################################
24
+ #++
25
+
26
+ require 'rake'
27
+
28
+ Gem::Specification.new do |s|
29
+ s.name = "shoes_mvc"
30
+ s.version = "0.0.0"
31
+ s.date = "2011-11-19"
32
+ s.summary = "Shoes MVC"
33
+ s.description = "A basic MVC framework for the Shoes toolkit"
34
+ s.authors = [ "Andrew S. Townley" ]
35
+ s.email = "ast@atownley.org"
36
+ s.files = FileList['lib/**/*.rb', 'test/**/*', '[A-Z]*', 'shoes_mvc.gemspec'].to_a
37
+ s.homepage = "http://atownley.org/shoes_mvc"
38
+ end
@@ -0,0 +1,56 @@
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: test_array_table_model.rb
21
+ # Created: Sat 19 Nov 2011 20:00:25 GMT
22
+ #
23
+ ######################################################################
24
+ #++
25
+
26
+ require 'testy'
27
+ require 'shoes_mvc/models'
28
+
29
+ include ShoesMVC::Models
30
+
31
+ Testy.testing "Core ArrayTableModel tests" do
32
+ test "Basic functionality" do |result|
33
+ keys = [ :foo, :bar ]
34
+ data = [
35
+ { :foo => "Foo1", :bar => "Bar1" },
36
+ { :foo => "Foo2", :bar => "Bar2" } ]
37
+
38
+ model = ArrayTableModel.new(data)
39
+ model.each_with_index do |row, i|
40
+ keys.each do |key|
41
+ result.check "row[#{i}][:#{key}] value is correct",
42
+ :expect => data[i][key],
43
+ :actual => row[key]
44
+ end
45
+ end
46
+
47
+ data << { :foo => "Foo3", :bar => "Bar3" }
48
+ model.each_with_index do |row, i|
49
+ keys.each do |key|
50
+ result.check "row[#{i}][:#{key}] value is correct after add",
51
+ :expect => data[i][key],
52
+ :actual => row[key]
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,54 @@
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: test_keyed_array_table_model.rb
21
+ # Created: Sat 19 Nov 2011 19:17:50 GMT
22
+ #
23
+ ######################################################################
24
+ #++
25
+
26
+ require 'testy'
27
+ require 'shoes_mvc/models'
28
+
29
+ include ShoesMVC::Models
30
+
31
+ Testy.testing "Core KeyedArrayTableModel tests" do
32
+ test "Basic functionality" do |result|
33
+ keys = %w( foo bar )
34
+ data = [ [ "Foo1", "Bar1" ], [ "Foo2", "Bar2" ] ]
35
+
36
+ model = KeyedArrayTableModel.new(keys, data)
37
+ model.each_with_index do |row, i|
38
+ keys.each_with_index do |key, j|
39
+ result.check "row[#{i}][:#{key}] value is correct",
40
+ :expect => data[i][j],
41
+ :actual => row[key]
42
+ end
43
+ end
44
+
45
+ data << [ "Foo3", "Bar3" ]
46
+ model.each_with_index do |row, i|
47
+ keys.each_with_index do |key, j|
48
+ result.check "row[#{i}][:#{key}] value is correct after add",
49
+ :expect => data[i][j],
50
+ :actual => row[key]
51
+ end
52
+ end
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shoes_mvc
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 0
10
+ version: 0.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Andrew S. Townley
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-11-19 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: A basic MVC framework for the Shoes toolkit
23
+ email: ast@atownley.org
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/shoes_mvc/controllers/app_controller.rb
32
+ - lib/shoes_mvc/controllers/rails_controller.rb
33
+ - lib/shoes_mvc/models/array_table_model.rb
34
+ - lib/shoes_mvc/models/keyed_array_table_model.rb
35
+ - lib/shoes_mvc/models/table_model.rb
36
+ - lib/shoes_mvc/models.rb
37
+ - lib/shoes_mvc/views/ar_model_editor.rb
38
+ - lib/shoes_mvc/views/table_view.rb
39
+ - lib/shoes_mvc/views.rb
40
+ - lib/shoes_mvc.rb
41
+ - test/unit/models/test_array_table_model.rb
42
+ - test/unit/models/test_keyed_array_table_model.rb
43
+ - LICENSE
44
+ - README.md
45
+ - shoes_mvc.gemspec
46
+ has_rdoc: true
47
+ homepage: http://atownley.org/shoes_mvc
48
+ licenses: []
49
+
50
+ post_install_message:
51
+ rdoc_options: []
52
+
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.6.2
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Shoes MVC
80
+ test_files: []
81
+