xml-sitemap 1.0.2 → 1.0.3
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/xml-sitemap.rb +42 -0
 - metadata +4 -4
 
    
        data/lib/xml-sitemap.rb
    CHANGED
    
    | 
         @@ -18,10 +18,13 @@ module XmlSitemap 
     | 
|
| 
       18 
18 
     | 
    
         
             
              class Map
         
     | 
| 
       19 
19 
     | 
    
         
             
                attr_reader :domain, :items
         
     | 
| 
       20 
20 
     | 
    
         
             
                attr_reader :buffer
         
     | 
| 
      
 21 
     | 
    
         
            +
                attr_reader :created_at
         
     | 
| 
      
 22 
     | 
    
         
            +
                attr_accessor :index_path
         
     | 
| 
       21 
23 
     | 
    
         | 
| 
       22 
24 
     | 
    
         
             
                # Creates new Map class for specified domain
         
     | 
| 
       23 
25 
     | 
    
         
             
                def initialize(domain)
         
     | 
| 
       24 
26 
     | 
    
         
             
                  @domain = domain
         
     | 
| 
      
 27 
     | 
    
         
            +
                  @created_at = Time.now
         
     | 
| 
       25 
28 
     | 
    
         
             
                  @items = []
         
     | 
| 
       26 
29 
     | 
    
         
             
                  yield self if block_given?
         
     | 
| 
       27 
30 
     | 
    
         
             
                end
         
     | 
| 
         @@ -37,6 +40,11 @@ module XmlSitemap 
     | 
|
| 
       37 
40 
     | 
    
         
             
                  @items << XmlSitemap::Item.new(opts)
         
     | 
| 
       38 
41 
     | 
    
         
             
                end
         
     | 
| 
       39 
42 
     | 
    
         | 
| 
      
 43 
     | 
    
         
            +
                # Get map items count
         
     | 
| 
      
 44 
     | 
    
         
            +
                def size
         
     | 
| 
      
 45 
     | 
    
         
            +
                  @items.size
         
     | 
| 
      
 46 
     | 
    
         
            +
                end
         
     | 
| 
      
 47 
     | 
    
         
            +
                
         
     | 
| 
       40 
48 
     | 
    
         
             
                # Render XML
         
     | 
| 
       41 
49 
     | 
    
         
             
                def render
         
     | 
| 
       42 
50 
     | 
    
         
             
                  return '' if @items.size == 0
         
     | 
| 
         @@ -55,4 +63,38 @@ module XmlSitemap 
     | 
|
| 
       55 
63 
     | 
    
         
             
                  return output.join("\n")
         
     | 
| 
       56 
64 
     | 
    
         
             
                end
         
     | 
| 
       57 
65 
     | 
    
         
             
              end
         
     | 
| 
      
 66 
     | 
    
         
            +
              
         
     | 
| 
      
 67 
     | 
    
         
            +
              class Index
         
     | 
| 
      
 68 
     | 
    
         
            +
                attr_reader :domain, :maps
         
     | 
| 
      
 69 
     | 
    
         
            +
                
         
     | 
| 
      
 70 
     | 
    
         
            +
                def initialize(domain)
         
     | 
| 
      
 71 
     | 
    
         
            +
                  @domain = domain
         
     | 
| 
      
 72 
     | 
    
         
            +
                  @maps = []
         
     | 
| 
      
 73 
     | 
    
         
            +
                end
         
     | 
| 
      
 74 
     | 
    
         
            +
                
         
     | 
| 
      
 75 
     | 
    
         
            +
                # Add XmlSitemap::Map item to sitemap index
         
     | 
| 
      
 76 
     | 
    
         
            +
                def add(map)
         
     | 
| 
      
 77 
     | 
    
         
            +
                  raise 'XmlSitemap::Map object requred!' unless map.kind_of?(Map)
         
     | 
| 
      
 78 
     | 
    
         
            +
                  @maps << {:loc => "http://#{@domain}/#{map.index_path}", :lastmod => map.created_at.for_sitemap}
         
     | 
| 
      
 79 
     | 
    
         
            +
                end
         
     | 
| 
      
 80 
     | 
    
         
            +
                
         
     | 
| 
      
 81 
     | 
    
         
            +
                # Generate sitemap XML index
         
     | 
| 
      
 82 
     | 
    
         
            +
                def render
         
     | 
| 
      
 83 
     | 
    
         
            +
                  output = [] ; map_id = 1
         
     | 
| 
      
 84 
     | 
    
         
            +
                  output << '<?xml version="1.0" encoding="UTF-8"?>'
         
     | 
| 
      
 85 
     | 
    
         
            +
                  output << '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'
         
     | 
| 
      
 86 
     | 
    
         
            +
                  @maps.each do |m|
         
     | 
| 
      
 87 
     | 
    
         
            +
                    output << '<sitemap>'
         
     | 
| 
      
 88 
     | 
    
         
            +
                    output << "<loc>#{m[:loc]}</loc>"
         
     | 
| 
      
 89 
     | 
    
         
            +
                    output << "<lastmod>#{m[:lastmod]}</lastmod>"
         
     | 
| 
      
 90 
     | 
    
         
            +
                    output << '</sitemap>'
         
     | 
| 
      
 91 
     | 
    
         
            +
                  end
         
     | 
| 
      
 92 
     | 
    
         
            +
                  output << '</sitemapindex>'
         
     | 
| 
      
 93 
     | 
    
         
            +
                  return output.join("\n")
         
     | 
| 
      
 94 
     | 
    
         
            +
                end
         
     | 
| 
      
 95 
     | 
    
         
            +
              end
         
     | 
| 
      
 96 
     | 
    
         
            +
            end
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
            class Time
         
     | 
| 
      
 99 
     | 
    
         
            +
              def for_sitemap ; self.utc.strftime("%Y-%m-%dT%H:%M:%S-0000") ; end
         
     | 
| 
       58 
100 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,13 +1,13 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification 
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: xml-sitemap
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
     | 
    
         
            -
              hash:  
     | 
| 
      
 4 
     | 
    
         
            +
              hash: 17
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       6 
6 
     | 
    
         
             
              segments: 
         
     | 
| 
       7 
7 
     | 
    
         
             
              - 1
         
     | 
| 
       8 
8 
     | 
    
         
             
              - 0
         
     | 
| 
       9 
     | 
    
         
            -
              -  
     | 
| 
       10 
     | 
    
         
            -
              version: 1.0. 
     | 
| 
      
 9 
     | 
    
         
            +
              - 3
         
     | 
| 
      
 10 
     | 
    
         
            +
              version: 1.0.3
         
     | 
| 
       11 
11 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       12 
12 
     | 
    
         
             
            authors: 
         
     | 
| 
       13 
13 
     | 
    
         
             
            - Dan Sosedoff
         
     | 
| 
         @@ -31,7 +31,7 @@ files: 
     | 
|
| 
       31 
31 
     | 
    
         
             
            - README
         
     | 
| 
       32 
32 
     | 
    
         
             
            - lib/xml-sitemap.rb
         
     | 
| 
       33 
33 
     | 
    
         
             
            has_rdoc: true
         
     | 
| 
       34 
     | 
    
         
            -
            homepage: http:// 
     | 
| 
      
 34 
     | 
    
         
            +
            homepage: http://github.com/sosedoff/xml-sitemap
         
     | 
| 
       35 
35 
     | 
    
         
             
            licenses: []
         
     | 
| 
       36 
36 
     | 
    
         | 
| 
       37 
37 
     | 
    
         
             
            post_install_message: 
         
     |