duck_map 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/sitemap_base_controller.rb +13 -0
- data/app/controllers/sitemap_controller.rb +3 -0
- data/app/views/sitemap/default_template.xml.erb +10 -0
- data/config/routes.rb +5 -0
- data/lib/duck_map/array_helper.rb +50 -0
- data/lib/duck_map/attributes.rb +182 -0
- data/lib/duck_map/class_helpers.rb +55 -0
- data/lib/duck_map/config.rb +367 -0
- data/lib/duck_map/controller_helpers.rb +206 -0
- data/lib/duck_map/engine.rb +92 -0
- data/lib/duck_map/filter_stack.rb +200 -0
- data/lib/duck_map/handlers/base.rb +102 -0
- data/lib/duck_map/handlers/index.rb +140 -0
- data/lib/duck_map/handlers/show.rb +231 -0
- data/lib/duck_map/last_mod.rb +45 -0
- data/lib/duck_map/list.rb +82 -0
- data/lib/duck_map/logger.rb +193 -0
- data/lib/duck_map/mapper.rb +216 -0
- data/lib/duck_map/model.rb +27 -0
- data/lib/duck_map/route.rb +275 -0
- data/lib/duck_map/route_filter.rb +177 -0
- data/lib/duck_map/route_set.rb +209 -0
- data/lib/duck_map/sitemap_object.rb +457 -0
- data/lib/duck_map/static.rb +146 -0
- data/lib/duck_map/sync.rb +192 -0
- data/lib/duck_map/version.rb +3 -0
- data/lib/duck_map/view_helpers.rb +107 -0
- data/lib/duck_map.rb +3 -0
- data/lib/generators/duckmap/sitemaps/USAGE +23 -0
- data/lib/generators/duckmap/sitemaps/sitemaps_generator.rb +36 -0
- data/lib/generators/duckmap/static/USAGE +47 -0
- data/lib/generators/duckmap/static/static_generator.rb +51 -0
- data/lib/generators/duckmap/sync/USAGE +25 -0
- data/lib/generators/duckmap/sync/sync_generator.rb +29 -0
- metadata +96 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
class SitemapBaseController < ApplicationController
|
2
|
+
|
3
|
+
include DuckMap::SitemapControllerHelpers
|
4
|
+
helper DuckMap::Model
|
5
|
+
helper DuckMap::SitemapHelpers
|
6
|
+
|
7
|
+
rescue_from ActionView::MissingTemplate do |exception|
|
8
|
+
respond_to do |format|
|
9
|
+
format.xml { render :template => "sitemap/default_template"}
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
2
|
+
<%= sitemap_content do |row| %>
|
3
|
+
<url>
|
4
|
+
<loc><%= row[:loc] %></loc>
|
5
|
+
<lastmod><%= row[:lastmod] %></lastmod>
|
6
|
+
<changefreq><%= row[:changefreq] %></changefreq>
|
7
|
+
<priority><%= row[:priority] %></priority>
|
8
|
+
</url>
|
9
|
+
<% end %>
|
10
|
+
</urlset>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# DONE
|
2
|
+
module DuckMap
|
3
|
+
|
4
|
+
# This is a small helper used to ensure values in an Array of are a certain type.
|
5
|
+
module ArrayHelper
|
6
|
+
|
7
|
+
##################################################################################
|
8
|
+
# Ensures all values in an Array are of a certain type. This is meant to be used internally
|
9
|
+
# by DuckMap modules and classes.
|
10
|
+
#
|
11
|
+
# values = ["new_book", "edit_book", "create_book", "destroy_book"]
|
12
|
+
# values = obj.convert_to(values, :symbol)
|
13
|
+
# puts values #=> [:new_book, :edit_book, :create_book, :destroy_book]
|
14
|
+
#
|
15
|
+
# @param [Array] values The Array to inspect and convert.
|
16
|
+
# @param [Symbol] type Valid values are :string and :symbol.
|
17
|
+
# - :string converts all values to a String.
|
18
|
+
# - :symbol converts all values to a Symbol.
|
19
|
+
# @return [Array]
|
20
|
+
def convert_to(values, type)
|
21
|
+
buffer = []
|
22
|
+
|
23
|
+
if values.kind_of?(Array)
|
24
|
+
|
25
|
+
values.each do |value|
|
26
|
+
|
27
|
+
begin
|
28
|
+
|
29
|
+
if type == :string
|
30
|
+
buffer.push(value.to_s)
|
31
|
+
|
32
|
+
elsif type == :symbol
|
33
|
+
buffer.push(value.to_sym)
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
rescue Exception => e
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
else
|
43
|
+
buffer = values
|
44
|
+
end
|
45
|
+
|
46
|
+
return buffer
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
# DONE
|
2
|
+
require 'active_support/concern'
|
3
|
+
|
4
|
+
module DuckMap
|
5
|
+
|
6
|
+
##################################################################################
|
7
|
+
# This module has a single purpose. To declare a class-level attribute using the Rails class_attribute method.
|
8
|
+
# Also, we are using {ActiveSupport::Concern} and the included block. This module is included in
|
9
|
+
# {ActionController::Base}, so, every controller object will have the attribute.
|
10
|
+
#
|
11
|
+
# See {DuckMap::Attributes::ClassMethods#sitemap_attributes} for an explanation.
|
12
|
+
module InheritableClassAttributes
|
13
|
+
extend ActiveSupport::Concern
|
14
|
+
|
15
|
+
################################################################################
|
16
|
+
included do
|
17
|
+
class_eval do
|
18
|
+
|
19
|
+
class_attribute :sitemap_attributes_hash
|
20
|
+
class_attribute :sitemap_attributes_defined
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
##################################################################################
|
28
|
+
# Module used to add Sitemap attributes to an object.
|
29
|
+
module Attributes
|
30
|
+
extend ActiveSupport::Concern
|
31
|
+
|
32
|
+
##################################################################################
|
33
|
+
module ClassMethods
|
34
|
+
|
35
|
+
##################################################################################
|
36
|
+
## See {DuckMap::Attributes#is_sitemap_attributes_defined? is_sitemap_attributes_defined?}
|
37
|
+
# @return [TrueClass, FalseClass]
|
38
|
+
def is_sitemap_attributes_defined?
|
39
|
+
|
40
|
+
if self.sitemap_attributes_defined.nil?
|
41
|
+
self.sitemap_attributes_defined = false
|
42
|
+
end
|
43
|
+
|
44
|
+
return self.sitemap_attributes_defined
|
45
|
+
end
|
46
|
+
|
47
|
+
##################################################################################
|
48
|
+
# Returns the entire attributes Hash that has been defined for an object. The actual Hash is maintained via an accessor method named: sitemap_attributes_hash.
|
49
|
+
# {#sitemap_attributes sitemap_attributes} is actually a wrapper method for sitemap_attributes_hash accessor method.
|
50
|
+
#
|
51
|
+
# There are actually two definitions of sitemap_attributes_hash accessor method. The purpose of two definitions is to allow common code
|
52
|
+
# contained in {DuckMap::Attributes} to be included in the {DuckMap::Config} and all controller classes. The code works by referencing
|
53
|
+
# sitemap_attributes_hash accessor method, however, the actual variable reference is different depending on the object that is referring to it.
|
54
|
+
#
|
55
|
+
# When {DuckMap::Attributes} module is included in {DuckMap::Config}, then, self.sitemap_attributes_hash is actually referencing the class
|
56
|
+
# level method defined on {DuckMap::Config}.
|
57
|
+
#
|
58
|
+
# When {DuckMap::Attributes} module is included in all controller classes (it is by default), then, self.sitemap_attributes_hash
|
59
|
+
# is actually referencing the class level method defined by {DuckMap::InheritableClassAttributes} via class_attribute method.
|
60
|
+
# This means that the actual variable that will contain the Hash value never gets initialized. So, self.sitemap_attributes_hash
|
61
|
+
# will ALWAYS be uninitialized during the first access from within a controller and will ALWAYS copy values from {DuckMap::Config}.
|
62
|
+
#
|
63
|
+
# @return [Hash]
|
64
|
+
def sitemap_attributes
|
65
|
+
|
66
|
+
# check the current state of self.sitemap_attributes_hash. If it is a Hash, then, it is considered initialized.
|
67
|
+
# otherwise, a new Hash is populated and assigned to self.sitemap_attributes_hash and a reference is returned.
|
68
|
+
#
|
69
|
+
# when this module is included in DuckMap::Config self.sitemap_attributes_hash is actually referencing the class
|
70
|
+
# level method defined on DuckMap::Config.
|
71
|
+
#
|
72
|
+
# When this module is included in all controller classes self.sitemap_attributes_hash is actually referencing the class
|
73
|
+
# level method defined on InheritableClassAttributes which never gets initialized. So, self.sitemap_attributes_hash
|
74
|
+
# will NEVER be a Hash on the first access from within a controller and will ALWAYS copy values from {DuckMap::Config}
|
75
|
+
unless self.sitemap_attributes_hash.kind_of?(Hash)
|
76
|
+
|
77
|
+
# I actually have code to do a deep clone of a Hash, however, I can't release it right now.
|
78
|
+
# I will in a later release. For now, I will commit another sin.
|
79
|
+
self.sitemap_attributes_hash = {}
|
80
|
+
|
81
|
+
source = DuckMap::Config.sitemap_attributes_hash
|
82
|
+
|
83
|
+
source.each do |item|
|
84
|
+
self.sitemap_attributes_hash[item.first] = {}.merge(item.last)
|
85
|
+
self.sitemap_attributes_hash[item.first][:handler] = {}.merge(item.last[:handler])
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
return self.sitemap_attributes_hash
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
##################################################################################
|
96
|
+
# This is a simple boolean value with a specific purpose. It is used to indicate if the object
|
97
|
+
# being worked on actually defined attributes using {DuckMap::SitemapObject::ClassMethods#acts_as_sitemap acts_as_sitemap},
|
98
|
+
# {DuckMap::SitemapObject::ClassMethods#sitemap_handler sitemap_handler} or {DuckMap::SitemapObject::ClassMethods#sitemap_segments sitemap_segments}
|
99
|
+
#
|
100
|
+
# This has special meaning for ActiveRecord::Base objects. When {DuckMap::Handlers handler methods} evaluate a model, the model is asked
|
101
|
+
# if it defined it's own attributes.
|
102
|
+
#
|
103
|
+
# If the model did define it's own attributes, then, those attributes are used and override any attributes
|
104
|
+
# set via acts_as_sitemap, sitemap_handler, or sitemap_segments on the controller.
|
105
|
+
#
|
106
|
+
# If the model did not define it's own attributes, then, the attributes defined on the controller are used.
|
107
|
+
#
|
108
|
+
# Defaults from {DuckMap::Config} are used if neither controller nor model defined any attributes.
|
109
|
+
#
|
110
|
+
# @return [TrueClass, FalseClass]
|
111
|
+
def is_sitemap_attributes_defined?
|
112
|
+
return self.class.is_sitemap_attributes_defined?
|
113
|
+
end
|
114
|
+
|
115
|
+
##################################################################################
|
116
|
+
# Returns a Hash associated with a key. The Hash represents all of the attributes for
|
117
|
+
# a given action name on a controller.
|
118
|
+
#
|
119
|
+
# acts_as_sitemap :index, title: "my title" # index is the key
|
120
|
+
# sitemap_attributes("index") # index is the key
|
121
|
+
#
|
122
|
+
# @return [Hash]
|
123
|
+
def sitemap_attributes(key = :default)
|
124
|
+
key = key.blank? ? :default : key.to_sym
|
125
|
+
|
126
|
+
# if the key exists and has a Hash value, cool. Otherwise, go back to :default.
|
127
|
+
# self.class.sitemap_attributes should ALWAYS return a Hash, so, no need to test for that.
|
128
|
+
# however, key may or may not be a Hash. should test for that.
|
129
|
+
unless self.class.sitemap_attributes[key].kind_of?(Hash)
|
130
|
+
key = :default
|
131
|
+
end
|
132
|
+
|
133
|
+
# the :default Hash SHOULD ALWAYS be there. If not, this might cause an exception!!
|
134
|
+
return self.class.sitemap_attributes[key]
|
135
|
+
end
|
136
|
+
|
137
|
+
##################################################################################
|
138
|
+
# Wrapper method for {#sitemap_attributes sitemap_attributes} that returns a Hash stripped of key/value pairs
|
139
|
+
# where the value is another Hash.
|
140
|
+
#
|
141
|
+
# # normal
|
142
|
+
# values = sitemap_attributes("index")
|
143
|
+
# puts values #=> {:title=>:title, :keywords=>:keywords,
|
144
|
+
# # :description=>:description, :lastmod=>:updated_at,
|
145
|
+
# # :handler=>{:action_name=>:sitemap_index, :first_model=>true}}
|
146
|
+
#
|
147
|
+
# # stripped
|
148
|
+
# values = sitemap_stripped_attributes("index")
|
149
|
+
# puts values #=> {:title=>:title, :keywords=>:keywords,
|
150
|
+
# # :description=>:description, :lastmod=>:updated_at}
|
151
|
+
#
|
152
|
+
# @return [Hash]
|
153
|
+
def sitemap_stripped_attributes(key = :default)
|
154
|
+
values = {}
|
155
|
+
|
156
|
+
attributes = self.sitemap_attributes(key)
|
157
|
+
attributes.each do |pair|
|
158
|
+
|
159
|
+
# we are traversing a Hash in this loop.
|
160
|
+
# each item passed to the block is a two-element Array.
|
161
|
+
# the first element is a key and the second element is the value.
|
162
|
+
# given: {title: :my_title, handler: {action_name: :sitemap_index}}
|
163
|
+
# :title would be pair.first
|
164
|
+
# :my_title would be pair.last
|
165
|
+
# in the second case:
|
166
|
+
# :handler would be pair.first
|
167
|
+
# the Hash {action_name: :sitemap_index} would be pair.last
|
168
|
+
# we want to skip all the dark meat and keep the white meat.
|
169
|
+
# therefore, we are only interested in attributes that are on the first level.
|
170
|
+
# meaning, simple key/value pairs where the value is a value other than Hash.
|
171
|
+
unless pair.last.kind_of?(Hash)
|
172
|
+
values[pair.first] = pair.last
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
return values
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# DONE
|
2
|
+
module DuckMap
|
3
|
+
|
4
|
+
##################################################################################
|
5
|
+
# Simple helper class that tries to find controller and model classes based on a controller name.
|
6
|
+
class ClassHelpers
|
7
|
+
|
8
|
+
##################################################################################
|
9
|
+
# Attempts to automagically determine the controller class name based on the named route.
|
10
|
+
# returns [Class]
|
11
|
+
def self.get_controller_class(controller_name)
|
12
|
+
controller = nil
|
13
|
+
|
14
|
+
begin
|
15
|
+
|
16
|
+
controller = "#{controller_name.camelize.pluralize}Controller".constantize
|
17
|
+
|
18
|
+
rescue Exception => e
|
19
|
+
# once upon a time, I was logging these exceptions, however, it made the log files very noisy.
|
20
|
+
# I expect to have the exceptions occur. i plan on doing a little more on this area later.
|
21
|
+
controller = nil
|
22
|
+
|
23
|
+
begin
|
24
|
+
|
25
|
+
controller = "#{controller_name.camelize.singularize}Controller".constantize
|
26
|
+
|
27
|
+
rescue Exception => e
|
28
|
+
# once upon a time, I was logging these exceptions, however, it made the log files very noisy.
|
29
|
+
# I expect to have the exceptions occur. i plan on doing a little more on this area later.
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
return controller
|
34
|
+
end
|
35
|
+
|
36
|
+
##################################################################################
|
37
|
+
# Attempts to automagically determine the model class name based on the named route.
|
38
|
+
# returns [Class]
|
39
|
+
def self.get_model_class(controller_name)
|
40
|
+
value = nil
|
41
|
+
|
42
|
+
begin
|
43
|
+
|
44
|
+
value = controller_name.camelize.singularize.constantize
|
45
|
+
|
46
|
+
rescue Exception => e
|
47
|
+
# once upon a time, I was logging these exceptions, however, it made the log files very noisy.
|
48
|
+
# I expect to have the exceptions occur. i plan on doing a little more on this area later.
|
49
|
+
end
|
50
|
+
|
51
|
+
return value
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,367 @@
|
|
1
|
+
module DuckMap
|
2
|
+
|
3
|
+
##################################################################################
|
4
|
+
# Config holds default values and attributes for sitemap and meta tags.
|
5
|
+
# see {file:GUIDE.md#Default_values_and_attributes Guide}
|
6
|
+
class Config
|
7
|
+
include Attributes
|
8
|
+
include SitemapObject
|
9
|
+
|
10
|
+
##################################################################################
|
11
|
+
# Resets {.sitemap_attributes_hash} and {.attributes} to the defaults.
|
12
|
+
#
|
13
|
+
# @param [Symbol, String] name The name of the class variable to reset.
|
14
|
+
# - :all - resets both variables.
|
15
|
+
# - :attributes - resets the {.attributes}
|
16
|
+
# - :sitemap_attributes_hash - resets the {.sitemap_attributes_hash}
|
17
|
+
# @return [NilClass]
|
18
|
+
def self.reset(name = :all)
|
19
|
+
name = name.blank? ? :all : name.to_sym
|
20
|
+
|
21
|
+
if name.eql?(:all) || name.eql?(:sitemap_attributes_hash)
|
22
|
+
self.sitemap_attributes_hash = nil
|
23
|
+
end
|
24
|
+
|
25
|
+
if name.eql?(:all) || name.eql?(:attributes)
|
26
|
+
self.attributes = nil
|
27
|
+
end
|
28
|
+
|
29
|
+
if name.eql?(:all) || name.eql?(:sitemap_attributes_defined)
|
30
|
+
self.sitemap_attributes_defined = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
return nil
|
34
|
+
end
|
35
|
+
|
36
|
+
##################################################################################
|
37
|
+
# This method needs to exist since {DuckMap::Attributes} is included in this class.
|
38
|
+
#
|
39
|
+
# See {DuckMap::Attributes#is_sitemap_attributes_defined?} for details.
|
40
|
+
#
|
41
|
+
# @return [TrueClass, FalseClass]
|
42
|
+
def self.sitemap_attributes_defined
|
43
|
+
|
44
|
+
if !defined?(@@sitemap_attributes_defined) || @@sitemap_attributes_defined.nil?
|
45
|
+
@@sitemap_attributes_defined = false
|
46
|
+
end
|
47
|
+
|
48
|
+
return @@sitemap_attributes_defined
|
49
|
+
end
|
50
|
+
|
51
|
+
##################################################################################
|
52
|
+
# Setter method for sitemap_attributes_defined
|
53
|
+
# @return [TrueClass, FalseClass]
|
54
|
+
def self.sitemap_attributes_defined=(value)
|
55
|
+
@@sitemap_attributes_defined = value
|
56
|
+
end
|
57
|
+
|
58
|
+
##################################################################################
|
59
|
+
# Class-level accessor method. The value of the class variable @@sitemap_attributes_hash
|
60
|
+
# is checked prior to returning a reference to it. If the variable has not been defined or is nil,
|
61
|
+
# then, it is initialized with default values.
|
62
|
+
#
|
63
|
+
# See {DuckMap::Attributes::ClassMethods#sitemap_attributes} for an explanation.
|
64
|
+
#
|
65
|
+
# @return [Hash]
|
66
|
+
def self.sitemap_attributes_hash
|
67
|
+
|
68
|
+
if !defined?(@@sitemap_attributes_hash) || @@sitemap_attributes_hash.nil?
|
69
|
+
|
70
|
+
# many tests are sensitive to the values generated by this method.
|
71
|
+
# changes to this structure will make tests fails until you edit
|
72
|
+
# some of the .yml file(s) in the tests directory
|
73
|
+
values = {
|
74
|
+
title: :title,
|
75
|
+
keywords: :keywords,
|
76
|
+
description: :description,
|
77
|
+
lastmod: :updated_at,
|
78
|
+
changefreq: nil,
|
79
|
+
priority: nil,
|
80
|
+
canonical: nil,
|
81
|
+
canonical_host: nil,
|
82
|
+
canonical_port: nil,
|
83
|
+
#compression: nil, # don't need it here.
|
84
|
+
#sitemap_content: nil, # don't need it here.
|
85
|
+
static_host: nil,
|
86
|
+
static_port: nil,
|
87
|
+
#static_target: nil, # don't need it here.
|
88
|
+
url_format: nil,
|
89
|
+
url_limit: nil
|
90
|
+
}
|
91
|
+
|
92
|
+
@@sitemap_attributes_hash = {}
|
93
|
+
@@sitemap_attributes_hash[:default] = {}.merge(values)
|
94
|
+
@@sitemap_attributes_hash[:default][:handler] = {action_name: :sitemap_index, first_model: false}
|
95
|
+
|
96
|
+
@@sitemap_attributes_hash[:edit] = {}.merge(values)
|
97
|
+
@@sitemap_attributes_hash[:edit][:handler] = {action_name: :sitemap_edit, first_model: true}
|
98
|
+
|
99
|
+
@@sitemap_attributes_hash[:index] = {}.merge(values)
|
100
|
+
@@sitemap_attributes_hash[:index][:handler] = {action_name: :sitemap_index, first_model: true}
|
101
|
+
|
102
|
+
@@sitemap_attributes_hash[:new] = {}.merge(values)
|
103
|
+
@@sitemap_attributes_hash[:new][:handler] = {action_name: :sitemap_new, first_model: true}
|
104
|
+
|
105
|
+
@@sitemap_attributes_hash[:show] = {}.merge(values)
|
106
|
+
@@sitemap_attributes_hash[:show][:handler] = {action_name: :sitemap_show, first_model: true}
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
return @@sitemap_attributes_hash
|
111
|
+
end
|
112
|
+
|
113
|
+
###################################################################################
|
114
|
+
# Returns a copy of the entire sitemap_attributes_hash Hash.
|
115
|
+
# return [Hash]
|
116
|
+
def self.copy_sitemap_attributes_hash
|
117
|
+
values = {}
|
118
|
+
|
119
|
+
# I actually have code to do a deep clone of a Hash, however, I can't release it right now.
|
120
|
+
# I will in a later release. For now, I will commit another sin.
|
121
|
+
|
122
|
+
self.sitemap_attributes_hash.each do |item|
|
123
|
+
values[item.first] = {}.merge(item.last)
|
124
|
+
values[item.first][:handler] = {}.merge(item.last[:handler])
|
125
|
+
end
|
126
|
+
|
127
|
+
return values
|
128
|
+
end
|
129
|
+
|
130
|
+
###################################################################################
|
131
|
+
# Class-level accessor method. Sets the value of the class variable @@sitemap_attributes_hash.
|
132
|
+
# Setting the value to nil will cause it to be re-initialized on the next call to the get
|
133
|
+
# method: class variable {.sitemap_attributes_hash}
|
134
|
+
# @return [Hash]
|
135
|
+
def self.sitemap_attributes_hash=(value)
|
136
|
+
@@sitemap_attributes_hash = value
|
137
|
+
return @@sitemap_attributes_hash
|
138
|
+
end
|
139
|
+
|
140
|
+
###################################################################################
|
141
|
+
# Returns the entire attributes Hash.
|
142
|
+
# return [Hash]
|
143
|
+
def self.attributes
|
144
|
+
|
145
|
+
# set the default values.
|
146
|
+
if !defined?(@@attributes) || @@attributes.nil?
|
147
|
+
# set default values
|
148
|
+
@@attributes = {
|
149
|
+
title: "Untitled",
|
150
|
+
keywords: nil,
|
151
|
+
description: nil,
|
152
|
+
lastmod: Time.now,
|
153
|
+
changefreq: "monthly",
|
154
|
+
priority: "0.5",
|
155
|
+
canonical: nil,
|
156
|
+
canonical_host: nil,
|
157
|
+
canonical_port: nil,
|
158
|
+
compression: :compressed,
|
159
|
+
sitemap_content: :xml,
|
160
|
+
static_host: nil,
|
161
|
+
static_port: nil,
|
162
|
+
static_target: nil,
|
163
|
+
url_format: "html",
|
164
|
+
url_limit: 50000
|
165
|
+
}
|
166
|
+
end
|
167
|
+
|
168
|
+
return @@attributes
|
169
|
+
end
|
170
|
+
|
171
|
+
###################################################################################
|
172
|
+
# Sets the entire attributes Hash.
|
173
|
+
# return [Hash]
|
174
|
+
def self.attributes=(value)
|
175
|
+
@@attributes = value
|
176
|
+
end
|
177
|
+
|
178
|
+
###################################################################################
|
179
|
+
# Returns a copy of the entire attributes Hash.
|
180
|
+
# return [Hash]
|
181
|
+
def self.copy_attributes
|
182
|
+
return {}.merge(self.attributes)
|
183
|
+
end
|
184
|
+
|
185
|
+
###################################################################################
|
186
|
+
# Performs a get or set on all of the key/values contained in the attributes class variable.
|
187
|
+
# To get a value, simply call DuckMap::Config with the method name.
|
188
|
+
#
|
189
|
+
# DuckMap::Config.title # => Untitled
|
190
|
+
#
|
191
|
+
# To set a value, simply call DuckMap::Config with the method name and an assignment.
|
192
|
+
#
|
193
|
+
# DuckMap::Config.title # => Untitled
|
194
|
+
# DuckMap::Config.title = "My App"
|
195
|
+
# DuckMap::Config.title # => My App
|
196
|
+
#
|
197
|
+
# I choose to go this route since this ONLY applies to DuckMap::Config and to reduce the amount of accessor
|
198
|
+
# methods needed to get/set attributes.
|
199
|
+
#
|
200
|
+
# return [Object] Value stored via key.
|
201
|
+
def self.method_missing(meth, *args, &block)
|
202
|
+
value = nil
|
203
|
+
|
204
|
+
|
205
|
+
if meth.to_s =~ /=$/
|
206
|
+
key = meth.to_s
|
207
|
+
key = key.slice(0, key.length - 1).to_sym
|
208
|
+
self.attributes[key] = args.first
|
209
|
+
else
|
210
|
+
# all tests showed that meth is a Symbol
|
211
|
+
value = self.attributes[meth]
|
212
|
+
end
|
213
|
+
|
214
|
+
return value
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
218
|
+
|
219
|
+
##################################################################################
|
220
|
+
# A mixin the provide helper methods that gain access for configuration values from config/routes.rb.
|
221
|
+
module ConfigHelpers
|
222
|
+
extend ActiveSupport::Concern
|
223
|
+
|
224
|
+
##################################################################################
|
225
|
+
# Sets the logging level.
|
226
|
+
#
|
227
|
+
# # sets the logging level to :debug and full stack traces for exceptions.
|
228
|
+
# MyApp::Application.routes.draw do
|
229
|
+
# log_level :debug, full: true
|
230
|
+
# end
|
231
|
+
#
|
232
|
+
# @param [Symbol] value The logger level to use. Valid values are:
|
233
|
+
# - :debug
|
234
|
+
# - :info
|
235
|
+
# - :warn
|
236
|
+
# - :error
|
237
|
+
# - :fatal
|
238
|
+
# - :unknown
|
239
|
+
# @param [Hash] options Options Hash.
|
240
|
+
# @option options [Symbol] :full Including full: true will include full stack traces for exceptions.
|
241
|
+
# Otherwise, stack traces are stripped and attempt to only include application traces.
|
242
|
+
def log_level(value, options = {})
|
243
|
+
DuckMap::Logger.log_level = value
|
244
|
+
if options.has_key?(:full)
|
245
|
+
DuckMap.logger.full_exception = options[:full]
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
#################################################################################
|
250
|
+
# See {DuckMap::ConfigHelpers} Overview for details.
|
251
|
+
def title(value)
|
252
|
+
Config.title = value
|
253
|
+
end
|
254
|
+
|
255
|
+
#################################################################################
|
256
|
+
# See {DuckMap::ConfigHelpers} Overview for details.
|
257
|
+
def keywords(value)
|
258
|
+
Config.keywords = value
|
259
|
+
end
|
260
|
+
|
261
|
+
#################################################################################
|
262
|
+
# See {DuckMap::ConfigHelpers} Overview for details.
|
263
|
+
def description(value)
|
264
|
+
Config.description = value
|
265
|
+
end
|
266
|
+
|
267
|
+
#################################################################################
|
268
|
+
# See {DuckMap::ConfigHelpers} Overview for details.
|
269
|
+
def lastmod(value)
|
270
|
+
Config.lastmod = LastMod.to_date(value)
|
271
|
+
end
|
272
|
+
|
273
|
+
#################################################################################
|
274
|
+
# See {DuckMap::ConfigHelpers} Overview for details.
|
275
|
+
def changefreq(value)
|
276
|
+
Config.changefreq = value
|
277
|
+
end
|
278
|
+
|
279
|
+
#################################################################################
|
280
|
+
# See {DuckMap::ConfigHelpers} Overview for details.
|
281
|
+
def priority(value)
|
282
|
+
unless value.blank?
|
283
|
+
Config.priority = value.to_s
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
#################################################################################
|
288
|
+
# See {DuckMap::ConfigHelpers} Overview for details.
|
289
|
+
def url_format(value)
|
290
|
+
Config.url_format = value
|
291
|
+
end
|
292
|
+
|
293
|
+
#################################################################################
|
294
|
+
# See {DuckMap::ConfigHelpers} Overview for details.
|
295
|
+
def canonical(value)
|
296
|
+
Config.canonical = value
|
297
|
+
end
|
298
|
+
|
299
|
+
#################################################################################
|
300
|
+
# See {DuckMap::ConfigHelpers} Overview for details.
|
301
|
+
def canonical_host(value)
|
302
|
+
Config.canonical_host = value
|
303
|
+
end
|
304
|
+
|
305
|
+
#################################################################################
|
306
|
+
# See {DuckMap::ConfigHelpers} Overview for details.
|
307
|
+
def canonical_port(value)
|
308
|
+
Config.canonical_port = value
|
309
|
+
end
|
310
|
+
|
311
|
+
#################################################################################
|
312
|
+
# See {DuckMap::ConfigHelpers} Overview for details.
|
313
|
+
def compression(value)
|
314
|
+
Config.compression = value
|
315
|
+
end
|
316
|
+
|
317
|
+
#################################################################################
|
318
|
+
# See {DuckMap::ConfigHelpers} Overview for details.
|
319
|
+
def sitemap_content(value)
|
320
|
+
Config.sitemap_content = value
|
321
|
+
end
|
322
|
+
|
323
|
+
#################################################################################
|
324
|
+
# See {DuckMap::ConfigHelpers} Overview for details.
|
325
|
+
def static_host(value)
|
326
|
+
Config.static_host = value
|
327
|
+
end
|
328
|
+
|
329
|
+
#################################################################################
|
330
|
+
# See {DuckMap::ConfigHelpers} Overview for details.
|
331
|
+
def static_port(value)
|
332
|
+
Config.static_port = value
|
333
|
+
end
|
334
|
+
|
335
|
+
#################################################################################
|
336
|
+
# See {DuckMap::ConfigHelpers} Overview for details.
|
337
|
+
def static_target(value)
|
338
|
+
Config.static_target = value
|
339
|
+
end
|
340
|
+
|
341
|
+
#################################################################################
|
342
|
+
# See {DuckMap::ConfigHelpers} Overview for details.
|
343
|
+
def url_limit(value)
|
344
|
+
Config.url_limit = value
|
345
|
+
end
|
346
|
+
|
347
|
+
#################################################################################
|
348
|
+
# See {DuckMap::SitemapObject::ClassMethods#acts_as_sitemap}
|
349
|
+
def acts_as_sitemap(*args)
|
350
|
+
Config.acts_as_sitemap(*args)
|
351
|
+
end
|
352
|
+
|
353
|
+
#################################################################################
|
354
|
+
# See {DuckMap::SitemapObject::ClassMethods#sitemap_handler}
|
355
|
+
def sitemap_handler(*args)
|
356
|
+
Config.sitemap_handler(*args)
|
357
|
+
end
|
358
|
+
|
359
|
+
#################################################################################
|
360
|
+
# See {DuckMap::SitemapObject::ClassMethods#sitemap_segments}
|
361
|
+
def sitemap_segments(*args)
|
362
|
+
Config.sitemap_segments(*args)
|
363
|
+
end
|
364
|
+
|
365
|
+
end
|
366
|
+
|
367
|
+
end
|