sitemaps 0.6.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.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 kazuyoshi tlacaelel
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,173 @@
1
+ = Sitemaps
2
+
3
+ Setup a config yaml file. I will download & compress your sitemaps!
4
+
5
+ Sitemaps provides an executable that will take a configuration yaml file.
6
+ When runned it will download and gzip-compress your sitemaps ready for production!
7
+
8
+ Basically the idea is that you do not want your production server to
9
+ compile the xml every single time, and on top of that you do not want
10
+ to (gzip) your sitemap on the fly nor tell your web-server to do that
11
+ for every single request.
12
+
13
+ So we precompile, the sitemaps and compress them in a "generator"
14
+ machine and store the static gziped-sitemaps on the webserver.
15
+
16
+ Sitemaps provides a simple way to do this, put the name of your
17
+ 'generator-machine' and setup your production domain, subdirectories
18
+ and sitemap-index (sitemap of sitemaps) will be dinamically generated
19
+ for you. so all you have to do is execute and copy to your web-servers!
20
+
21
+ a sample robots file is also generated for you, you can simply cat
22
+ this and append it to your existing robots.txt file or simply use it
23
+ as a reference if you are generating it dinamically.
24
+
25
+ By Kazuyoshi Tlacaelel
26
+
27
+
28
+ Run..
29
+
30
+ $ sitemaps config.yml
31
+
32
+ Enjoy!
33
+
34
+ $ tree sitemaps
35
+ sitemaps
36
+ |-- downloads
37
+ | `-- communities.xml
38
+ |-- index.xml
39
+ |-- index.xml.gz
40
+ |-- robots.txt
41
+ `-- sitemaps
42
+ `-- communities.xml.gz
43
+
44
+ 2 directories, 5 files
45
+
46
+ == Dependancies
47
+
48
+ # external libraries
49
+ require 'net/http'
50
+ require 'yaml'
51
+ require 'zlib'
52
+ require 'builder'
53
+
54
+ == Features
55
+
56
+ * automatic generation of sitemap indexes ( a sitemap of sitemaps )
57
+
58
+ $ cat sitemaps/index.xml
59
+
60
+ <?version1.0encodingUTF-8?>
61
+ <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
62
+ <sitemap>
63
+ <loc>http://example.com/sitemaps/communities.xml.gz</loc>
64
+ <lastmod>2009-09-15</lastmod>
65
+ </sitemap>
66
+ </sitemapindex>
67
+
68
+ * sample robots.txt generation
69
+
70
+ Sitemap: http://example.com/sitemaps/index.xml.gz
71
+
72
+ * download of sitemaps + compression
73
+
74
+ $ tree sitemaps
75
+
76
+ sitemaps
77
+ |-- downloads
78
+ | `-- communities.xml
79
+ |-- index.xml
80
+ |-- index.xml.gz
81
+ |-- robots.txt
82
+ `-- sitemaps
83
+ `-- communities.xml.gz
84
+
85
+ 2 directories, 5 files
86
+
87
+ * The config file
88
+
89
+ configuration:
90
+
91
+ # Machine that generates your sitemaps
92
+ # do not prefix "http://" nor append the port
93
+ generator: localhost
94
+
95
+ # The http-port of your generator
96
+ generator_port: 3000
97
+
98
+ # The time to wait for each sitemap to be received
99
+ generator_timeout: 999
100
+
101
+ # Domain from where the sitemaps will be available.
102
+ # It is important that you do not append the last slash
103
+ # otherwise you may get an error message
104
+ #
105
+ # NG
106
+ # http://example.com/
107
+ #
108
+ # OK
109
+ # http://example.com
110
+ #
111
+ domain: http://example.com
112
+
113
+ # Path to sitemaps to be compiled on "generator".
114
+ # For example: if you have the following url
115
+ #
116
+ # http://localhost:3000/sitemap_for/users.xml
117
+ #
118
+ # The target must be specified as such
119
+ #
120
+ # Note: you can have multiple targets
121
+ #
122
+ targets:
123
+ - /sitemap_for/users.xml
124
+
125
+ # Directory where compressed maps will be placed.
126
+ #
127
+ # Its a good idea to use a sub-path in your domain.
128
+ #
129
+ # For example:
130
+ # (your dump_dir could be sitemaps for the following url)
131
+ #
132
+ # http://example.com/sitemaps
133
+ #
134
+ dump_dir: sitemaps
135
+
136
+ == Install
137
+
138
+ $ gem sources -a http://gems.github.com
139
+ $ gem install ktlacaelel-sitemaps
140
+
141
+ == Note on Patches/Pull Requests
142
+
143
+ * Fork the project.
144
+ * Make your feature addition or bug fix.
145
+ * Add tests for it. This is important so I don't break it in a
146
+ future version unintentionally.
147
+ * Commit, do not mess with rakefile, version, or history.
148
+ (if you want to have your own version, that is fine but
149
+ bump version in a commit by itself I can ignore when I pull)
150
+ * Send me a pull request. Bonus points for topic branches.
151
+
152
+ == Ruby versions
153
+
154
+ ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0]
155
+ ruby 1.8.7 (2009-06-12 patchlevel 174) [x86_64-linux]
156
+
157
+ (havent tried any other let me know if you have any problems)
158
+
159
+ == Tested under
160
+
161
+ # Darwin tlacaelel.local 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:55:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_I386 i386
162
+ # Linux utopia.local 2.6.28-11-server #42-Ubuntu SMP Fri Apr 17 02:45:36 UTC 2009 x86_64 GNU/Linux
163
+
164
+ == Tests
165
+ only the download and compression part have no tests but the api is
166
+ pretty stable
167
+
168
+ == Copyright
169
+
170
+ MIT LICENSE
171
+
172
+ Copyright (c) 2009 kazuyoshi tlacaelel. See "LICENSE" file for details.
173
+
@@ -0,0 +1,60 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "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
+ }
13
+ gem.email = "kazu.dev@gmail.com"
14
+ gem.homepage = "http://github.com/ktlacaelel/sitemaps"
15
+ gem.authors = ["kazuyoshi tlacaelel"]
16
+ gem.add_development_dependency "thoughtbot-shoulda"
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')
19
+ end
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
22
+ end
23
+
24
+ require 'rake/testtask'
25
+ Rake::TestTask.new(:test) do |test|
26
+ test.libs << 'lib' << 'test'
27
+ test.pattern = 'test/**/*_test.rb'
28
+ test.verbose = true
29
+ end
30
+
31
+ begin
32
+ require 'rcov/rcovtask'
33
+ Rcov::RcovTask.new do |test|
34
+ test.libs << 'test'
35
+ test.pattern = 'test/**/*_test.rb'
36
+ test.verbose = true
37
+ end
38
+ rescue LoadError
39
+ task :rcov do
40
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
41
+ end
42
+ end
43
+
44
+ task :test => :check_dependencies
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/rdoctask'
49
+ Rake::RDocTask.new do |rdoc|
50
+ if File.exist?('VERSION')
51
+ version = File.read('VERSION')
52
+ else
53
+ version = ""
54
+ end
55
+
56
+ rdoc.rdoc_dir = 'rdoc'
57
+ rdoc.title = "sitemaps #{version}"
58
+ rdoc.rdoc_files.include('README*')
59
+ rdoc.rdoc_files.include('lib/**/*.rb')
60
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.6.0
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'rubygems'
4
+ require 'sitemaps'
5
+
6
+ configuration = Sitemaps::Configuration.new(ARGV[0])
7
+ Sitemaps::Generator.new(configuration).execute!
8
+
@@ -0,0 +1,109 @@
1
+ module Sitemaps
2
+
3
+ class Configuration
4
+
5
+ attr_reader :generator, :domain, :targets, :dump_dir, :generator_port, :generator_timeout
6
+
7
+ def initialize(yaml_file)
8
+ @yaml_file = yaml_file
9
+ validate!
10
+ end
11
+
12
+ protected
13
+
14
+ def validate!
15
+ validate_file!
16
+ validate_generator!
17
+ validate_generator_port!
18
+ validate_generator_timeout!
19
+ validate_domain!
20
+ validate_dump_dir!
21
+ validate_targets!
22
+ end
23
+
24
+ def validate_file!
25
+ unless @yaml_file.is_a? String
26
+ raise InvalidConfigurationError.new('Not a valid config filename')
27
+ end
28
+ unless File.exist? @yaml_file
29
+ raise InvalidConfigurationError.new('File not found: %s' % @yaml_file)
30
+ end
31
+ @configuration = YAML::load_file(@yaml_file)
32
+ unless @configuration.is_a? Hash
33
+ raise InvalidConfigurationError.new('Incorrect yaml-syntax')
34
+ end
35
+ @configuration = @configuration['configuration']
36
+ end
37
+
38
+ def validate_generator_timeout!
39
+ unless @configuration.keys.include? 'generator_timeout'
40
+ raise InvalidConfigurationError.new('Missing generator timeout in config')
41
+ end
42
+ unless @configuration['generator_timeout'].is_a? Fixnum
43
+ raise InvalidConfigurationError.new('Please specify a generator timeout')
44
+ end
45
+ @generator_timeout = @configuration['generator_timeout']
46
+ end
47
+
48
+ def validate_generator_port!
49
+ unless @configuration.keys.include? 'generator_port'
50
+ raise InvalidConfigurationError.new('Missing generator port in config')
51
+ end
52
+ unless @configuration['generator_port'].is_a? Fixnum
53
+ raise InvalidConfigurationError.new('Please specify a generator port')
54
+ end
55
+ @generator_port = @configuration['generator_port']
56
+ end
57
+
58
+ def validate_generator!
59
+ unless @configuration.keys.include? 'generator'
60
+ raise InvalidConfigurationError.new('Missing generator in config')
61
+ end
62
+ if @configuration['generator'].nil? || @configuration['generator'] == ''
63
+ raise InvalidConfigurationError.new('Please specify a generator')
64
+ end
65
+ unless @configuration['generator'].is_a? String
66
+ raise InvalidConfigurationError.new('Generator is not a string')
67
+ end
68
+ if @configuration['generator'] =~ /^http/
69
+ raise InvalidConfigurationError.new('Do not prefix generator with http')
70
+ end
71
+ if @configuration['generator'] =~ /:\d+$/
72
+ raise InvalidConfigurationError.new('Do not sufix generator with port!')
73
+ end
74
+ @generator = @configuration['generator']
75
+ end
76
+
77
+ def validate_domain!
78
+ unless @configuration.keys.include? 'domain'
79
+ raise InvalidConfigurationError.new('Missing domain in config')
80
+ end
81
+ if @configuration['domain'].nil? || @configuration['domain'] == ''
82
+ raise InvalidConfigurationError.new('Please specify a domain')
83
+ end
84
+ @domain = @configuration['domain']
85
+ end
86
+
87
+ def validate_targets!
88
+ unless @configuration.keys.include? 'targets'
89
+ raise InvalidConfigurationError.new('Missing targets in config')
90
+ end
91
+ if !@configuration['targets'].is_a?(Array) || @configuration['targets'].size == 0
92
+ raise InvalidConfigurationError.new('Please specify some targets')
93
+ end
94
+ @targets = @configuration['targets']
95
+ end
96
+
97
+ def validate_dump_dir!
98
+ unless @configuration.keys.include? 'dump_dir'
99
+ raise InvalidConfigurationError.new('Missing dump_dir in config')
100
+ end
101
+ if @configuration['dump_dir'].nil? || @configuration['dump_dir'] == ''
102
+ raise InvalidConfigurationError.new('Please specify a dump_dir')
103
+ end
104
+ @dump_dir = @configuration['dump_dir']
105
+ end
106
+
107
+ end
108
+
109
+ end
@@ -0,0 +1,136 @@
1
+ module Sitemaps
2
+
3
+ class Generator
4
+
5
+ attr_reader :configuration
6
+
7
+ def initialize(configuration_object)
8
+ self.configuration = configuration_object
9
+ end
10
+
11
+ def prepare
12
+ Dir.mkdir configuration.dump_dir
13
+ end
14
+
15
+ def configuration=(object)
16
+ unless object.is_a? Configuration
17
+ raise InvalidConfigurationError.new('Not a sitemap configuration object!')
18
+ end
19
+ @configuration = object
20
+ end
21
+
22
+ def execute!
23
+ download!
24
+ compress!
25
+ compile!
26
+ end
27
+
28
+ protected
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
+
69
+ def download!
70
+ ensure_dump_dir
71
+ Net::HTTP.start(@configuration.generator, @configuration.generator_port) do |http|
72
+ http.read_timeout = @configuration.generator_timeout
73
+ @configuration.targets.each do |target|
74
+ store_downloaded_data target, http.get(target).body
75
+ end
76
+ end
77
+ end
78
+
79
+ def compress!
80
+ ensure_compress_dir
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 + '/*')
90
+ end
91
+
92
+ def get_gzip_filename(long_path)
93
+ File.join(compress_path, File.basename(long_path) + '.gz')
94
+ end
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
+
104
+ def ensure_dump_dir
105
+ [@configuration.dump_dir, download_path].each do |path|
106
+ Dir.mkdir path unless File.exist? path
107
+ end
108
+ end
109
+
110
+ def ensure_compress_dir
111
+ unless File.exist? compress_path
112
+ Dir.mkdir compress_path
113
+ end
114
+ end
115
+
116
+ def store_downloaded_data(target, data)
117
+ File.open(download_target_for(target), 'w+') do |file|
118
+ file.write data
119
+ end
120
+ end
121
+
122
+ def compress_path
123
+ @compress_path ||= File.join(@configuration.dump_dir, @configuration.dump_dir)
124
+ end
125
+
126
+ def download_target_for(target)
127
+ File.join(download_path, File.basename(target))
128
+ end
129
+
130
+ def download_path
131
+ File.join(@configuration.dump_dir, 'downloads')
132
+ end
133
+
134
+ end
135
+
136
+ end
@@ -0,0 +1,6 @@
1
+ module Sitemaps
2
+
3
+ class InvalidConfigurationError < Exception
4
+ end
5
+
6
+ end
@@ -0,0 +1,12 @@
1
+
2
+ # external libraries
3
+ require 'net/http'
4
+ require 'yaml'
5
+ require 'zlib'
6
+ require 'builder'
7
+
8
+ # internal libraries
9
+ require 'configuration'
10
+ require 'invalid_configuration_error'
11
+ require 'generator'
12
+
@@ -0,0 +1,79 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{sitemaps}
8
+ s.version = "0.6.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["kazuyoshi tlacaelel"]
12
+ s.date = %q{2009-09-15}
13
+ s.default_executable = %q{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
+ }
18
+ s.email = %q{kazu.dev@gmail.com}
19
+ s.executables = ["sitemaps"]
20
+ s.extra_rdoc_files = [
21
+ "LICENSE",
22
+ "README.rdoc"
23
+ ]
24
+ s.files = [
25
+ ".document",
26
+ ".gitignore",
27
+ "LICENSE",
28
+ "README.rdoc",
29
+ "Rakefile",
30
+ "VERSION",
31
+ "bin/sitemaps",
32
+ "lib/configuration.rb",
33
+ "lib/generator.rb",
34
+ "lib/invalid_configuration_error.rb",
35
+ "lib/sitemaps.rb",
36
+ "sitemaps.gemspec",
37
+ "test/configuration_test.rb",
38
+ "test/data/empty_configuration_file.yml",
39
+ "test/data/generator_with_http_configuration_file.yml",
40
+ "test/data/generator_with_port_configuration_file.yml",
41
+ "test/data/invalid_configuration_file.yml",
42
+ "test/data/no_domain_configuration_file.yml",
43
+ "test/data/no_dump_dir_configuration_file.yml",
44
+ "test/data/no_generator_configuration_file.yml",
45
+ "test/data/no_port_configuration_file.yml",
46
+ "test/data/no_targets_configuration_file.yml",
47
+ "test/data/no_timeout_configuration_file.yml",
48
+ "test/data/valid_configuration_file.yml",
49
+ "test/data/valid_configuration_file2.yml",
50
+ "test/generator_test.rb",
51
+ "test/test_helper.rb"
52
+ ]
53
+ s.homepage = %q{http://github.com/ktlacaelel/sitemaps}
54
+ s.rdoc_options = ["--charset=UTF-8"]
55
+ s.require_paths = ["lib"]
56
+ s.rubygems_version = %q{1.3.3}
57
+ s.summary = %q{Setup a config yaml file. I will download & compress your sitemaps!}
58
+ s.test_files = [
59
+ "test/configuration_test.rb",
60
+ "test/generator_test.rb",
61
+ "test/test_helper.rb"
62
+ ]
63
+
64
+ if s.respond_to? :specification_version then
65
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
66
+ s.specification_version = 3
67
+
68
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
69
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
70
+ s.add_runtime_dependency(%q<builder>, [">= 2.1.2"])
71
+ else
72
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
73
+ s.add_dependency(%q<builder>, [">= 2.1.2"])
74
+ end
75
+ else
76
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
77
+ s.add_dependency(%q<builder>, [">= 2.1.2"])
78
+ end
79
+ end
@@ -0,0 +1,108 @@
1
+ require 'test_helper'
2
+
3
+ class ConfigurationTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @empty = 'test/data/empty_configuration_file.yml'
7
+ @invalid = 'test/data/invalid_configuration_file.yml'
8
+ @no_domain = 'test/data/no_domain_configuration_file.yml'
9
+ @no_dump_dir = 'test/data/no_dump_dir_configuration_file.yml'
10
+ @no_generator = 'test/data/no_generator_configuration_file.yml'
11
+ @no_port = 'test/data/no_port_configuration_file.yml'
12
+ @no_targets = 'test/data/no_targets_configuration_file.yml'
13
+ @no_timeout = 'test/data/no_timeout_configuration_file.yml'
14
+ @gen_n_port = 'test/data/generator_with_port_configuration_file.yml'
15
+ @gen_n_http = 'test/data/generator_with_http_configuration_file.yml'
16
+ @valid = 'test/data/valid_configuration_file.yml'
17
+ end
18
+
19
+ # ============================================================================
20
+ # YAML LOADING
21
+ # ============================================================================
22
+
23
+ should 'check if configuration file exists' do
24
+ assert_raise(Sitemaps::InvalidConfigurationError) { Sitemaps::Configuration.new('a') }
25
+ assert_raise(Sitemaps::InvalidConfigurationError) { Sitemaps::Configuration.new(nil) }
26
+ end
27
+
28
+ should 'load a configuration file' do
29
+ Sitemaps::Configuration.new(@valid)
30
+ end
31
+
32
+ # ============================================================================
33
+ # MISSING PARAMETERS
34
+ # ============================================================================
35
+
36
+ should 'raise an error when generator is not given' do
37
+ assert_raise(Sitemaps::InvalidConfigurationError) { Sitemaps::Configuration.new(@no_generator) }
38
+ end
39
+
40
+ should 'raise an error when generator port is not given' do
41
+ assert_raise(Sitemaps::InvalidConfigurationError) { Sitemaps::Configuration.new(@no_port) }
42
+ end
43
+
44
+ should 'raise an error when generator timeout is not given' do
45
+ assert_raise(Sitemaps::InvalidConfigurationError) { Sitemaps::Configuration.new(@no_timeout) }
46
+ end
47
+
48
+ should 'raise an error when domain is not given' do
49
+ assert_raise(Sitemaps::InvalidConfigurationError) { Sitemaps::Configuration.new(@no_domain) }
50
+ end
51
+
52
+ should 'raise an error when targets is not given' do
53
+ assert_raise(Sitemaps::InvalidConfigurationError) { Sitemaps::Configuration.new(@no_targets) }
54
+ end
55
+
56
+ should 'raise an error when dump_dir is not given' do
57
+ assert_raise(Sitemaps::InvalidConfigurationError) { Sitemaps::Configuration.new(@no_dump_dir) }
58
+ end
59
+
60
+ # ============================================================================
61
+ # INVALID FORMAT
62
+ # ============================================================================
63
+
64
+ should 'raise an error when generator given has port' do
65
+ assert_raise(Sitemaps::InvalidConfigurationError) do
66
+ Sitemaps::Configuration.new(@gen_n_port)
67
+ end
68
+ end
69
+
70
+ should 'raise an error when generator given includes "http://" prefixed' do
71
+ assert_raise(Sitemaps::InvalidConfigurationError) do
72
+ Sitemaps::Configuration.new(@gen_n_http)
73
+ end
74
+ end
75
+
76
+ # ============================================================================
77
+ # CONFIGURATION ACCESS
78
+ # ============================================================================
79
+
80
+ def config
81
+ Sitemaps::Configuration.new(@valid)
82
+ end
83
+
84
+ should 'retrive generator' do
85
+ assert_equal 'localhost', config.generator
86
+ end
87
+
88
+ should 'retrive generator port' do
89
+ assert_equal 3000, config.generator_port
90
+ end
91
+
92
+ should 'retrive ttl' do
93
+ assert_equal 999, config.generator_timeout
94
+ end
95
+
96
+ should 'retrive domain' do
97
+ assert_equal 'http://example.com', config.domain
98
+ end
99
+
100
+ should 'retrive targets' do
101
+ assert_equal ['/sitemap_for/users.xml'], config.targets
102
+ end
103
+
104
+ should 'retrive dump_dir' do
105
+ assert_equal 'sitemaps', config.dump_dir
106
+ end
107
+
108
+ end
File without changes
@@ -0,0 +1,11 @@
1
+
2
+ configuration:
3
+
4
+ generator: http://localhost
5
+ generator_port: 3000
6
+ generator_timeout: 999
7
+ domain: http://example.com
8
+ targets:
9
+ - /sitemap_for/users.xml
10
+ dump_dir: sitemaps
11
+
@@ -0,0 +1,11 @@
1
+
2
+ configuration:
3
+
4
+ generator: localhost:3000
5
+ generator_port: 3000
6
+ generator_timeout: 999
7
+ domain: http://example.com
8
+ targets:
9
+ - /sitemap_for/users.xml
10
+ dump_dir: sitemaps
11
+
@@ -0,0 +1,9 @@
1
+
2
+ configuration:
3
+ generator: localhost
4
+ generator_timeout: 999
5
+ generator_port: 3000
6
+ targets:
7
+ - /sitemap_for/users.xml
8
+ dump_dir: sitemaps
9
+
@@ -0,0 +1,9 @@
1
+
2
+ configuration:
3
+ generator: localhost
4
+ generator_timeout: 999
5
+ generator_port: 3000
6
+ domain: http://example.com
7
+ targets:
8
+ - /sitemap_for/users.xml
9
+
@@ -0,0 +1,9 @@
1
+
2
+ configuration:
3
+ domain: http://example.com
4
+ generator_timeout: 999
5
+ generator_port: 3000
6
+ targets:
7
+ - /sitemap_for/users.xml
8
+ dump_dir: sitemaps
9
+
@@ -0,0 +1,9 @@
1
+
2
+ configuration:
3
+ generator: localhost
4
+ generator_port: 3000
5
+ domain: http://example.com
6
+ targets:
7
+ - /sitemap_for/users.xml
8
+ dump_dir: sitemaps
9
+
@@ -0,0 +1,8 @@
1
+
2
+ configuration:
3
+ generator: localhost
4
+ generator_timeout: 999
5
+ generator_port: 3000
6
+ domain: http://example.com
7
+ dump_dir: sitemaps
8
+
@@ -0,0 +1,8 @@
1
+
2
+ configuration:
3
+ generator: localhost
4
+ generator_timeout: 999
5
+ domain: http://example.com
6
+ targets:
7
+ - /sitemap_for/users.xml
8
+ dump_dir: sitemaps
@@ -0,0 +1,48 @@
1
+
2
+ configuration:
3
+
4
+ # Machine that generates your sitemaps
5
+ # do not prefix "http://" nor append the port
6
+ generator: localhost
7
+
8
+ # The http-port of your generator
9
+ generator_port: 3000
10
+
11
+ # The time to wait for each sitemap to be received
12
+ generator_timeout: 999
13
+
14
+ # Domain from where the sitemaps will be available.
15
+ # It is important that you do not append the last slash
16
+ # otherwise you may get an error message
17
+ #
18
+ # NG
19
+ # http://example.com/
20
+ #
21
+ # OK
22
+ # http://example.com
23
+ #
24
+ domain: http://example.com
25
+
26
+ # Path to sitemaps to be compiled on "generator".
27
+ # For example: if you have the following url
28
+ #
29
+ # http://localhost:3000/sitemap_for/users.xml
30
+ #
31
+ # The target must be specified as such
32
+ #
33
+ # Note: you can have multiple targets
34
+ #
35
+ targets:
36
+ - /sitemap_for/users.xml
37
+
38
+ # Directory where compressed maps will be placed.
39
+ #
40
+ # Its a good idea to use a sub-path in your domain.
41
+ #
42
+ # For example:
43
+ # (your dump_dir could be sitemaps for the following url)
44
+ #
45
+ # http://example.com/sitemaps
46
+ #
47
+ dump_dir: sitemaps
48
+
@@ -0,0 +1,19 @@
1
+
2
+ configuration:
3
+
4
+ # machine that generates sitemaps in xml format
5
+ generator: xxxxxxxxx
6
+
7
+ generator_timeout: 999
8
+ generator_port: 3000
9
+
10
+ # domain from where the sitemaps will be available
11
+ domain: http://example.com
12
+
13
+ # path to sitemaps to be compiled
14
+ targets:
15
+ - /sitemap_for/users.xml
16
+
17
+ # directory where compressed maps will be placed
18
+ dump_dir: sitemaps
19
+
@@ -0,0 +1,38 @@
1
+ require 'test_helper'
2
+
3
+ class GeneratorTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @valid = 'test/data/valid_configuration_file.yml'
7
+ @valid2 = 'test/data/valid_configuration_file2.yml'
8
+ @config = Sitemaps::Configuration.new(@valid)
9
+ end
10
+
11
+ should 'check for a sitemap configuration on instantiantion' do
12
+ assert_raise (Sitemaps::InvalidConfigurationError) do
13
+ Sitemaps::Generator.new(nil)
14
+ end
15
+ end
16
+
17
+ should 'prepare dump_dir' do
18
+ `rm -rf sitemaps`
19
+ Sitemaps::Generator.new(@config).prepare
20
+ assert File.exist? 'sitemaps'
21
+ end
22
+
23
+ should 'get config' do
24
+ config = Sitemaps::Generator.new(@config).configuration
25
+ assert_equal config.generator, 'localhost'
26
+ end
27
+
28
+ should 'change config' do
29
+ generator = Sitemaps::Generator.new(@config)
30
+ new_config = Sitemaps::Configuration.new(@valid2)
31
+ generator.configuration = new_config
32
+ assert_equal new_config, generator.configuration
33
+ end
34
+
35
+ should 'should download sitemaps'
36
+ should 'should gzip sitemaps'
37
+
38
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'sitemaps'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sitemaps
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ platform: ruby
6
+ authors:
7
+ - kazuyoshi tlacaelel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-15 00:00:00 +09:00
13
+ default_executable: sitemaps
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thoughtbot-shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
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: "\n Sitemaps provides an executable that will take a configuration yaml file.\n When runned it will download and gzip-compress your sitemaps ready for production!\n "
36
+ email: kazu.dev@gmail.com
37
+ executables:
38
+ - sitemaps
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - bin/sitemaps
52
+ - lib/configuration.rb
53
+ - lib/generator.rb
54
+ - lib/invalid_configuration_error.rb
55
+ - lib/sitemaps.rb
56
+ - sitemaps.gemspec
57
+ - test/configuration_test.rb
58
+ - test/data/empty_configuration_file.yml
59
+ - test/data/generator_with_http_configuration_file.yml
60
+ - test/data/generator_with_port_configuration_file.yml
61
+ - test/data/invalid_configuration_file.yml
62
+ - test/data/no_domain_configuration_file.yml
63
+ - test/data/no_dump_dir_configuration_file.yml
64
+ - test/data/no_generator_configuration_file.yml
65
+ - test/data/no_port_configuration_file.yml
66
+ - test/data/no_targets_configuration_file.yml
67
+ - test/data/no_timeout_configuration_file.yml
68
+ - test/data/valid_configuration_file.yml
69
+ - test/data/valid_configuration_file2.yml
70
+ - test/generator_test.rb
71
+ - test/test_helper.rb
72
+ has_rdoc: true
73
+ homepage: http://github.com/ktlacaelel/sitemaps
74
+ licenses: []
75
+
76
+ post_install_message:
77
+ rdoc_options:
78
+ - --charset=UTF-8
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "0"
86
+ version:
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: "0"
92
+ version:
93
+ requirements: []
94
+
95
+ rubyforge_project:
96
+ rubygems_version: 1.3.5
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: Setup a config yaml file. I will download & compress your sitemaps!
100
+ test_files:
101
+ - test/configuration_test.rb
102
+ - test/generator_test.rb
103
+ - test/test_helper.rb