ktlacaelel-sitemaps 0.4.2 → 0.5.0

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/Rakefile CHANGED
@@ -5,13 +5,17 @@ begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "sitemaps"
8
- gem.summary = %Q{SEO Sitemap Generator}
9
- gem.description = %Q{Setup a config file & execute. I will download and compress your sitemaps!}
8
+ gem.summary = %Q{Setup a config yaml file. I will download & compress your sitemaps!}
9
+ gem.description = %Q{
10
+ Sitemaps provides an executable that will take a configuration yaml file.
11
+ When runned it will download and gzip-compress your sitemaps ready for production!
12
+ }
10
13
  gem.email = "kazu.dev@gmail.com"
11
14
  gem.homepage = "http://github.com/ktlacaelel/sitemaps"
12
15
  gem.authors = ["kazuyoshi tlacaelel"]
13
16
  gem.add_development_dependency "thoughtbot-shoulda"
14
17
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ gem.add_dependency('builder', '>=2.1.2')
15
19
  end
16
20
  rescue LoadError
17
21
  puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.2
1
+ 0.5.0
data/lib/generator.rb CHANGED
@@ -22,13 +22,54 @@ module Sitemaps
22
22
  def execute!
23
23
  download!
24
24
  compress!
25
+ compile!
25
26
  end
26
27
 
27
28
  protected
28
29
 
30
+ def compile!
31
+ compile_index
32
+ compile_robots
33
+ end
34
+
35
+ def compile_index
36
+ output = File.new(sitemaps_index_filename, 'w+')
37
+ xml = Builder::XmlMarkup.new(:target => output, :indent => 2)
38
+ xml.instruct! :version => '1.0', :encoding => 'UTF-8'
39
+ xml.sitemapindex :xmlns => 'http://www.sitemaps.org/schemas/sitemap/0.9' do
40
+ downloaded_maps.each do |map|
41
+ xml.sitemap do
42
+ xml.loc get_gzip_url(map)
43
+ xml.lastmod Time.now.strftime('%Y-%m-%d')
44
+ end
45
+ end
46
+ end
47
+ output.close
48
+ compress_file(sitemaps_index_filename, sitemaps_gziped_index_filename)
49
+ end
50
+
51
+ def compile_robots
52
+ File.open(robots_filename, 'w+') do |rostob|
53
+ rostob.puts 'Sitemap: %s/%s' % [@configuration.domain, sitemaps_gziped_index_filename]
54
+ end
55
+ end
56
+
57
+ def robots_filename
58
+ File.join(@configuration.dump_dir, 'robots.txt')
59
+ end
60
+
61
+ def sitemaps_index_filename
62
+ File.join(@configuration.dump_dir, 'index.xml')
63
+ end
64
+
65
+ def sitemaps_gziped_index_filename
66
+ File.join(@configuration.dump_dir, 'index.xml' + '.gz')
67
+ end
68
+
29
69
  def download!
30
70
  ensure_dump_dir
31
71
  Net::HTTP.start(@configuration.generator, '3000') do |http|
72
+ http.read_timeout = 999
32
73
  @configuration.targets.each do |target|
33
74
  store_downloaded_data target, http.get(target).body
34
75
  end
@@ -37,17 +78,29 @@ module Sitemaps
37
78
 
38
79
  def compress!
39
80
  ensure_compress_dir
40
- Dir.glob(download_path + '/*').each do |file|
41
- Zlib::GzipWriter.open(get_gzip_filename(file)) do |gz|
42
- gz.write File.read(file)
43
- end
44
- end
81
+ downloaded_maps.each { |map| compress_file(map, get_gzip_filename(map)) }
82
+ end
83
+
84
+ def compress_file(source, target)
85
+ Zlib::GzipWriter.open(target) { |gz| gz.write File.read(source) }
86
+ end
87
+
88
+ def downloaded_maps
89
+ Dir.glob(download_path + '/*')
45
90
  end
