Module: DuckMap::ControllerHelpers
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/duck_map/controller_helpers.rb
Instance Method Summary collapse
- #find_first_model_object ⇒ Object
- #find_model_object ⇒ Object
-
#sitemap_meta_data ⇒ Object
Returns the current value of the instance variable #sitemap_meta_data.
- #sitemap_meta_data=(value) ⇒ Object
-
#sitemap_setup(options = {}) ⇒ Array
Determines all of the attributes defined for a controller, then, calls the handler method on the controller to generate and return an Array of Hashes representing all of the url nodes to be included in the sitemap for the current route being processed.
-
#sitemap_static_lastmod(my_controller_name = nil, my_action_name = nil) ⇒ DateTime
Returns the date / time value from config/locale/sitemap.yml associated with the current controller / action.
Instance Method Details
#find_first_model_object ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/duck_map/controller_helpers.rb', line 128 def find_first_model_object model_object = self.find_model_object #if model_object.kind_of?(Array) && #(model_object.first.kind_of?(ActiveRecord::Base) || model_object.first.kind_of?(Mongoid::Document)) #model_object = model_object.first #end if model_object.kind_of?(Array) && ::DuckMap::Model::Supported.is_supported?(model_object.first) model_object = model_object.first end return model_object end |
#find_model_object ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/duck_map/controller_helpers.rb', line 143 def find_model_object model_object = nil candidate = nil skip_vars = ["@_config", "@view_renderer", "@_routes", "@_assigns", "@_request", "@view_flow", "@output_buffer", "@virtual_path"] list = self.instance_variables.map.find_all {|x| !skip_vars.include?(x.to_s)} list.each do |obj_sym| obj = self.instance_variable_get(obj_sym) if obj if ::DuckMap::Model::Supported.is_supported?(obj) model_object = obj break elsif obj.kind_of?(Array) && ::DuckMap::Model::Supported.is_supported?(obj.first) (obj.first.kind_of?(ActiveRecord::Base) || obj.first.kind_of?(Mongoid::Document)) && candidate.blank? candidate = obj end end end if model_object.blank? && !candidate.blank? model_object = candidate end return model_object end |
#sitemap_meta_data ⇒ Object
Returns the current value of the instance variable #sitemap_meta_data.
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/duck_map/controller_helpers.rb', line 112 def unless defined?(@sitemap_meta_data) @sitemap_meta_data = {} self.sitemap_setup({action_name: action_name, controller_name: controller_name, route: nil, source: :meta_data}) end return @sitemap_meta_data end |
#sitemap_meta_data=(value) ⇒ Object
123 124 125 |
# File 'lib/duck_map/controller_helpers.rb', line 123 def (value) @sitemap_meta_data = value end |
#sitemap_setup(options = {}) ⇒ Array
Determines all of the attributes defined for a controller, then, calls the handler method on the controller to generate and return an Array of Hashes representing all of the url nodes to be included in the sitemap for the current route being processed.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/duck_map/controller_helpers.rb', line 93 def sitemap_setup( = {}) rows = [] DuckMap.logger.debug "sitemap_setup: action_name => #{[:action_name]} source => #{[:source]} model => #{[:model]}" attributes = self.sitemap_attributes([:action_name]) DuckMap.logger.debug "sitemap_setup: attributes => #{attributes}" if attributes.kind_of?(Hash) && attributes[:handler].kind_of?(Hash) && !attributes[:handler][:action_name].blank? config = {handler: attributes[:handler]}.merge() rows = self.send(attributes[:handler][:action_name], config) end return rows end |
#sitemap_static_lastmod(my_controller_name = nil, my_action_name = nil) ⇒ DateTime
Returns the date / time value from config/locale/sitemap.yml associated with the current controller / action. The static date/times are actual timestamps extracted from the date of the view on disk and from a .git repository if used. Be sure to run the generator or rake task: duck_map:sync to populate the locale file at: config/locale/sitemap.yml
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/duck_map/controller_helpers.rb', line 183 def sitemap_static_lastmod(my_controller_name = nil, my_action_name = nil) value = nil unless my_controller_name.blank? || my_action_name.blank? unless my_controller_name.blank? my_controller_name = my_controller_name.underscore my_controller_name = my_controller_name.gsub("/", ".") end begin value = I18n.t("#{my_controller_name.downcase}.#{my_action_name.downcase}", default: "", locale: :sitemap) rescue Exception => e DuckMap.logger.exception(e) end value = value.blank? ? nil : LastMod.to_date(value) end return value end |