shoes_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.
- data/README.md +39 -3
- data/lib/shoes_mvc.rb +1 -0
- data/lib/shoes_mvc/controllers/app_controller.rb +26 -0
- data/lib/shoes_mvc/module.rb +35 -0
- data/lib/shoes_mvc/views.rb +21 -1
- data/lib/shoes_mvc/views/ar_model_editor.rb +21 -1
- data/lib/shoes_mvc/views/ar_type_editor.rb +65 -0
- data/lib/shoes_mvc/views/ar_type_list.rb +45 -0
- data/lib/shoes_mvc/views/table_view.rb +6 -2
- data/shoes_mvc.gemspec +1 -2
- data/test/unit/test_array_table_model.rb +38 -0
- metadata +8 -4
data/README.md
CHANGED
@@ -6,12 +6,48 @@ This project provides a basic MVC framework on top of the Shoes
|
|
6
6
|
environment for those of us strange people who have done MVC so long
|
7
7
|
it's extremely difficult to think about applications other ways.
|
8
8
|
|
9
|
+
*NOTE: this code is **highly experimental** and an early work in
|
10
|
+
progress. It wouldn't be wise to rely on it right now for anything
|
11
|
+
other than experiments, prototypes and proofs of concept.*
|
12
|
+
|
9
13
|
Installation
|
10
14
|
============
|
11
15
|
|
12
|
-
|
13
|
-
|
14
|
-
|
16
|
+
The normal way to ensure this gem is installed is to add it to the
|
17
|
+
Shoes.setup block, e.g.
|
18
|
+
|
19
|
+
Shoes.setup do
|
20
|
+
gem 'shoes_mvc'
|
21
|
+
end
|
22
|
+
|
23
|
+
As of version 0.0.0, it's available as a gem from rubygems.org, so
|
24
|
+
this should just work. If you're using the Rails integration, you'll
|
25
|
+
also need to have a version of ActiveRecord installed.
|
26
|
+
|
27
|
+
If you're building it manually (because you're hacking on it), then
|
28
|
+
you'll need to install it yourself in the local Shoes gem directory
|
29
|
+
for your user. On MacOS X, you can do it like this:
|
15
30
|
|
16
31
|
$ gem build shoes_mvc.gemspec
|
17
32
|
$ gem install --install-dir $HOME/.shoes/+gem ./*.gem
|
33
|
+
|
34
|
+
Known Issues
|
35
|
+
============
|
36
|
+
|
37
|
+
The following issues are related to getting this gem actually
|
38
|
+
installed and working as expected:
|
39
|
+
|
40
|
+
* http://librelist.com/browser/shoes/2011/11/18/a-tangled-web-mess-of-dependencies-encoding-vs-sqlite3-vs-activerecord/
|
41
|
+
* https://github.com/shoes/shoes/issues/163
|
42
|
+
* https://github.com/shoes/shoes/issues/164
|
43
|
+
|
44
|
+
Additional Encoding Hack
|
45
|
+
------------------------
|
46
|
+
|
47
|
+
With Policeman, the Encoding class doesn't seem to actually be defined
|
48
|
+
completely. As a result, anything to do with Encoding and
|
49
|
+
ActiveRecord chokes fairly hard. The "solution" is to hack the
|
50
|
+
encoding.rb file in activesupport so that it
|
51
|
+
defines #encoding_supported? as false. Neat, huh?
|
52
|
+
|
53
|
+
Hopefully, this will all get fixed with the next release of Shoes. :(
|
data/lib/shoes_mvc.rb
CHANGED
@@ -25,6 +25,30 @@
|
|
25
25
|
|
26
26
|
module ShoesMVC
|
27
27
|
|
28
|
+
# This module takes care of dispatching links to controller
|
29
|
+
# classes.
|
30
|
+
|
31
|
+
module LinkDispatcher
|
32
|
+
# This method is a callback to allow links embedded in
|
33
|
+
# views to trigger controller actions in a loosely-coupled
|
34
|
+
# manner.
|
35
|
+
#
|
36
|
+
# The default implementation will attempt to call methods
|
37
|
+
# based on applying the ShoesMVC#method_name
|
38
|
+
# transformation and checking if the controller responds
|
39
|
+
# to the method. To manually dispatch the method, simply
|
40
|
+
# override this method in the derived class.
|
41
|
+
|
42
|
+
def link_activated(sender, link)
|
43
|
+
@shoes.debug("#link_activated(#{sender}, #{link}")
|
44
|
+
m = ShoesMVC.method_name(link).to_sym
|
45
|
+
if self.respond_to? m
|
46
|
+
@shoes.debug("dispatching to ##{m}")
|
47
|
+
self.send(m, sender, link)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
28
52
|
# This controller is used to assist in writing Shoes
|
29
53
|
# applications for an existing Rails application. All of
|
30
54
|
# the models will be automatically loaded based on the
|
@@ -32,6 +56,8 @@ module ShoesMVC
|
|
32
56
|
# database connection environment will be used.
|
33
57
|
|
34
58
|
class AppController
|
59
|
+
include LinkDispatcher
|
60
|
+
|
35
61
|
# The controller is instantiated by an
|
36
62
|
# application-specific controller instance that passes
|
37
63
|
# through the location of the appication controller source
|
@@ -0,0 +1,35 @@
|
|
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: module.rb
|
21
|
+
# Created: Sat 19 Nov 2011 11:24:19 GMT
|
22
|
+
#
|
23
|
+
######################################################################
|
24
|
+
#++
|
25
|
+
|
26
|
+
module ShoesMVC
|
27
|
+
# This method is used to convert a name to a method name.
|
28
|
+
# It is borrowed and adapted from shoes.rb:538-540.
|
29
|
+
|
30
|
+
def self.method_name(str)
|
31
|
+
str.to_s.gsub("/", "").gsub("::", "_").
|
32
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
33
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').downcase
|
34
|
+
end
|
35
|
+
end
|
data/lib/shoes_mvc/views.rb
CHANGED
@@ -23,5 +23,25 @@
|
|
23
23
|
#####################################################################
|
24
24
|
#++
|
25
25
|
|
26
|
-
|
26
|
+
module ShoesMVC
|
27
|
+
module Views
|
28
|
+
|
29
|
+
# This is the base view class that provides integration
|
30
|
+
# with the controllers
|
31
|
+
|
32
|
+
class View < Shoes::Widget
|
33
|
+
attr_accessor :controller
|
34
|
+
|
35
|
+
def initialize(*args)
|
36
|
+
if(options = args.last).is_a? Hash
|
37
|
+
self.controller = options[:controller]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
27
44
|
require 'shoes_mvc/views/table_view'
|
45
|
+
require 'shoes_mvc/views/ar_model_editor'
|
46
|
+
require 'shoes_mvc/views/ar_type_list'
|
47
|
+
require 'shoes_mvc/views/ar_type_editor'
|
@@ -52,18 +52,38 @@ module Views
|
|
52
52
|
stack :width => "100%" do
|
53
53
|
flow :width => "100%" do
|
54
54
|
model.attributes.keys.sort.each do |key|
|
55
|
+
# FIXME: I can't believe that you have to do this
|
56
|
+
# this way with AR. I'm surely missing
|
57
|
+
# something...
|
58
|
+
m = "#{key}=".to_sym
|
55
59
|
value = model.attributes[key]
|
56
60
|
flow :width => lwidth, :margin_top => 2 do
|
57
61
|
para key, :weight => 'bold', :align => "right"
|
58
62
|
end
|
59
63
|
flow :width => 1 - lwidth do
|
60
64
|
edit_line model.attributes[key] do |e|
|
61
|
-
model.
|
65
|
+
model.send(m, e.text)
|
62
66
|
end
|
63
67
|
end
|
64
68
|
end
|
65
69
|
end
|
66
70
|
end
|
71
|
+
|
72
|
+
@model = model
|
73
|
+
@options = options
|
74
|
+
end
|
75
|
+
|
76
|
+
def save
|
77
|
+
debug("model: #{@model.inspect}")
|
78
|
+
@model.save!
|
79
|
+
end
|
80
|
+
|
81
|
+
def create
|
82
|
+
if @model
|
83
|
+
load(@model.class.new, options)
|
84
|
+
else
|
85
|
+
alert("No template model.\nUse the #load method instead.")
|
86
|
+
end
|
67
87
|
end
|
68
88
|
end
|
69
89
|
|
@@ -0,0 +1,65 @@
|
|
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_type_editor.rb
|
21
|
+
# Created: Mon 21 Nov 2011 18:00:49 GMT
|
22
|
+
#
|
23
|
+
#####################################################################
|
24
|
+
#++
|
25
|
+
|
26
|
+
module ShoesMVC
|
27
|
+
module Views
|
28
|
+
|
29
|
+
class ActiveRecordTypeEditor < View
|
30
|
+
include ShoesMVC::LinkDispatcher
|
31
|
+
|
32
|
+
def initialize(type, options = {}, &block)
|
33
|
+
ctrl = options[:controller] = options[:controller] || self
|
34
|
+
super(options, &block)
|
35
|
+
@type = type
|
36
|
+
@list = active_record_type_list type
|
37
|
+
para link("New...") {
|
38
|
+
ctrl.link_activated(self, "/create_instance")
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def create_instance(sender, link)
|
43
|
+
debug("create instance of type #{@type}")
|
44
|
+
obj = @type.new
|
45
|
+
window do
|
46
|
+
stack do
|
47
|
+
obj.description = "Some text"
|
48
|
+
editor = active_record_model_editor obj
|
49
|
+
flow :margin_left => 0, :left => "-25%" do
|
50
|
+
button "Cancel", :align => "right" do
|
51
|
+
close
|
52
|
+
end
|
53
|
+
button "Save", :align => "right" do
|
54
|
+
editor.save
|
55
|
+
close
|
56
|
+
end
|
57
|
+
debug("created buttons")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,45 @@
|
|
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_type_list.rb
|
21
|
+
# Created: Mon 21 Nov 2011 15:57:27 GMT
|
22
|
+
#
|
23
|
+
#####################################################################
|
24
|
+
#++
|
25
|
+
|
26
|
+
module ShoesMVC
|
27
|
+
module Views
|
28
|
+
|
29
|
+
class ActiveRecordTypeList < TableView
|
30
|
+
def load(model, options = {}, &block)
|
31
|
+
@entity_type = model
|
32
|
+
super(model.find(options[:query] || :all), options, &block)
|
33
|
+
end
|
34
|
+
|
35
|
+
def columns(model, options)
|
36
|
+
cols = []
|
37
|
+
@entity_type.attribute_names.each do |key|
|
38
|
+
cols << { :key => key, :label => key.capitalize }
|
39
|
+
end
|
40
|
+
cols
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -31,7 +31,7 @@ module Views
|
|
31
31
|
# requires that the data to be displayed be supplied as a
|
32
32
|
# TableModel instance.
|
33
33
|
|
34
|
-
class TableView <
|
34
|
+
class TableView < View
|
35
35
|
def initialize(model, options = {}, &block)
|
36
36
|
super(options, &block)
|
37
37
|
load(model, options, &block)
|
@@ -81,7 +81,11 @@ module Views
|
|
81
81
|
flow do
|
82
82
|
cols.each do |col|
|
83
83
|
flow(:width => defw) do
|
84
|
-
|
84
|
+
if(r = col[:renderer])
|
85
|
+
r.render(self, row, col)
|
86
|
+
else
|
87
|
+
para row[col[:key]], col[:style]
|
88
|
+
end
|
85
89
|
end
|
86
90
|
end
|
87
91
|
end
|
data/shoes_mvc.gemspec
CHANGED
@@ -27,8 +27,7 @@ require 'rake'
|
|
27
27
|
|
28
28
|
Gem::Specification.new do |s|
|
29
29
|
s.name = "shoes_mvc"
|
30
|
-
s.version = "0.0.
|
31
|
-
s.date = "2011-11-19"
|
30
|
+
s.version = "0.0.2"
|
32
31
|
s.summary = "Shoes MVC"
|
33
32
|
s.description = "A basic MVC framework for the Shoes toolkit"
|
34
33
|
s.authors = [ "Andrew S. Townley" ]
|
@@ -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: test_shoes_mvc.rb
|
21
|
+
# Created: Mon 21 Nov 2011 18:10:45 GMT
|
22
|
+
#
|
23
|
+
######################################################################
|
24
|
+
#++
|
25
|
+
|
26
|
+
require 'testy'
|
27
|
+
require 'shoes_mvc/module'
|
28
|
+
|
29
|
+
Testy.testing "Core module tests" do
|
30
|
+
test "Basic functionality" do |result|
|
31
|
+
data = %w( some_path some_path module_klass )
|
32
|
+
%w( /some_path /somePath Module::Klass ).each_with_index do |uri, i|
|
33
|
+
result.check "uri to method_name #{uri}",
|
34
|
+
:expect => data[i],
|
35
|
+
:actual => ShoesMVC.method_name(uri)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shoes_mvc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andrew S. Townley
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-11-
|
18
|
+
date: 2011-11-21 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -34,12 +34,16 @@ files:
|
|
34
34
|
- lib/shoes_mvc/models/keyed_array_table_model.rb
|
35
35
|
- lib/shoes_mvc/models/table_model.rb
|
36
36
|
- lib/shoes_mvc/models.rb
|
37
|
+
- lib/shoes_mvc/module.rb
|
37
38
|
- lib/shoes_mvc/views/ar_model_editor.rb
|
39
|
+
- lib/shoes_mvc/views/ar_type_editor.rb
|
40
|
+
- lib/shoes_mvc/views/ar_type_list.rb
|
38
41
|
- lib/shoes_mvc/views/table_view.rb
|
39
42
|
- lib/shoes_mvc/views.rb
|
40
43
|
- lib/shoes_mvc.rb
|
41
44
|
- test/unit/models/test_array_table_model.rb
|
42
45
|
- test/unit/models/test_keyed_array_table_model.rb
|
46
|
+
- test/unit/test_array_table_model.rb
|
43
47
|
- LICENSE
|
44
48
|
- README.md
|
45
49
|
- shoes_mvc.gemspec
|