active_presenters 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,157 @@
1
+ module ActivePresenter
2
+
3
+ REST_VERBS = {
4
+ :index => :get,
5
+ :show => :get,
6
+ :new => :get,
7
+ :create => :post,
8
+ :edit => :get,
9
+ :update => :put,
10
+ :destroy => :delete
11
+ }
12
+
13
+ class Base
14
+ include ActionView::Helpers::TagHelper # link_to
15
+ include ActionView::Helpers::UrlHelper # url_for
16
+ include ActionController::UrlWriter # named routes
17
+ include ActionView::Helpers::TextHelper # link_to
18
+ include ActionView::Helpers::FormHelper
19
+ include ActionView::Helpers::FormTagHelper
20
+ include ActionView::Helpers::FormOptionsHelper
21
+ include ActionView::Helpers::ActiveRecordHelper
22
+ include ActionView::Helpers::AssetTagHelper
23
+ include ActionView::Helpers::BenchmarkHelper
24
+ include ActionView::Helpers::CacheHelper
25
+ include ActionView::Helpers::DateHelper
26
+ include ActionView::Helpers::JavaScriptHelper
27
+ include ActionView::Helpers::JavaScriptMacrosHelper
28
+ include ActionView::Helpers::NumberHelper
29
+ include ActionView::Helpers::PaginationHelper
30
+ include ActionView::Helpers::PrototypeHelper
31
+ include ActionView::Helpers::ScriptaculousHelper
32
+ attr_accessor :options
33
+ attr_accessor :model_underscore # => debate_side
34
+ attr_accessor :model_camelcase # => DebateSide
35
+
36
+ def initialize(source, options = {})
37
+ self.model_underscore = source.class.to_s.underscore
38
+ self.model_camelcase = source.class.to_s
39
+ eval %{alias :#{self.model_underscore} :model}
40
+ @model = source
41
+ self.options = options || {}
42
+ if source.is_a? ActiveRecord::Base
43
+ if source.is_restful?
44
+ build_common_ar_resource_methods
45
+ build_ar_resource_methods
46
+ else
47
+ #build_ar_non_resource_methods
48
+ end
49
+ end
50
+ end
51
+
52
+ def model
53
+ @model
54
+ end
55
+
56
+ protected
57
+
58
+ def build_common_ar_resource_methods
59
+ instance_eval do
60
+ unless method_defined?(:destroy_link_options)
61
+ def destroy_link_options
62
+ {:confirm => 'Are you sure?', :method => :delete}
63
+ end
64
+ end
65
+ end
66
+
67
+ instance_eval do
68
+ REST_VERBS.each_pair do |verb, meth|
69
+ eval %{
70
+ unless method_defined?(:#{verb}_link_text)
71
+ def #{verb}_link_text
72
+ "#{verb}"
73
+ end
74
+ end
75
+
76
+ unless method_defined?(:#{verb}_link_options)
77
+ def #{verb}_link_options
78
+ {:method => :#{meth}}
79
+ end
80
+ end
81
+
82
+ unless method_defined?(:#{verb}_link)
83
+ def #{verb}_link(name = #{verb}_link_text, options = {}, html_options = nil, *args)
84
+ options = #{verb}_link_options.merge(options)
85
+ link_to(h(name), #{verb}_path, options, html_options, *args)
86
+ end
87
+ end
88
+ }
89
+ end
90
+ end
91
+ end
92
+
93
+ def build_ar_resource_methods
94
+ instance_eval do
95
+ eval %{
96
+ unless method_defined?(:index_path)
97
+ def index_path
98
+ #{self.plural}_path#{self.model.nested_resource.nil? ? '' : "(self.model.nested_resource)"}
99
+ end
100
+ end
101
+
102
+ unless method_defined?(:show_path)
103
+ def show_path
104
+ #{self.singular}_path(#{self.model.nested_resource.nil? ? '' : "self.model.nested_resource, "}self.model)
105
+ end
106
+ end
107
+
108
+ unless method_defined?(:new_path)
109
+ def new_path
110
+ new_#{self.singular}_path#{self.model.nested_resource.nil? ? '' : "(self.model.nested_resource)"}
111
+ end
112
+ end
113
+
114
+ unless method_defined?(:create_path)
115
+ def create_path
116
+ #{self.plural}_path#{self.model.nested_resource.nil? ? '' : "(self.model.nested_resource)"}
117
+ end
118
+ end
119
+
120
+ unless method_defined?(:edit_path)
121
+ def edit_path
122
+ edit_#{self.singular}_path(#{self.model.nested_resource.nil? ? '' : "self.model.nested_resource, "}self.model)
123
+ end
124
+ end
125
+
126
+ unless method_defined?(:update_path)
127
+ def update_path
128
+ #{self.singular}_path(#{self.model.nested_resource.nil? ? '' : "self.model.nested_resource, "}self.model)
129
+ end
130
+ end
131
+
132
+ unless method_defined?(:destroy_path)
133
+ def destroy_path
134
+ #{self.singular}_path(#{self.model.nested_resource.nil? ? '' : "self.model.nested_resource, "}self.model)
135
+ end
136
+ end
137
+ }
138
+
139
+ end
140
+
141
+ end
142
+
143
+ def plural
144
+ self.model_underscore.pluralize
145
+ end
146
+
147
+ def singular
148
+ self.model_underscore.singularize
149
+ end
150
+
151
+ def method_defined?(meth)
152
+ self.methods.include?("#{meth}")
153
+ end
154
+
155
+ end
156
+
157
+ end
@@ -5,9 +5,9 @@ puts path
5
5
 
6
6
  FileUtils.mkdir_p(path) unless File.exists?(path)
7
7
 
8
+ require 'active_presenter_base'
8
9
  require 'presentable'
9
10
  require 'proxy'
10
- require 'base'
11
11
 
12
12
  Find.find(path) do |f|
13
13
  if FileTest.directory?(f) and f =~ /\.svn/
@@ -20,6 +20,8 @@ Find.find(path) do |f|
20
20
  model = m.to_s
21
21
  x = model.gsub('/', '').gsub('.rb', '')
22
22
  begin
23
+ puts "x = #{x}"
24
+ puts "path/x = #{path}/#{x}"
23
25
  require "#{path}/#{x}"
24
26
  rescue => ex
25
27
  puts ex
data/lib/ar_hooks.rb CHANGED
@@ -1,13 +0,0 @@
1
- # class << ActiveRecord::Base
2
- #
3
- # alias_method :ar_find, :find
4
- #
5
- # def find(*args)
6
- # res = ar_find(*args)
7
- # if res.is_a? Array
8
- # res.is_presentable = true
9
- # end
10
- # res
11
- # end
12
- #
13
- # end
data/lib/presentable.rb CHANGED
@@ -36,7 +36,7 @@ module ActivePresenter
36
36
  end
37
37
 
38
38
  def is_restful?
39
- return self.is_a? ActiveRecord::Base
39
+ return self.is_a?(ActiveRecord::Base)
40
40
  end
41
41
 
42
42
  attr_accessor :nested_resource
@@ -2,4 +2,4 @@
2
2
  gem_name: active_presenters
3
3
  package: active_presenters
4
4
  project: magrathea
5
- version: 1.0.0
5
+ version: 1.0.1
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: active_presenters
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.0
7
- date: 2007-09-11 00:00:00 -04:00
6
+ version: 1.0.1
7
+ date: 2007-09-14 00:00:00 -04:00
8
8
  summary: active_presenters
9
9
  require_paths:
10
10
  - lib
@@ -16,18 +16,11 @@ homepage:
16
16
  rubyforge_project: magrathea
17
17
  description: "active_presenters was developed by: markbates"
18
18
  autorequire:
19
- - proxy
20
- - presentable
21
- - base
22
- - ar_hooks
23
19
  - active_presenters
24
- - ac_hooks
25
20
  - proxy
26
21
  - presentable
27
- - base
28
22
  - ar_hooks
29
- - active_presenters
30
- - ac_hooks
23
+ - active_presenter_base
31
24
  default_executable:
32
25
  bindir: bin
33
26
  has_rdoc: false
@@ -45,10 +38,9 @@ authors:
45
38
  - markbates
46
39
  files:
47
40
  - init.rb
48
- - lib/ac_hooks.rb
41
+ - lib/active_presenter_base.rb
49
42
  - lib/active_presenters.rb
50
43
  - lib/ar_hooks.rb
51
- - lib/base.rb
52
44
  - lib/presentable.rb
53
45
  - lib/proxy.rb
54
46
  - lib/tasks/rubyforge_config.yml
data/lib/ac_hooks.rb DELETED
@@ -1,33 +0,0 @@
1
- # module ActionController
2
- # class Base
3
- # alias_method :ac_render, :render
4
- #
5
- # def render(options = nil, deprecated_status = nil, &block)
6
- # puts "in active_presenter render"
7
- # self.instance_variables.each do |v|
8
- # puts "v = #{v}"
9
- # var = self.instance_variable_get(v)
10
- # puts "var = #{var.class}"
11
- # puts "var.is_presentable? = #{var.is_presentable?}"
12
- # if var.is_presentable?
13
- # if var.is_a? Array
14
- # presenters = []
15
- # var.each do |a|
16
- # if a.is_presentable?
17
- # presenter = a.build_presenter(self)
18
- # presenters << presenter
19
- # end
20
- # end
21
- # self.instance_variable_set("#{v.singularize}_presenters".to_sym, presenters)
22
- # else
23
- # presenter = var.build_presenter(self)
24
- # # puts "presenter = #{presenter.inspect}"
25
- # self.instance_variable_set("#{v.singularize}_presenter".to_sym, presenter)
26
- # end
27
- # end
28
- # end
29
- # ac_render(options, deprecated_status, &block)
30
- # end
31
- #
32
- # end
33
- # end
data/lib/base.rb DELETED
@@ -1,142 +0,0 @@
1
- module ActivePresenter
2
-
3
- REST_VERBS = {
4
- :index => :get,
5
- :show => :get,
6
- :new => :get,
7
- :create => :post,
8
- :edit => :get,
9
- :update => :put,
10
- :destroy => :delete
11
- }
12
-
13
- class Base
14
-
15
- include ActionView::Helpers::TagHelper # link_to
16
- include ActionView::Helpers::UrlHelper # url_for
17
- include ActionController::UrlWriter # named routes
18
- include ActionView::Helpers::TextHelper # link_to
19
- include ActionView::Helpers::FormHelper
20
- include ActionView::Helpers::FormTagHelper
21
- include ActionView::Helpers::FormOptionsHelper
22
- attr_accessor :options
23
- attr_accessor :model_underscore # => debate_side
24
- attr_accessor :model_camelcase # => DebateSide
25
-
26
- def initialize(source, options = {})
27
- self.model_underscore = source.class.to_s.underscore
28
- self.model_camelcase = source.class.to_s
29
- eval %{alias :#{self.model_underscore} :model}
30
- @model = source
31
- self.options = options || {}
32
- if source.is_a? ActiveRecord::Base
33
- if source.is_restful?
34
- build_common_ar_resource_methods
35
- build_ar_resource_methods
36
- else
37
- #build_ar_non_resource_methods
38
- end
39
- end
40
- end
41
-
42
- def model
43
- @model
44
- end
45
-
46
- protected
47
-
48
- def build_common_ar_resource_methods
49
-
50
- instance_eval do
51
- unless method_defined?(:destroy_link_options)
52
- def destroy_link_options
53
- {:confirm => 'Are you sure?', :method => :delete}
54
- end
55
- end
56
- end
57
-
58
- REST_VERBS.each_pair do |verb, meth|
59
- instance_eval %{
60
- unless method_defined?(:#{verb}_link_text)
61
- def #{verb}_link_text
62
- "#{verb}"
63
- end
64
- end
65
-
66
- unless method_defined?(:#{verb}_link_options)
67
- def #{verb}_link_options
68
- {:method => :#{meth}}
69
- end
70
- end
71
-
72
- unless method_defined?(:#{verb}_link)
73
- def #{verb}_link(name = #{verb}_link_text, options = {}, html_options = nil, *args)
74
- options = #{verb}_link_options.merge(options)
75
- link_to(h(name), #{verb}_path, options, html_options, *args)
76
- end
77
- end
78
- }
79
- end
80
- end
81
-
82
- def build_ar_resource_methods
83
- instance_eval %{
84
- unless method_defined?(:index_path)
85
- def index_path
86
- #{self.plural}_path#{self.model.nested_resource.nil? ? '' : "(self.model.nested_resource)"}
87
- end
88
- end
89
-
90
- unless method_defined?(:show_path)
91
- def show_path
92
- #{self.singular}_path(#{self.model.nested_resource.nil? ? '' : "self.model.nested_resource, "}self.model)
93
- end
94
- end
95
-
96
- unless method_defined?(:new_path)
97
- def new_path
98
- new_#{self.singular}_path#{self.model.nested_resource.nil? ? '' : "(self.model.nested_resource)"}
99
- end
100
- end
101
-
102
- unless method_defined?(:create_path)
103
- def create_path
104
- #{self.plural}_path#{self.model.nested_resource.nil? ? '' : "(self.model.nested_resource)"}
105
- end
106
- end
107
-
108
- unless method_defined?(:edit_path)
109
- def edit_path
110
- edit_#{self.singular}_path(#{self.model.nested_resource.nil? ? '' : "self.model.nested_resource, "}self.model)
111
- end
112
- end
113
-
114
- unless method_defined?(:update_path)
115
- def update_path
116
- #{self.singular}_path(#{self.model.nested_resource.nil? ? '' : "self.model.nested_resource, "}self.model)
117
- end
118
- end
119
-
120
- unless method_defined?(:destroy_path)
121
- def destroy_path
122
- #{self.singular}_path(#{self.model.nested_resource.nil? ? '' : "self.model.nested_resource, "}self.model)
123
- end
124
- end
125
- }
126
- end
127
-
128
- def plural
129
- self.model_underscore.pluralize
130
- end
131
-
132
- def singular
133
- self.model_underscore.singularize
134
- end
135
-
136
- def method_defined?(meth)
137
- self.methods.include?("#{meth}")
138
- end
139
-
140
- end
141
-
142
- end