duck_map 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/duck_map/handlers/show.rb +7 -112
- data/lib/duck_map/list.rb +4 -5
- data/lib/duck_map/mapper.rb +4 -0
- data/lib/duck_map/route_set.rb +2 -0
- data/lib/duck_map/sitemap_object.rb +13 -0
- data/lib/duck_map/version.rb +1 -1
- data/lib/generators/duckmap/sitemaps/sitemaps_generator.rb +3 -3
- metadata +2 -2
| @@ -10,7 +10,6 @@ module DuckMap | |
| 10 10 | 
             
                  ##################################################################################
         | 
| 11 11 | 
             
                  def sitemap_show(options = {})
         | 
| 12 12 | 
             
                    rows = []
         | 
| 13 | 
            -
            puts YAML.dump(options)
         | 
| 14 13 |  | 
| 15 14 | 
             
                    # always start off with default values from config, then, simply overwrite them as we progress.
         | 
| 16 15 | 
             
                    values = sitemap_defaults(options)
         | 
| @@ -24,32 +23,21 @@ puts YAML.dump(options) | |
| 24 23 |  | 
| 25 24 | 
             
                    # first, capture the values from the controller.
         | 
| 26 25 | 
             
                    attributes = self.sitemap_stripped_attributes(options[:action_name])
         | 
| 27 | 
            -
            puts "............................ attributes"
         | 
| 28 | 
            -
            puts YAML.dump(attributes)
         | 
| 29 | 
            -
             | 
| 30 26 | 
             
                    values = values.merge(self.sitemap_capture_attributes(attributes))
         | 
| 31 | 
            -
            puts "---------------------------------==== values"
         | 
| 32 | 
            -
            puts YAML.dump(values)
         | 
| 33 27 |  | 
| 34 28 | 
             
                    if options[:source] == :meta_data
         | 
| 35 | 
            -
             | 
| 29 | 
            +
             | 
| 36 30 | 
             
                      # capture values from the first available model unless disabled.
         | 
| 37 31 | 
             
                      model_object = sitemap_first_model(options[:handler])
         | 
| 38 | 
            -
             | 
| 32 | 
            +
             | 
| 39 33 | 
             
                      unless model_object.blank?
         | 
| 40 34 | 
             
                        model_attributes = attributes
         | 
| 41 35 | 
             
                        if model_object.is_sitemap_attributes_defined?
         | 
| 42 36 | 
             
                          model_attributes = model_object.sitemap_stripped_attributes(options[:action_name])
         | 
| 43 37 | 
             
                        end
         | 
| 44 | 
            -
            puts "**********************************************==== model_attributes"
         | 
| 45 | 
            -
            puts YAML.dump(model_attributes)
         | 
| 46 | 
            -
             | 
| 47 | 
            -
            puts "wtf wtf wtf wtf wtf wtf wtf wtf wtf wtf wtf wtf wtf wtf wtf wtf wtf wtf wtf wtf "
         | 
| 48 | 
            -
            puts YAML.dump(model_object.sitemap_capture_attributes(model_attributes))
         | 
| 49 38 |  | 
| 50 39 | 
             
                        values = values.merge(model_object.sitemap_capture_attributes(model_attributes))
         | 
| 51 | 
            -
             | 
| 52 | 
            -
            puts YAML.dump(values)
         | 
| 40 | 
            +
             | 
| 53 41 | 
             
                      end
         | 
| 54 42 |  | 
| 55 43 | 
             
                      if values[:canonical].blank?
         | 
| @@ -60,8 +48,6 @@ puts YAML.dump(values) | |
| 60 48 | 
             
                      else
         | 
| 61 49 | 
             
                        values[:loc] = values[:canonical]
         | 
| 62 50 | 
             
                      end
         | 
| 63 | 
            -
            puts "............................ values"
         | 
| 64 | 
            -
            puts YAML.dump(values)
         | 
| 65 51 |  | 
| 66 52 | 
             
                      rows.push(values)
         | 
| 67 53 |  | 
| @@ -102,8 +88,11 @@ puts YAML.dump(values) | |
| 102 88 | 
             
                          # defined on the model.  The model attributes win!
         | 
| 103 89 | 
             
                          # same thing for segments below.
         | 
| 104 90 | 
             
                          model_attributes = attributes
         | 
