ktlacaelel-sitemaps 0.2.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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
6
+ sitemaps
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.
data/README.rdoc ADDED
@@ -0,0 +1,18 @@
1
+ = sitemaps
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2009 kazuyoshi tlacaelel. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
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{SEO Sitemap Generator}
9
+ gem.description = %Q{Setup a config file & execute. I will download and compress your sitemaps!}
10
+ gem.email = "kazu.dev@gmail.com"
11
+ gem.homepage = "http://github.com/ktlacaelel/sitemaps"
12
+ gem.authors = ["kazuyoshi tlacaelel"]
13
+ gem.add_development_dependency "thoughtbot-shoulda"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/*_test.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/*_test.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ task :test => :check_dependencies
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ if File.exist?('VERSION')
47
+ version = File.read('VERSION')
48
+ else
49
+ version = ""
50
+ end
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "sitemaps #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
data/lib/cli.rb ADDED
@@ -0,0 +1,6 @@
1
+ module Sitemaps
2
+
3
+ class Cli
4
+ end
5
+
6
+ end
@@ -0,0 +1,78 @@
1
+ module Sitemaps
2
+
3
+ class Configuration
4
+
5
+ attr_reader :generator, :domain, :targets, :dump_dir
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_domain!
18
+ validate_dump_dir!
19
+ validate_targets!
20
+ end
21
+
22
+ def validate_file!
23
+ unless @yaml_file.is_a? String
24
+ raise InvalidConfigurationError.new('Not a valid config filename')
25
+ end
26
+ unless File.exist? @yaml_file
27
+ raise InvalidConfigurationError.new('File not found: %s' % @yaml_file)
28
+ end
29
+ @configuration = YAML::load_file(@yaml_file)
30
+ unless @configuration.is_a? Hash
31
+ raise InvalidConfigurationError.new('Incorrect yaml-syntax')
32
+ end
33
+ @configuration = @configuration['configuration']
34
+ end
35
+
36
+ def validate_generator!
37
+ unless @configuration.keys.include? 'generator'
38
+ raise InvalidConfigurationError.new('Missing generator in config')
39
+ end
40
+ if @configuration['generator'].nil? || @configuration['generator'] == ''
41
+ raise InvalidConfigurationError.new('Please specify a generator')
42
+ end
43
+ @generator = @configuration['generator']
44
+ end
45
+
46
+ def validate_domain!
47
+ unless @configuration.keys.include? 'domain'
48
+ raise InvalidConfigurationError.new('Missing domain in config')
49
+ end
50
+ if @configuration['domain'].nil? || @configuration['domain'] == ''
51
+ raise InvalidConfigurationError.new('Please specify a domain')
52
+ end
53
+ @domain = @configuration['domain']
54
+ end
55
+
56
+ def validate_targets!
57
+ unless @configuration.keys.include? 'targets'
58
+ raise InvalidConfigurationError.new('Missing targets in config')
59
+ end
60
+ if !@configuration['targets'].is_a?(Array) || @configuration['targets'].size == 0
61
+ raise InvalidConfigurationError.new('Please specify some targets')
62
+ end
63
+ @targets = @configuration['targets']
64
+ end
65
+
66
+ def validate_dump_dir!
67
+ unless @configuration.keys.include? 'dump_dir'
68
+ raise InvalidConfigurationError.new('Missing dump_dir in config')
69
+ end
70
+ if @configuration['dump_dir'].nil? || @configuration['dump_dir'] == ''
71
+ raise InvalidConfigurationError.new('Please specify a dump_dir')
72
+ end
73
+ @dump_dir = @configuration['dump_dir']
74
+ end
75
+
76
+ end
77
+
78
+ end
data/lib/generator.rb ADDED
@@ -0,0 +1,6 @@
1
+ module Sitemaps
2
+
3
+ class Generator
4
+ end
5
+
6
+ end
@@ -0,0 +1,2 @@
1
+ class InvalidConfigurationError < Exception
2
+ end
data/lib/sitemaps.rb ADDED
@@ -0,0 +1,12 @@
1
+
2
+ # external libraries
3
+ require 'net/http'
4
+ require 'yaml'
5
+ require 'zlib'
6
+
7
+ # internal libraries
8
+ require 'cli'
9
+ require 'configuration'
10
+ require 'invalid_configuration_error'
11
+ require 'generator'
12
+
data/sitemaps.gemspec ADDED
@@ -0,0 +1,68 @@
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.2.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-10}
13
+ s.description = %q{Setup a config file & execute. I will download and compress your sitemaps!}
14
+ s.email = %q{kazu.dev@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/cli.rb",
27
+ "lib/configuration.rb",
28
+ "lib/generator.rb",
29
+ "lib/invalid_configuration_error.rb",
30
+ "lib/sitemaps.rb",
31
+ "sitemaps.gemspec",
32
+ "test/cli_test.rb",
33
+ "test/configuration_test.rb",
34
+ "test/data/empty_configuration_file.yml",
35
+ "test/data/invalid_configuration_file.yml",
36
+ "test/data/no_domain_configuration_file.yml",
37
+ "test/data/no_dump_dir_configuration_file.yml",
38
+ "test/data/no_generator_configuration_file.yml",
39
+ "test/data/no_targets_configuration_file.yml",
40
+ "test/data/valid_configuration_file.yml",
41
+ "test/generator_test.rb",
42
+ "test/test_helper.rb"
43
+ ]
44
+ s.homepage = %q{http://github.com/ktlacaelel/sitemaps}
45
+ s.rdoc_options = ["--charset=UTF-8"]
46
+ s.require_paths = ["lib"]
47
+ s.rubygems_version = %q{1.3.3}
48
+ s.summary = %q{SEO Sitemap Generator}
49
+ s.test_files = [
50
+ "test/cli_test.rb",
51
+ "test/configuration_test.rb",
52
+ "test/generator_test.rb",
53
+ "test/test_helper.rb"
54
+ ]
55
+
56
+ if s.respond_to? :specification_version then
57
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
58
+ s.specification_version = 3
59
+
60
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
61
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
62
+ else
63
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
64
+ end
65
+ else
66
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
67
+ end
68
+ end
data/test/cli_test.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'test_helper'
2
+
3
+ class CliTest < Test::Unit::TestCase
4
+ end
@@ -0,0 +1,72 @@
1
+ require 'test_helper'
2
+
3
+ class ConfigurationTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @valid = 'test/data/valid_configuration_file.yml'
7
+ @invalid = 'test/data/invalid_configuration_file.yml'
8
+ @empty = 'test/data/empty_configuration_file.yml'
9
+ @no_generator = 'test/data/no_generator_configuration_file.yml'
10
+ @no_domain = 'test/data/no_domain_configuration_file.yml'
11
+ @no_targets = 'test/data/no_targets_configuration_file.yml'
12
+ @no_dump_dir = 'test/data/no_dump_dir_configuration_file.yml'
13
+ end
14
+
15
+ # ============================================================================
16
+ # YAML LOADING
17
+ # ============================================================================
18
+
19
+ should 'check if configuration file exists' do
20
+ assert_raise (InvalidConfigurationError) { Sitemaps::Configuration.new('a') }
21
+ assert_raise (InvalidConfigurationError) { Sitemaps::Configuration.new(nil) }
22
+ end
23
+
24
+ should 'load a configuration file' do
25
+ Sitemaps::Configuration.new(@valid)
26
+ end
27
+
28
+ # ============================================================================
29
+ # MISSING PARAMETERS
30
+ # ============================================================================
31
+
32
+ should 'throw an error when generator is not given' do
33
+ assert_raise (InvalidConfigurationError) { Sitemaps::Configuration.new(@no_generator) }
34
+ end
35
+
36
+ should 'throw an error when domain is not given' do
37
+ assert_raise (InvalidConfigurationError) { Sitemaps::Configuration.new(@no_domain) }
38
+ end
39
+
40
+ should 'throw an error when targets is not given' do
41
+ assert_raise (InvalidConfigurationError) { Sitemaps::Configuration.new(@no_targets) }
42
+ end
43
+
44
+ should 'throw an error when dump_dir is not given' do
45
+ assert_raise (InvalidConfigurationError) { Sitemaps::Configuration.new(@no_dump_dir) }
46
+ end
47
+
48
+ # ============================================================================
49
+ # CONFIGURATION ACCESS
50
+ # ============================================================================
51
+
52
+ def config
53
+ Sitemaps::Configuration.new(@valid)
54
+ end
55
+
56
+ should 'retrive generator' do
57
+ assert_equal 'http://localhost:3000', config.generator
58
+ end
59
+
60
+ should 'retrive domain' do
61
+ assert_equal 'http://example.com', config.domain
62
+ end
63
+
64
+ should 'retrive targets' do
65
+ assert_equal ['/sitemap_for/users.xml'], config.targets
66
+ end
67
+
68
+ should 'retrive dump_dir' do
69
+ assert_equal 'sitemaps', config.dump_dir
70
+ end
71
+
72
+ end
File without changes
File without changes
@@ -0,0 +1,7 @@
1
+
2
+ configuration:
3
+ generator: http://localhost:3000
4
+ targets:
5
+ - /sitemap_for/users.xml
6
+ dump_dir: sitemaps
7
+
@@ -0,0 +1,7 @@
1
+
2
+ configuration:
3
+ generator: http://localhost:3000
4
+ domain: http://example.com
5
+ targets:
6
+ - /sitemap_for/users.xml
7
+
@@ -0,0 +1,7 @@
1
+
2
+ configuration:
3
+ domain: http://example.com
4
+ targets:
5
+ - /sitemap_for/users.xml
6
+ dump_dir: sitemaps
7
+
@@ -0,0 +1,6 @@
1
+
2
+ configuration:
3
+ generator: http://localhost:3000
4
+ domain: http://example.com
5
+ dump_dir: sitemaps
6
+
@@ -0,0 +1,16 @@
1
+
2
+ configuration:
3
+
4
+ # machine that generates sitemaps in xml format
5
+ generator: http://localhost:3000
6
+
7
+ # domain from where the sitemaps will be available
8
+ domain: http://example.com
9
+
10
+ # path to sitemaps to be compiled
11
+ targets:
12
+ - /sitemap_for/users.xml
13
+
14
+ # directory where compressed maps will be placed
15
+ dump_dir: sitemaps
16
+
@@ -0,0 +1,36 @@
1
+ require 'test_helper'
2
+
3
+ class GeneratorTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @valid = 'test/data/valid_configuration_file.yml'
7
+ @config = Sitemaps::Configuration.new(@valid)
8
+ end
9
+
10
+ should 'check for a sitemap configuration on instantiantion' do
11
+ assert_raise (InvalidConfigurationError) do
12
+ Sitemaps::Generator.new(nil)
13
+ end
14
+ end
15
+
16
+ should 'prepare dump_dir' do
17
+ Sitemaps::Generator.new(@config).prepare
18
+ assert File.exist? 'sitemaps'
19
+ end
20
+
21
+ should 'get config' do
22
+ config = Sitemaps::Generator.new(@config).configuration
23
+ assert_equal config.generator, 'http://localhost:3000'
24
+ end
25
+
26
+ should 'change config' do
27
+ generator = Sitemaps::Generator.new(@config)
28
+ @config.stub(:generator).returns('changed!')
29
+ generator.change_config @config
30
+ assert_equal generator.configuration.generator, 'changed!'
31
+ end
32
+
33
+ should 'should download sitemaps'
34
+ should 'should gzip sitemaps'
35
+
36
+ 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,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ktlacaelel-sitemaps
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - kazuyoshi tlacaelel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-10 00:00:00 -07:00
13
+ default_executable:
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
+ description: Setup a config file & execute. I will download and compress your sitemaps!
26
+ email: kazu.dev@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - lib/cli.rb
42
+ - lib/configuration.rb
43
+ - lib/generator.rb
44
+ - lib/invalid_configuration_error.rb
45
+ - lib/sitemaps.rb
46
+ - sitemaps.gemspec
47
+ - test/cli_test.rb
48
+ - test/configuration_test.rb
49
+ - test/data/empty_configuration_file.yml
50
+ - test/data/invalid_configuration_file.yml
51
+ - test/data/no_domain_configuration_file.yml
52
+ - test/data/no_dump_dir_configuration_file.yml
53
+ - test/data/no_generator_configuration_file.yml
54
+ - test/data/no_targets_configuration_file.yml
55
+ - test/data/valid_configuration_file.yml
56
+ - test/generator_test.rb
57
+ - test/test_helper.rb
58
+ has_rdoc: false
59
+ homepage: http://github.com/ktlacaelel/sitemaps
60
+ post_install_message:
61
+ rdoc_options:
62
+ - --charset=UTF-8
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.2.0
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: SEO Sitemap Generator
84
+ test_files:
85
+ - test/cli_test.rb
86
+ - test/configuration_test.rb
87
+ - test/generator_test.rb
88
+ - test/test_helper.rb