Class: Cms::Portlet
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Cms::Portlet
show all
- Defined in:
- app/models/cms/portlet.rb
Instance Attribute Summary collapse
-
#connect_to_container ⇒ Object
These are here simply to temporarily hold these values Makes it easy to pass them through the process of selecting a portlet type.
-
#connect_to_page_id ⇒ Object
These are here simply to temporarily hold these values Makes it easy to pass them through the process of selecting a portlet type.
-
#controller ⇒ Object
These are here simply to temporarily hold these values Makes it easy to pass them through the process of selecting a portlet type.
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#connect_to_container ⇒ Object
These are here simply to temporarily hold these values Makes it easy to pass them through the process of selecting a portlet type
8
9
10
|
# File 'app/models/cms/portlet.rb', line 8
def connect_to_container
@connect_to_container
end
|
#connect_to_page_id ⇒ Object
These are here simply to temporarily hold these values Makes it easy to pass them through the process of selecting a portlet type
8
9
10
|
# File 'app/models/cms/portlet.rb', line 8
def connect_to_page_id
@connect_to_page_id
end
|
#controller ⇒ Object
These are here simply to temporarily hold these values Makes it easy to pass them through the process of selecting a portlet type
8
9
10
|
# File 'app/models/cms/portlet.rb', line 8
def controller
@controller
end
|
Class Method Details
.columns_for_index ⇒ Object
129
130
131
132
133
|
# File 'app/models/cms/portlet.rb', line 129
def self.columns_for_index
[{:label => "Name", :method => :name, :order => "name"},
{:label => "Type", :method => :type_name, :order => "type"},
{:label => "Updated On", :method => :updated_on_string, :order => "updated_at"}]
end
|
.connectable? ⇒ Boolean
Duck typing (like a ContentBlock) for determining if this block should have a usages link or not.
136
137
138
|
# File 'app/models/cms/portlet.rb', line 136
def self.connectable?
true
end
|
.default_template ⇒ Object
79
80
81
82
83
84
85
|
# File 'app/models/cms/portlet.rb', line 79
def self.default_template
template_file = ActionController::Base.view_paths.map do |vp|
path = vp.to_s.first == "/" ? vp.to_s : Rails.root.join(vp.to_s)
Dir[File.join(path, default_template_path) + '.*']
end.flatten.first
template_file ? open(template_file) { |f| f.read } : ""
end
|
.default_template_path ⇒ Object
91
92
93
|
# File 'app/models/cms/portlet.rb', line 91
def self.default_template_path
@default_template_path ||= "portlets/#{name.tableize.sub('_portlets', '')}/render"
end
|
.enable_template_editor(enabled) ⇒ Object
Determines if the template editor in the CMS UI will be enabled when creating or editing instances of this portlet If enabled, the portlet will use the template code stored in the database. If not, it will render from the render.html.erb file created.
111
112
113
|
# File 'app/models/cms/portlet.rb', line 111
def self.enable_template_editor (enabled)
render_inline enabled
end
|
75
76
77
|
# File 'app/models/cms/portlet.rb', line 75
def self.form
"portlets/#{name.tableize.sub('_portlets', '')}/form"
end
|
.get_subclass(type) ⇒ Object
65
66
67
68
|
# File 'app/models/cms/portlet.rb', line 65
def self.get_subclass(type)
raise "Unknown Portlet Type" unless types.map(&:name).include?(type)
type.constantize
end
|
.handler(handler_type) ⇒ Object
104
105
106
|
# File 'app/models/cms/portlet.rb', line 104
def self.handler(handler_type)
define_method(:handler) { handler_type }
end
|
.has_edit_link? ⇒ Boolean
51
52
53
|
# File 'app/models/cms/portlet.rb', line 51
def self.has_edit_link?
false
end
|
.render_inline(*args) ⇒ Object
115
116
117
118
119
120
121
122
123
|
# File 'app/models/cms/portlet.rb', line 115
def self.render_inline(*args)
if args.length > 0
@render_inline = args.first
elsif !defined?(@render_inline)
@render_inline = true
else
@render_inline
end
end
|
.set_default_template_path(s) ⇒ Object
87
88
89
|
# File 'app/models/cms/portlet.rb', line 87
def self.set_default_template_path(s)
@default_template_path = s
end
|
.types ⇒ Object
55
56
57
58
59
60
61
62
63
|
# File 'app/models/cms/portlet.rb', line 55
def self.types
@types ||= ActiveSupport::Dependencies.autoload_paths.map do |d|
if d =~ /app\/portlets/
Dir["#{d}/*_portlet.rb"].map do |p|
File.basename(p, ".rb").classify
end
end
end.flatten.compact.uniq.sort
end
|
Instance Method Details
#inline_options ⇒ Object
Called by ‘render’ to determine if this portlet should render itself using a file (render.html.erb) or using its ‘template’ attribute.
97
98
99
100
101
102
|
# File 'app/models/cms/portlet.rb', line 97
def inline_options
options = {}
options[:inline] = self.template if self.class.render_inline && !(self.template.nil? || self.template.blank?)
options[:type] = self.handler unless self.handler.blank?
options
end
|
#instance_name ⇒ Object
149
150
151
|
# File 'app/models/cms/portlet.rb', line 149
def instance_name
"#{self.class.name.demodulize.underscore}_#{id}"
end
|
#page_title(new_title) ⇒ Object
Used by portlets to set a custom title, typically in the render body. For example, this allows a page with a single portlet that might display a content block to set the page name to that block name.
145
146
147
|
# File 'app/models/cms/portlet.rb', line 145
def page_title(new_title)
controller.current_page.title = new_title
end
|
#portlet_type_name ⇒ Object
71
72
73
|
# File 'app/models/cms/portlet.rb', line 71
def portlet_type_name
type.titleize
end
|
#store_errors_in_flash(errors) ⇒ Object
This will convert the errors object into a hash and then store it in the flash under the key #Cms::Portlet.portletportlet.instance_name_errors
175
176
177
178
|
# File 'app/models/cms/portlet.rb', line 175
def store_errors_in_flash(errors)
store_hash_in_flash("#{instance_name}_errors",
errors.inject({}) { |h, (k, v)| h[k] = v; h })
end
|
#store_hash_in_flash(key, hash) ⇒ Object
180
181
182
183
184
185
186
187
|
# File 'app/models/cms/portlet.rb', line 180
def store_hash_in_flash(key, hash)
flash[key] = hash.inject(HashWithIndifferentAccess.new) do |p, (k, v)|
unless StringIO === v || Tempfile === v
p[k.to_sym] = v
end
p
end
end
|
#store_params_in_flash ⇒ Object
This will copy all the params from this request into the flash. The key in the flash with be the portlet instance_name and the value will be the hash of all the params, except the params that have values that are a StringIO or a Tempfile will be left out.
169
170
171
|
# File 'app/models/cms/portlet.rb', line 169
def store_params_in_flash
store_hash_in_flash instance_name, params
end
|
#type_name ⇒ Object
125
126
127
|
# File 'app/models/cms/portlet.rb', line 125
def type_name
type.to_s.titleize
end
|
#url_for_failure ⇒ Object
159
160
161
162
163
|
# File 'app/models/cms/portlet.rb', line 159
def url_for_failure
[params[:failure_url], self.failure_url, request.referer].detect do |e|
!e.blank?
end
end
|
#url_for_success ⇒ Object
153
154
155
156
157
|
# File 'app/models/cms/portlet.rb', line 153
def url_for_success
[params[:success_url], self.success_url, request.referer].detect do |e|
!e.blank?
end
end
|