active_presenter_generator 1.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.
@@ -0,0 +1,16 @@
|
|
1
|
+
class ActivePresenterGenerator < Rails::Generator::NamedBase
|
2
|
+
def manifest
|
3
|
+
record do |m|
|
4
|
+
|
5
|
+
unless file_name.match(/_presenter/)
|
6
|
+
file_name << "_presenter"
|
7
|
+
class_name << "Presenter"
|
8
|
+
end
|
9
|
+
|
10
|
+
m.class_collisions class_name
|
11
|
+
|
12
|
+
m.template("app/presenters/presenter.template", "app/presenters/#{file_name}.rb")
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
=begin
|
2
|
+
General Notes:
|
3
|
+
attr_accessor :options # => returns the options hash for this Presenter.
|
4
|
+
attr_accessor :model_underscore # => returns the underscore version of the model's name. ie. 'debate_side'
|
5
|
+
attr_accessor :model_camelcase # => returns the camelcase version of the model's name. ie. 'DebateSide'
|
6
|
+
|
7
|
+
ActiveRecord (AR) Notes:
|
8
|
+
If you are using a presenter with AR then the source
|
9
|
+
will automatically be set to the AR object you are using.
|
10
|
+
Because of this, and trying to make things easier to use,
|
11
|
+
if you want to pass options into the initialize method you will need
|
12
|
+
to override the method presenter_options in your AR model.
|
13
|
+
|
14
|
+
Your AR model will be available via a method called model
|
15
|
+
self.model => your AR object
|
16
|
+
An alias of the model method is also created that uses
|
17
|
+
the underscore version of your model name.
|
18
|
+
Model Name is DebateSide
|
19
|
+
self.debate_side aliases self.model
|
20
|
+
|
21
|
+
By default ActivePresenter assumes that your AR model
|
22
|
+
is a RESTful model. If it is not RESTful then you need
|
23
|
+
to override the is_restful? method in your AR model and
|
24
|
+
have it return false.
|
25
|
+
def is_restful?
|
26
|
+
false
|
27
|
+
end
|
28
|
+
|
29
|
+
If your AR model is RESTful it will build the following
|
30
|
+
methods by default for each RESTful verb:
|
31
|
+
|
32
|
+
#{verb}_link_text # => this is the default text for the #{verb}_link method
|
33
|
+
#{verb}_link_options # => this is the default set of options for the #{verb}_link
|
34
|
+
method. This includes the proper 'method', ie get, put, post, delete,
|
35
|
+
that this link needs. If you override this method, make sure you set
|
36
|
+
the method correctly, or you may get the wrong url!
|
37
|
+
#{verb}_link # => this generates the default link_to string for this verb.
|
38
|
+
# => Params: (name = #{verb}_link_text, options = {}, html_options = nil, *args)
|
39
|
+
#{verb}_path # => this generates the proper path for this verb.
|
40
|
+
|
41
|
+
REST_VERBS = {
|
42
|
+
:index => :get,
|
43
|
+
:show => :get,
|
44
|
+
:new => :get,
|
45
|
+
:create => :post,
|
46
|
+
:edit => :get,
|
47
|
+
:update => :put,
|
48
|
+
:destroy => :delete
|
49
|
+
}
|
50
|
+
|
51
|
+
The destroy_link_options method has a caveat, unlike the other #{verb}_link_options
|
52
|
+
methods, the destroy_link_options method also adds a confirmation popup to the options,
|
53
|
+
as well as the verb.
|
54
|
+
|
55
|
+
=> {:confirm => 'Are you sure?', :method => :delete}
|
56
|
+
|
57
|
+
By default ActivePresenter assumes that your AR model is not
|
58
|
+
a nested resource. It does this by checking the nested_resource method
|
59
|
+
in your AR model. By default this method will return nil. If it returns nil
|
60
|
+
it generates the default methods. However, if this method returns an object,
|
61
|
+
such as another AR model, it will generate nested resource methods for you.
|
62
|
+
|
63
|
+
Some Gotcha's:
|
64
|
+
To use a 'render' method you must have access to the view. You'll need to pass the view
|
65
|
+
from into the presenter method in order to use it.
|
66
|
+
|
67
|
+
example:
|
68
|
+
def render_simple(view)
|
69
|
+
view.render :partial => "foo"
|
70
|
+
end
|
71
|
+
|
72
|
+
To use image_tag you need to set an @controller instance variable before you call image_tag.
|
73
|
+
This can be done by passing the view in as follows:
|
74
|
+
|
75
|
+
example:
|
76
|
+
def my_image(view)
|
77
|
+
@controller = view.controller
|
78
|
+
image_tag("my_image.gif")
|
79
|
+
end
|
80
|
+
=end
|
81
|
+
class <%=class_name%> < ActivePresenter::Base
|
82
|
+
|
83
|
+
end
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.2
|
3
|
+
specification_version: 1
|
4
|
+
name: active_presenter_generator
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 1.0.0
|
7
|
+
date: 2007-09-11 00:00:00 -04:00
|
8
|
+
summary: active_presenter_generator
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
- lib
|
12
|
+
- lib
|
13
|
+
- lib/tasks
|
14
|
+
email:
|
15
|
+
homepage:
|
16
|
+
rubyforge_project: magrathea
|
17
|
+
description: "active_presenter_generator was developed by: markbates"
|
18
|
+
autorequire: []
|
19
|
+
|
20
|
+
default_executable:
|
21
|
+
bindir: bin
|
22
|
+
has_rdoc: false
|
23
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 0.0.0
|
28
|
+
version:
|
29
|
+
platform: ruby
|
30
|
+
signing_key:
|
31
|
+
cert_chain:
|
32
|
+
post_install_message:
|
33
|
+
authors:
|
34
|
+
- markbates
|
35
|
+
files:
|
36
|
+
- active_presenter_generator.rb
|
37
|
+
- lib/tasks/rubyforge_config.yml
|
38
|
+
- templates/app/presenters/presenter.template
|
39
|
+
test_files: []
|
40
|
+
|
41
|
+
rdoc_options: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
executables: []
|
46
|
+
|
47
|
+
extensions: []
|
48
|
+
|
49
|
+
requirements: []
|
50
|
+
|
51
|
+
dependencies: []
|
52
|
+
|