Module: DuckMap::SitemapControllerHelpers

Included in:
ActionViewTestObject
Defined in:
lib/duck_map/controller_helpers.rb

Overview

This module is empty on purpose. Sitemap::Mapper will create a sitemap method on this module when a sitemap is actually created via config/routes.rb. This module is included in the SitemapBaseController and therefore will have all of the methods defined via config/routes.rb. Originally, methods were defined directly on SitemapBaseController, however, it was creating some wierd problems during development. Meaning, if you tried to edit and refresh (Rails standard) the Rails stack would blow up. Adding the methods to a module and including the module seemed to fix the problem.

Instance Method Summary collapse

Instance Method Details

#sitemap_build(request_path = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/duck_map/controller_helpers.rb', line 17

def sitemap_build(request_path = nil)

  self.sitemap_model = []

  begin

    request_path = request_path.blank? ? request.path : request_path

    sitemap_route = Rails.application.routes.find_sitemap_route(request_path)
    unless sitemap_route.blank?
      Rails.application.routes.sitemap_routes(sitemap_route).each do |route|

      begin

        DuckMap.logger.info "processing route:  name: #{route.name}  controller: #{route.controller_name}  action: #{route.action_name}"

        clazz = ClassHelpers.get_controller_class(route.controller_name)

        if clazz.blank?
          DuckMap.logger.debug "sorry, could not determine controller class...: route name: #{route.name} controller: #{route.controller_name}  action: #{route.action_name}"
        else

          controller_object = clazz.new
          controller_object.request = request
          controller_object.response = ActionDispatch::Response.new

          begin

            options = { action_name: route.action_name,
                        controller_name: route.controller_name,
                        model: ClassHelpers.get_model_class(route.controller_name),
                        route: route,
                        source: :sitemap}

            rows = controller_object.sitemap_setup(options)
            if rows.kind_of?(Array) && rows.length > 0
              self.sitemap_model.concat(rows)
            end

          rescue Exception => e
            DuckMap.logger.exception(e)
          end

        end

      rescue Exception => e
        DuckMap.logger.exception(e)
      end

      end
    end

    self.sitemap_model.each do |item|
      unless item[:lastmod].kind_of?(String)
        item[:lastmod] = item[:lastmod].to_s(:sitemap)
      end
    end

  rescue Exception => e
    DuckMap.logger.exception(e)
  end

  return nil
end