46
91
 
47
92
  def get_gzip_filename(long_path)
48
93
  File.join(compress_path, File.basename(long_path) + '.gz')
49
94
  end
50
95
 
96
+ def get_gzip_url(long_path)
97
+ [
98
+ @configuration.domain,
99
+ @configuration.dump_dir,
100
+ File.basename(long_path) + '.gz'
101
+ ].join('/')
102
+ end
103
+
51
104
  def ensure_dump_dir
52
105
  [@configuration.dump_dir, download_path].each do |path|
53
106
  Dir.mkdir path unless File.exist? path
data/lib/sitemaps.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'net/http'
4
4
  require 'yaml'
5
5
  require 'zlib'
6
+ require 'builder'
6
7
 
7
8
  # internal libraries
8
9
  require 'configuration'
data/sitemaps.gemspec CHANGED
@@ -5,13 +5,16 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sitemaps}
8
- s.version = "0.4.2"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["kazuyoshi tlacaelel"]
12
12
  s.date = %q{2009-09-15}
13
13
  s.default_executable = %q{sitemaps}
14
- s.description = %q{Setup a config file & execute. I will download and compress your sitemaps!}
14
+ s.description = %q{
15
+ Sitemaps provides an executable that will take a configuration yaml file.
16
+ When runned it will download and gzip-compress your sitemaps ready for production!
17
+ }
15
18
  s.email = %q{kazu.dev@gmail.com}
16
19
  s.executables = ["sitemaps"]
17
20
  s.extra_rdoc_files = [
@@ -47,7 +50,7 @@ Gem::Specification.new do |s|
47
50
  s.rdoc_options = ["--charset=UTF-8"]
48
51
  s.require_paths = ["lib"]
49
52
  s.rubygems_version = %q{1.3.3}
50
- s.summary = %q{SEO Sitemap Generator}
53
+ s.summary = %q{Setup a config yaml file. I will download & compress your sitemaps!}
51
54
  s.test_files = [
52
55
  "test/configuration_test.rb",
53
56
  "test/generator_test.rb",
@@ -60,10 +63,13 @@ Gem::Specification.new do |s|
60
63
 
61
64
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
62
65
  s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
66
+ s.add_runtime_dependency(%q<builder>, [">= 2.1.2"])
63
67
  else
64
68
  s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
69
+ s.add_dependency(%q<builder>, [">= 2.1.2"])
65
70
  end
66
71
  else
67
72
  s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
73
+ s.add_dependency(%q<builder>, [">= 2.1.2"])
68
74
  end
69
75
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ktlacaelel-sitemaps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kazuyoshi tlacaelel
@@ -22,7 +22,17 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: "0"
24
24
  version:
25
- description: Setup a config file & execute. I will download and compress your sitemaps!
25
+ - !ruby/object:Gem::Dependency
26
+ name: builder
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.2
34
+ version:
35
+ description: Sitemaps provides an executable that will take a configuration yaml file. When runned it will download and gzip-compress your sitemaps ready for production!
26
36
  email: kazu.dev@gmail.com
27
37
  executables:
28
38
  - sitemaps
@@ -57,6 +67,7 @@ files:
57
67
  - test/test_helper.rb
58
68
  has_rdoc: false
59
69
  homepage: http://github.com/ktlacaelel/sitemaps
70
+ licenses:
60
71
  post_install_message:
61
72
  rdoc_options:
62
73
  - --charset=UTF-8
@@ -77,10 +88,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
88
  requirements: []
78
89
 
79
90
  rubyforge_project:
80
- rubygems_version: 1.2.0
91
+ rubygems_version: 1.3.5
81
92
  signing_key:
82
93
  specification_version: 3
83
- summary: SEO Sitemap Generator
94
+ summary: Setup a config yaml file. I will download & compress your sitemaps!
84
95
  test_files:
85
96
  - test/configuration_test.rb
86
97
  - test/generator_test.rb