sitemap_simple 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: caec881cb7ab8091f2439a5e5241b7f99039eff8
4
+ data.tar.gz: 3cf6dbd94c6544ffebee1fc4a89391fd82fd4b6f
5
+ SHA512:
6
+ metadata.gz: a1a0ca63d1493b7c374956d3ca60f4b3a55274078e7edd4c99e56fe1d335093512f2a848d32c86fb36443d58cb42a7b03740c6357d06255378486dffaa7d215b
7
+ data.tar.gz: 9d49f6336a9a9b63214c2faf121a59dec3042e54f9d809f1074d10312fc505afd24ad0f66e3ae8ed33de25300e250185d1b7fc3ed067462e2d9e7d7776b36316
@@ -0,0 +1,47 @@
1
+ class Sitemap
2
+ attr_reader :entries, :collection_scope
3
+
4
+ def initialize(entries = [], **options, &block)
5
+ @entries = entries
6
+ @collection_scope = options[:collection_scope] || :all
7
+ yield self if block_given?
8
+ end
9
+
10
+ def entry(location, **options)
11
+ @entries << Entry.new(location, **options)
12
+ end
13
+
14
+ def collection(resource, record_route, collection_route = nil)
15
+ records = resource.send(collection_scope).inject [] do |m, record|
16
+ m << Entry.new(record_route[record],
17
+ lastmod: record.respond_to?(:updated_at) ? record.updated_at : nil
18
+ )
19
+ end
20
+ if collection_route
21
+ @entries << collection_entry(collection_route, records)
22
+ end
23
+ @entries += records
24
+ end
25
+
26
+ def each_entry(&block)
27
+ @entries.each &block
28
+ end
29
+
30
+ private
31
+
32
+ def collection_entry(location, records, options = {})
33
+ options.merge! lastmod: records.max_by(&:lastmod).lastmod if records.any?
34
+ Entry.new(location, options)
35
+ end
36
+
37
+ class Entry
38
+ attr_reader :location, :lastmod, :changefreq, :priority
39
+
40
+ def initialize(location, lastmod: nil, changefreq: nil, priority: nil)
41
+ @location = location
42
+ @lastmod = lastmod
43
+ @changefreq = changefreq
44
+ @priority = priority
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module SitemapSimple
2
+ VERSION = '0.1.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sitemap_simple
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Thibault Jouan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '11.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '11.2'
27
+ description: Sitemap simple
28
+ email: tj@a13.fr
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/sitemap_simple/sitemap.rb
34
+ - lib/sitemap_simple/version.rb
35
+ homepage: https://rubygems.org/gems/sitemap_simple
36
+ licenses:
37
+ - BSD-3-Clause
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 2.5.1
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Sitemap simple
59
+ test_files: []