Class: Cms::Portlet
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Cms::Portlet
- Defined in:
- app/models/cms/portlet.rb
Direct Known Subclasses
DeprecatedPlaceholder, DynamicPortlet, EmailPagePortlet, ForgotPasswordPortlet, ListPortlet, LoginPortlet, TagCloudPortlet
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
-
.blacklist ⇒ Array<String>
Returns a blacklist of all content types that shouldn’t be accessible.
-
.blacklisted?(type_name) ⇒ Boolean
Determines if a content_type is blacklisted or not.
- .columns_for_index ⇒ Object
-
.connectable? ⇒ Boolean
Duck typing (like a ContentBlock) for determining if this block should have a usages link or not.
- .default_template ⇒ Object
- .default_template_path ⇒ Object
-
.description(description = "") ⇒ String
Descriptions for portlets will be displayed when a user is adding one to page, or when editing the portlet.
-
.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.
- .form ⇒ Object
- .get_subclass(type) ⇒ Object
- .handler(handler_type) ⇒ Object
- .has_edit_link? ⇒ Boolean
- .render_inline(*args) ⇒ Object
- .set_default_template_path(s) ⇒ Object
-
.types ⇒ Array<Class>
Returns an alphabetical list of classes that descend from Cms::Portlet.
Instance Method Summary collapse
-
#connected_pages ⇒ Object
For polymorphic permissions A generic portlet shouldn’t be connected to pages.
-
#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.
- #instance_name ⇒ Object
-
#page_title(new_title) ⇒ Object
Used by portlets to set a custom title, typically in the render body.
-
#portlet_type_name ⇒ Object
For column in list.
-
#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 #portletportlet.instance_name_errors.
- #store_hash_in_flash(key, hash) ⇒ Object
-
#store_params_in_flash ⇒ Object
This will copy all the params from this request into the flash.
- #type_name ⇒ Object
- #url_for_failure ⇒ Object
- #url_for_success ⇒ Object
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
10 11 12 |
# File 'app/models/cms/portlet.rb', line 10 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
10 11 12 |
# File 'app/models/cms/portlet.rb', line 10 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
10 11 12 |
# File 'app/models/cms/portlet.rb', line 10 def controller @controller end |
Class Method Details
.blacklist ⇒ Array<String>
Returns a blacklist of all content types that shouldn’t be accessible. Includes both portlets and other CMS types.
102 103 104 |
# File 'app/models/cms/portlet.rb', line 102 def self.blacklist @blacklist ||= Rails.configuration.cms.content_types.blacklist.map {|underscore_name| underscore_name.to_s.camelize } end |
.blacklisted?(type_name) ⇒ Boolean
Determines if a content_type is blacklisted or not.
95 96 97 |
# File 'app/models/cms/portlet.rb', line 95 def self.blacklisted?(type_name) blacklist.include?(type_name.to_s.camelize) end |
.columns_for_index ⇒ Object
170 171 172 173 174 |
# File 'app/models/cms/portlet.rb', line 170 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.
177 178 179 |
# File 'app/models/cms/portlet.rb', line 177 def self.connectable? true end |
.default_template ⇒ Object
120 121 122 123 124 125 126 |
# File 'app/models/cms/portlet.rb', line 120 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
132 133 134 |
# File 'app/models/cms/portlet.rb', line 132 def self.default_template_path @default_template_path ||= "portlets/#{name.tableize.sub('_portlets', '')}/render" end |
.description(description = "") ⇒ String
Descriptions for portlets will be displayed when a user is adding one to page, or when editing the portlet. The goal is provide a more detailed overview of how a portlet should be used or what it does.
16 17 18 19 20 21 22 23 24 |
# File 'app/models/cms/portlet.rb', line 16 def self.description(description="") unless description.blank? @description = description end if @description.blank? return "(No description available)" end @description 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.
152 153 154 |
# File 'app/models/cms/portlet.rb', line 152 def self.enable_template_editor (enabled) render_inline enabled end |
.form ⇒ Object
116 117 118 |
# File 'app/models/cms/portlet.rb', line 116 def self.form "portlets/#{name.tableize.sub('_portlets', '')}/form" end |
.get_subclass(type) ⇒ Object
106 107 108 109 |
# File 'app/models/cms/portlet.rb', line 106 def self.get_subclass(type) raise "Unknown Portlet Type" unless types.map(&:name).include?(type) type.constantize end |
.handler(handler_type) ⇒ Object
145 146 147 |
# File 'app/models/cms/portlet.rb', line 145 def self.handler(handler_type) define_method(:handler) { handler_type } end |
.has_edit_link? ⇒ Boolean
72 73 74 |
# File 'app/models/cms/portlet.rb', line 72 def self.has_edit_link? false end |
.render_inline(*args) ⇒ Object
156 157 158 159 160 161 162 163 164 |
# File 'app/models/cms/portlet.rb', line 156 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
128 129 130 |
# File 'app/models/cms/portlet.rb', line 128 def self.set_default_template_path(s) @default_template_path = s end |
.types ⇒ Array<Class>
Returns an alphabetical list of classes that descend from Cms::Portlet.
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/models/cms/portlet.rb', line 79 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.constantize end end end.flatten.compact.uniq @types.sort! { |a,b| a.name.downcase <=> b.name.downcase } @types.select! { |type| !blacklist.include?(type.name)} @types end |
Instance Method Details
#connected_pages ⇒ Object
For polymorphic permissions A generic portlet shouldn’t be connected to pages.
183 184 185 |
# File 'app/models/cms/portlet.rb', line 183 def connected_pages [] end |
#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.
138 139 140 141 142 143 |
# File 'app/models/cms/portlet.rb', line 138 def = {} [:inline] = self.template if self.class.render_inline && !(self.template.nil? || self.template.blank?) [:type] = self.handler unless self.handler.blank? end |
#instance_name ⇒ Object
196 197 198 |
# File 'app/models/cms/portlet.rb', line 196 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.
192 193 194 |
# File 'app/models/cms/portlet.rb', line 192 def page_title(new_title) controller.current_page.title = new_title end |
#portlet_type_name ⇒ Object
For column in list
112 113 114 |
# File 'app/models/cms/portlet.rb', line 112 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
222 223 224 225 |
# File 'app/models/cms/portlet.rb', line 222 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
227 228 229 230 231 232 233 234 |
# File 'app/models/cms/portlet.rb', line 227 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.
216 217 218 |
# File 'app/models/cms/portlet.rb', line 216 def store_params_in_flash store_hash_in_flash instance_name, params end |
#type_name ⇒ Object
166 167 168 |
# File 'app/models/cms/portlet.rb', line 166 def type_name type.to_s.titleize end |
#url_for_failure ⇒ Object
206 207 208 209 210 |
# File 'app/models/cms/portlet.rb', line 206 def url_for_failure [params[:failure_url], self.failure_url, request.referer].detect do |e| !e.blank? end end |
#url_for_success ⇒ Object
200 201 202 203 204 |
# File 'app/models/cms/portlet.rb', line 200 def url_for_success [params[:success_url], self.success_url, request.referer].detect do |e| !e.blank? end end |