| 91 | 
            +
                          segment_mappings = self.sitemap_attributes(options[:action_name])[:segments]
         | 
| 92 | 
            +
             | 
| 105 93 | 
             
                          if data_row.is_sitemap_attributes_defined?
         | 
| 106 94 | 
             
                            model_attributes = data_row.sitemap_stripped_attributes(options[:action_name])
         | 
| 95 | 
            +
                            segment_mappings = data_row.sitemap_attributes(options[:action_name])[:segments]
         | 
| 107 96 | 
             
                          end
         | 
| 108 97 |  | 
| 109 98 | 
             
                          row_values = values.merge(data_row.sitemap_capture_attributes(model_attributes))
         | 
| @@ -112,7 +101,7 @@ puts YAML.dump(values) | |
| 112 101 |  | 
| 113 102 | 
             
                          if row_values[:canonical].blank?
         | 
| 114 103 |  | 
| 115 | 
            -
                            segments = data_row.sitemap_capture_segments( | 
| 104 | 
            +
                            segments = data_row.sitemap_capture_segments(segment_mappings, options[:route].segments)
         | 
| 116 105 | 
             
                            row_values[:canonical] = self.send("#{options[:route].name}_url", url_options.merge(segments))
         | 
| 117 106 | 
             
                            row_values[:loc] = row_values[:canonical]
         | 
| 118 107 |  | 
| @@ -131,100 +120,6 @@ puts YAML.dump(values) | |
| 131 120 | 
             
                    return sitemap_url_limit(rows, options[:handler])
         | 
| 132 121 | 
             
                  end
         | 
| 133 122 |  | 
| 134 | 
            -
                  ###################################################################################
         | 
| 135 | 
            -
                  #def sitemap_show(options = {})
         | 
| 136 | 
            -
                    #rows = []
         | 
| 137 | 
            -
             | 
| 138 | 
            -
                    ## always start off with default values from config, then, simply overwrite them as we progress.
         | 
| 139 | 
            -
                    #values = sitemap_defaults
         | 
| 140 | 
            -
             | 
| 141 | 
            -
                    #if options[:source] == :meta_data
         | 
| 142 | 
            -
             | 
| 143 | 
            -
                      ## if the source is meta_data, that means this method call is the result of a user
         | 
| 144 | 
            -
                      ## requesting an index page.  Therefore, the controller action_name variable should be set.
         | 
| 145 | 
            -
                      ## so, go ahead and use it.
         | 
| 146 | 
            -
             | 
| 147 | 
            -
                      #lastmod = self.sitemap_static_lastmod(controller_name, action_name)
         | 
| 148 | 
            -
                      #unless lastmod.blank?
         | 
| 149 | 
            -
                        #values[:lastmod] = lastmod
         | 
| 150 | 
            -
                      #end
         | 
| 151 | 
            -
             | 
| 152 | 
            -
                      ## first, capture the values from the controller.
         | 
| 153 | 
            -
                      #attributes = self.sitemap_stripped_attributes(action_name)
         | 
| 154 | 
            -
                      #values = values.merge(self.sitemap_capture_attributes(attributes))
         | 
| 155 | 
            -
             | 
| 156 | 
            -
                      #if options[:handler][:first_model]
         | 
| 157 | 
            -
                        #model_object = sitemap_first_model(options[:handler])
         | 
| 158 | 
            -
                        #unless model_object.blank?
         | 
| 159 | 
            -
                          #values = values.merge(model_object.sitemap_capture_attributes(attributes))
         | 
| 160 | 
            -
                        #end
         | 
| 161 | 
            -
                      #end
         | 
| 162 | 
            -
             | 
| 163 | 
            -
                      #route = Rails.application.routes.find_route_via_path(request.path)
         | 
| 164 | 
            -
                      #values[:loc] = self.send("#{route.name}_url", params.merge({format: values[:url_format]}))
         | 
| 165 | 
            -
                      #values[:canonical] = values[:loc]
         | 
| 166 | 
            -
             | 
| 167 | 
            -
                      #rows.push(values)
         | 
| 168 | 
            -
             | 
| 169 | 
            -
                      #self.sitemap_meta_data = values
         | 
| 170 | 
            -
             | 
| 171 | 
            -
                    #elsif options[:source] == :sitemap
         | 
| 172 | 
            -
             | 
| 173 | 
            -
                      #begin
         | 
| 174 | 
            -
             | 
| 175 | 
            -
                        #route = options[:route]
         | 
| 176 | 
            -
             | 
| 177 | 
            -
                        #lastmod = self.sitemap_static_lastmod(route.controller_name, route.action_name)
         | 
| 178 | 
            -
                        #unless lastmod.blank?
         | 
| 179 | 
            -
                          #values[:lastmod] = lastmod
         | 
| 180 | 
            -
                        #end
         | 
| 181 | 
            -
             | 
| 182 | 
            -
                        #attributes = self.sitemap_stripped_attributes(options[:action_name])
         | 
| 183 | 
            -
                        #values = values.merge(self.sitemap_capture_attributes(attributes))
         | 
| 184 | 
            -
             | 
| 185 | 
            -
                        #data_rows = []
         | 
| 186 | 
            -
             | 
| 187 | 
            -
                        #if !options[:handler][:block].blank?
         | 
| 188 | 
            -
             | 
| 189 | 
            -
                          #data_rows = options[:handler][:block].call(options)
         | 
| 190 | 
            -
             | 
| 191 | 
            -
                        #elsif !options[:handler][:model].blank?
         | 
| 192 | 
            -
             | 
| 193 | 
            -
                          #data_rows = options[:handler][:model].send(:all)
         | 
| 194 | 
            -
             | 
| 195 | 
            -
                        #elsif !options[:model].blank?
         | 
| 196 | 
            -
             | 
| 197 | 
            -
                          #data_rows = options[:model].send(:all)
         | 
| 198 | 
            -
             | 
| 199 | 
            -
                        #end
         | 
| 200 | 
            -
             | 
| 201 | 
            -
                        #unless data_rows.kind_of?(Array)
         | 
| 202 | 
            -
                          #if data_rows.kind_of?(ActiveRecord::Base)
         | 
| 203 | 
            -
                            #data_rows = [data_rows]
         | 
| 204 | 
            -
                          #end
         | 
| 205 | 
            -
                        #end
         | 
| 206 | 
            -
             | 
| 207 | 
            -
                        #data_rows.each do |data_row|
         | 
| 208 | 
            -
             | 
| 209 | 
            -
                          #row_values = values.merge(data_row.sitemap_capture_attributes(attributes))
         | 
| 210 | 
            -
             | 
| 211 | 
            -
                          #segments = data_row.sitemap_capture_segments(attributes, route.segments)
         | 
| 212 | 
            -
             | 
| 213 | 
            -
                          #row_values[:canonical] = self.send("#{route.name}_url", {format: row_values[:url_format]}.merge(segments))
         | 
| 214 | 
            -
                          #row_values[:loc] = row_values[:canonical]
         | 
| 215 | 
            -
                          #rows.push(row_values)
         | 
| 216 | 
            -
             | 
| 217 | 
            -
                        #end
         | 
| 218 | 
            -
             | 
| 219 | 
            -
                      #rescue Exception => e
         | 
| 220 | 
            -
                        #DuckMap.logger.exception(e)
         | 
| 221 | 
            -
                      #end
         | 
| 222 | 
            -
             | 
| 223 | 
            -
                    #end
         | 
| 224 | 
            -
             | 
| 225 | 
            -
                    #return sitemap_url_limit(rows, values)
         | 
| 226 | 
            -
                  #end
         | 
| 227 | 
            -
             | 
| 228 123 | 
             
                end
         | 
| 229 124 |  | 
| 230 125 | 
             
              end
         | 
    
        data/lib/duck_map/list.rb
    CHANGED
    
    | @@ -9,9 +9,9 @@ module DuckMap | |
| 9 9 |  | 
| 10 10 | 
             
                  key = options[:key].blank? ? :all : options[:key].to_s.downcase.to_sym
         | 
| 11 11 |  | 
| 12 | 
            -
                   | 
| 12 | 
            +
                  verbose = options.has_key?(:verbose) ? true : false
         | 
| 13 13 |  | 
| 14 | 
            -
                   | 
| 14 | 
            +
                  verbose = key.eql?(:all) ? verbose : true
         | 
| 15 15 |  | 
| 16 16 | 
             
                  puts "Searching for route: #{key}"
         | 
| 17 17 |  | 
| @@ -46,12 +46,11 @@ module DuckMap | |
| 46 46 |  | 
| 47 47 | 
             
                      puts %(#{"".ljust(40)} #{route.path.spec})
         | 
| 48 48 |  | 
| 49 | 
            -
                      if  | 
| 49 | 
            +
                      if verbose
         | 
| 50 50 |  | 
| 51 51 | 
             
                        sitemap_routes = Rails.application.routes.sitemap_routes(route)
         | 
| 52 52 | 
             
                        if sitemap_routes.length > 0
         | 
| 53 | 
            -
             | 
| 54 | 
            -
                          #puts %(#{"".ljust(5)}                                    path)
         | 
| 53 | 
            +
             | 
| 55 54 | 
             
                          puts %(#{"".ljust(5)} --------------------------------------------------------------)
         | 
| 56 55 |  | 
| 57 56 | 
             
                          sitemap_routes.each do |sitemap_route|
         | 
    
        data/lib/duck_map/mapper.rb
    CHANGED
    
    | @@ -35,6 +35,10 @@ module DuckMap | |
| 35 35 | 
             
                  @set.routes.last.sitemap_route_name = last_route_name
         | 
| 36 36 | 
             
                  @set.routes.last.sitemap_raw_route_name = sitemap_raw_route_name
         | 
| 37 37 |  | 
| 38 | 
            +
                  # this is how I am faking to always point to the SitemapController
         | 
| 39 | 
            +
                  # regardless of namespace
         | 
| 40 | 
            +
                  @set.routes.last.defaults[:controller] = "sitemap"
         | 
| 41 | 
            +
             | 
| 38 42 | 
             
                  # determine if we added a duplicate route.
         | 
| 39 43 | 
             
                  # The gem defines a default sitemap in config/routes.rb (inside the gem, not the app).
         | 
| 40 44 | 
             
                  # So, it is very likely that most apps will be creating duplicates since most of the code is geared towards
         | 
    
        data/lib/duck_map/route_set.rb
    CHANGED
    
    
| @@ -178,6 +178,19 @@ module DuckMap | |
| 178 178 | 
             
                      keys.push(key)
         | 
| 179 179 | 
             
                    end
         | 
| 180 180 |  | 
| 181 | 
            +
                    if values[:lastmod].kind_of?(String)
         | 
| 182 | 
            +
                      begin
         | 
| 183 | 
            +
             | 
| 184 | 
            +
                        buffer = LastMod.to_date(values[:lastmod])
         | 
| 185 | 
            +
                        if buffer.kind_of?(Time)
         | 
| 186 | 
            +
                          values[:lastmod] = buffer
         | 
| 187 | 
            +
                        end
         | 
| 188 | 
            +
             | 
| 189 | 
            +
                      rescue Exception => e
         | 
| 190 | 
            +
                        # TODO logging
         | 
| 191 | 
            +
                      end
         | 
| 192 | 
            +
                    end
         | 
| 193 | 
            +
             | 
| 181 194 | 
             
                    # process all of the keys in the list.
         | 
| 182 195 | 
             
                    keys.each do |key|
         | 
| 183 196 |  | 
    
        data/lib/duck_map/version.rb
    CHANGED
    
    
| @@ -12,7 +12,7 @@ module Duckmap | |
| 12 12 | 
             
                            required: false,
         | 
| 13 13 | 
             
                            optional: true
         | 
| 14 14 |  | 
| 15 | 
            -
                  class_option : | 
| 15 | 
            +
                  class_option :verbose, desc: "Include the routes contained in a sitemap"
         | 
| 16 16 |  | 
| 17 17 | 
             
                  def self.source_root
         | 
| 18 18 | 
             
                    File.join(File.dirname(__FILE__), "templates")
         | 
| @@ -22,8 +22,8 @@ module Duckmap | |
| 22 22 |  | 
| 23 23 | 
             
                    config = {key: key}
         | 
| 24 24 |  | 
| 25 | 
            -
                    unless options[: | 
| 26 | 
            -
                      config[: | 
| 25 | 
            +
                    unless options[:verbose].blank?
         | 
| 26 | 
            +
                      config[:verbose] = options[:verbose]
         | 
| 27 27 | 
             
                    end
         | 
| 28 28 |  | 
| 29 29 | 
             
                    DuckMap::List.new.build(config)
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: duck_map
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.8. | 
| 4 | 
            +
              version: 0.8.1
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2013-02- | 
| 12 | 
            +
            date: 2013-02-20 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: highline
         |