spree_dynamic_sitemaps 0.50.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +32 -0
- data/Rakefile +120 -0
- data/app/controllers/sitemap_controller.rb +99 -0
- data/app/helpers/sitemap_helper.rb +2 -0
- data/app/views/sitemap/index.html.erb +29 -0
- data/app/views/sitemap/index.text.erb +4 -0
- data/app/views/sitemap/index.xml.builder +0 -0
- data/config/routes.rb +5 -0
- data/lib/dynamic_sitemaps.rb +17 -0
- data/lib/tasks/dynamic_sitemaps.rake +10 -0
- data/lib/tasks/install.rake +26 -0
- data/spree_dynamic_sitemaps.gemspec +19 -0
- metadata +75 -0
data/README.markdown
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
SUMMARY
|
2
|
+
=======
|
3
|
+
|
4
|
+
This Spree extension generates dynamic, seo-friendly sitemaps on the fly in html, xml and txt formats.
|
5
|
+
|
6
|
+
This extension is compatible with the [static_content][1] extension and will check for content in the Page table.
|
7
|
+
|
8
|
+
In order to avoid an seo penalty for duplicate content, products are only listed once at /product/_productName_
|
9
|
+
|
10
|
+
for rails 3 and spree >= 0.30.0
|
11
|
+
|
12
|
+
INSTALLATION
|
13
|
+
------------
|
14
|
+
|
15
|
+
1. Install the extension
|
16
|
+
|
17
|
+
gem 'dynamic_sitemaps', :git => 'git://github.com/bzt/spree_dynamic_sitemaps.git'
|
18
|
+
bundle install
|
19
|
+
|
20
|
+
(rake dynamic_sitemaps:install)
|
21
|
+
|
22
|
+
2. Add link to sitemap to a view
|
23
|
+
|
24
|
+
`<%= link_to 'Sitemap', '/sitemap' %>`
|
25
|
+
|
26
|
+
The sitemaps are accessible at public_domain/sitemap.html, public_domain/sitemap.xml, and public_domain/sitemap.txt
|
27
|
+
|
28
|
+
Hat tip [stephp][2] for doing all the heavy lifting with her [spree-sitemaps][3] extension.
|
29
|
+
|
30
|
+
[1]: http://ext.spreecommerce.com/extensions/2-static-content
|
31
|
+
[2]: http://github.com/stephp
|
32
|
+
[3]: http://ext.spreecommerce.com/extensions/3-spree-sitemaps
|
data/Rakefile
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
# I think this is the one that should be moved to the extension Rakefile template
|
2
|
+
|
3
|
+
# In rails 1.2, plugins aren't available in the path until they're loaded.
|
4
|
+
# Check to see if the rspec plugin is installed first and require
|
5
|
+
# it if it is. If not, use the gem version.
|
6
|
+
|
7
|
+
# Determine where the RSpec plugin is by loading the boot
|
8
|
+
unless defined? SPREE_ROOT
|
9
|
+
ENV["RAILS_ENV"] = "test"
|
10
|
+
case
|
11
|
+
when ENV["SPREE_ENV_FILE"]
|
12
|
+
require File.dirname(ENV["SPREE_ENV_FILE"]) + "/boot"
|
13
|
+
when File.dirname(__FILE__) =~ %r{vendor/SPREE/vendor/extensions}
|
14
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
|
15
|
+
else
|
16
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake'
|
21
|
+
require 'rake/rdoctask'
|
22
|
+
require 'rake/testtask'
|
23
|
+
|
24
|
+
rspec_base = File.expand_path(SPREE_ROOT + '/vendor/plugins/rspec/lib')
|
25
|
+
$LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
|
26
|
+
require 'spec/rake/spectask'
|
27
|
+
# require 'spec/translator'
|
28
|
+
|
29
|
+
# Cleanup the SPREE_ROOT constant so specs will load the environment
|
30
|
+
Object.send(:remove_const, :SPREE_ROOT)
|
31
|
+
|
32
|
+
extension_root = File.expand_path(File.dirname(__FILE__))
|
33
|
+
|
34
|
+
task :default => :spec
|
35
|
+
task :stats => "spec:statsetup"
|
36
|
+
|
37
|
+
desc "Run all specs in spec directory"
|
38
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
39
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
40
|
+
t.spec_files = FileList["#{extension_root}/spec/**/*_spec.rb"]
|
41
|
+
end
|
42
|
+
|
43
|
+
namespace :spec do
|
44
|
+
desc "Run all specs in spec directory with RCov"
|
45
|
+
Spec::Rake::SpecTask.new(:rcov) do |t|
|
46
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
47
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
48
|
+
t.rcov = true
|
49
|
+
t.rcov_opts = ['--exclude', 'spec', '--rails']
|
50
|
+
end
|
51
|
+
|
52
|
+
desc "Print Specdoc for all specs"
|
53
|
+
Spec::Rake::SpecTask.new(:doc) do |t|
|
54
|
+
t.spec_opts = ["--format", "specdoc", "--dry-run"]
|
55
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
56
|
+
end
|
57
|
+
|
58
|
+
[:models, :controllers, :views, :helpers].each do |sub|
|
59
|
+
desc "Run the specs under spec/#{sub}"
|
60
|
+
Spec::Rake::SpecTask.new(sub) do |t|
|
61
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
62
|
+
t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Hopefully no one has written their extensions in pre-0.9 style
|
67
|
+
# desc "Translate specs from pre-0.9 to 0.9 style"
|
68
|
+
# task :translate do
|
69
|
+
# translator = ::Spec::Translator.new
|
70
|
+
# dir = RAILS_ROOT + '/spec'
|
71
|
+
# translator.translate(dir, dir)
|
72
|
+
# end
|
73
|
+
|
74
|
+
# Setup specs for stats
|
75
|
+
task :statsetup do
|
76
|
+
require 'code_statistics'
|
77
|
+
::STATS_DIRECTORIES << %w(Model\ specs spec/models)
|
78
|
+
::STATS_DIRECTORIES << %w(View\ specs spec/views)
|
79
|
+
::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
|
80
|
+
::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
|
81
|
+
::CodeStatistics::TEST_TYPES << "Model specs"
|
82
|
+
::CodeStatistics::TEST_TYPES << "View specs"
|
83
|
+
::CodeStatistics::TEST_TYPES << "Controller specs"
|
84
|
+
::CodeStatistics::TEST_TYPES << "Helper specs"
|
85
|
+
::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
|
86
|
+
end
|
87
|
+
|
88
|
+
namespace :db do
|
89
|
+
namespace :fixtures do
|
90
|
+
desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
|
91
|
+
task :load => :environment do
|
92
|
+
require 'active_record/fixtures'
|
93
|
+
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
|
94
|
+
(ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
|
95
|
+
Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
desc 'Generate documentation for the sitemaps extension.'
|
103
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
104
|
+
rdoc.rdoc_dir = 'rdoc'
|
105
|
+
rdoc.title = 'SpreeSitemapsExtension'
|
106
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
107
|
+
rdoc.rdoc_files.include('README')
|
108
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
109
|
+
end
|
110
|
+
|
111
|
+
# For extensions that are in transition
|
112
|
+
desc 'Test the sitemaps extension.'
|
113
|
+
Rake::TestTask.new(:test) do |t|
|
114
|
+
t.libs << 'lib'
|
115
|
+
t.pattern = 'test/**/*_test.rb'
|
116
|
+
t.verbose = true
|
117
|
+
end
|
118
|
+
|
119
|
+
# Load any custom rakefiles for extension
|
120
|
+
Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
|
@@ -0,0 +1,99 @@
|
|
1
|
+
class SitemapController < Spree::BaseController
|
2
|
+
def index
|
3
|
+
@public_dir = root_url
|
4
|
+
|
5
|
+
@products = Product.active.find(:all)
|
6
|
+
@taxonomies = Taxonomy.all
|
7
|
+
|
8
|
+
# Get Pages from static_content extension
|
9
|
+
@pages = _select_static_pages
|
10
|
+
|
11
|
+
respond_to do |format|
|
12
|
+
format.html { }
|
13
|
+
format.xml do
|
14
|
+
nav = _build_taxon_hash
|
15
|
+
nav = _build_pages_hash nav
|
16
|
+
nav = _add_products_to_tax nav, false
|
17
|
+
render :layout => false, :xml => _build_xml(nav, @public_dir)
|
18
|
+
end
|
19
|
+
format.text do
|
20
|
+
@nav = _add_products_to_tax(_build_taxon_hash, false)
|
21
|
+
render :layout => false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
def _build_xml(nav, public_dir)
|
28
|
+
returning '' do |output|
|
29
|
+
xml = Builder::XmlMarkup.new(:target => output, :indent => 2)
|
30
|
+
xml.instruct! :xml, :version => "1.0", :encoding => "UTF-8"
|
31
|
+
xml.urlset( :xmlns => "http://www.sitemaps.org/schemas/sitemap/0.9" ) {
|
32
|
+
xml.url {
|
33
|
+
xml.loc public_dir
|
34
|
+
xml.lastmod Date.today
|
35
|
+
xml.changefreq 'daily'
|
36
|
+
xml.priority '1.0'
|
37
|
+
}
|
38
|
+
nav.each do |k, v|
|
39
|
+
xml.url {
|
40
|
+
xml.loc public_dir + v['link']
|
41
|
+
xml.lastmod v['updated'].xmlschema #change timestamp of last modified
|
42
|
+
xml.changefreq 'weekly'
|
43
|
+
xml.priority '0.8'
|
44
|
+
}
|
45
|
+
end
|
46
|
+
}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def _build_taxon_hash
|
51
|
+
nav = Hash.new
|
52
|
+
Taxon.find(:all).each do |taxon|
|
53
|
+
tinfo = Hash.new
|
54
|
+
tinfo['name'] = taxon.name
|
55
|
+
tinfo['depth'] = taxon.permalink.split('/').size
|
56
|
+
tinfo['link'] = 't/' + taxon.permalink
|
57
|
+
tinfo['updated'] = taxon.updated_at
|
58
|
+
nav[taxon.permalink] = tinfo
|
59
|
+
end
|
60
|
+
nav
|
61
|
+
end
|
62
|
+
|
63
|
+
def _add_products_to_tax(nav, multiples_allowed)
|
64
|
+
Product.active.find(:all).each do |product|
|
65
|
+
pinfo = Hash.new
|
66
|
+
pinfo['name'] = product.name
|
67
|
+
pinfo['link'] = 'products/' + product.permalink # primary
|
68
|
+
pinfo['updated'] = product.updated_at
|
69
|
+
|
70
|
+
nav[pinfo['link']] = pinfo # store primary
|
71
|
+
end
|
72
|
+
nav
|
73
|
+
end
|
74
|
+
|
75
|
+
def _build_pages_hash(nav)
|
76
|
+
return nav if @pages.empty?
|
77
|
+
|
78
|
+
@pages.each do |page|
|
79
|
+
nav[page.slug] = {'name' => page.title,
|
80
|
+
'link' => page.slug.gsub(/^\//, ''),
|
81
|
+
'updated' => page.updated_at}
|
82
|
+
end
|
83
|
+
nav
|
84
|
+
end
|
85
|
+
|
86
|
+
def _select_static_pages
|
87
|
+
pages = []
|
88
|
+
begin
|
89
|
+
slugs_to_reject = ["/on-main-page"]
|
90
|
+
Page.visible.each do |page|
|
91
|
+
pages << page unless slugs_to_reject.include?(page.slug)
|
92
|
+
end
|
93
|
+
|
94
|
+
rescue NameError
|
95
|
+
pages = []
|
96
|
+
end
|
97
|
+
pages
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<h1>Sitemap</h1>
|
2
|
+
<%= link_to Spree::Config[:site_name], @public_dir %><br />
|
3
|
+
<% unless @pages.blank? %>
|
4
|
+
<ul>
|
5
|
+
<% @pages.each do |page| %>
|
6
|
+
<li><%= link_to page.title, @public_dir + page.slug %></li>
|
7
|
+
<% end %>
|
8
|
+
</ul>
|
9
|
+
<% end %>
|
10
|
+
<% unless @taxonomies.blank? %>
|
11
|
+
<% @taxonomies.each do |taxonomy| %>
|
12
|
+
<% taxons = Taxon.find_all_by_taxonomy_id(taxonomy.id) %>
|
13
|
+
<h3><%= taxonomy.name %></h3>
|
14
|
+
<ul>
|
15
|
+
<% taxons.each do |taxon| %>
|
16
|
+
<% unless taxon.name == taxonomy.name %><li><%= link_to taxon.name, @public_dir + taxon.permalink %></li><% end %>
|
17
|
+
<% end %>
|
18
|
+
</ul>
|
19
|
+
<% end %>
|
20
|
+
|
21
|
+
<% end %>
|
22
|
+
<% unless @products.blank? %>
|
23
|
+
<h3>Products</h3>
|
24
|
+
<ul>
|
25
|
+
<% @products.each do |product| %>
|
26
|
+
<li><%= link_to product.name, @public_dir + "products/" + product.permalink %></li>
|
27
|
+
<% end %>
|
28
|
+
</ul>
|
29
|
+
<% end %>
|
File without changes
|
data/config/routes.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spree_core'
|
2
|
+
|
3
|
+
module DynamicSitemaps
|
4
|
+
class Engine < Rails::Engine
|
5
|
+
|
6
|
+
config.autoload_paths += %W(#{config.root}/lib)
|
7
|
+
|
8
|
+
def self.activate
|
9
|
+
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
|
10
|
+
Rails.env.production? ? require(c) : load(c)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
config.to_prepare &method(:activate).to_proc
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
namespace :db do
|
2
|
+
desc "Bootstrap your database for Spree."
|
3
|
+
task :bootstrap => :environment do
|
4
|
+
# load initial database fixtures (in db/sample/*.yml) into the current environment's database
|
5
|
+
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
|
6
|
+
Dir.glob(File.join(DynamicSitemaps.root, "db", 'sample', '*.{yml,csv}')).each do |fixture_file|
|
7
|
+
Fixtures.create_fixtures("#{DynamicSitemaps.root}/db/sample", File.basename(fixture_file, '.*'))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
namespace :dynamic_sitemaps do
|
2
|
+
desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
|
3
|
+
task :install do
|
4
|
+
Rake::Task['dynamic_sitemaps:install:migrations'].invoke
|
5
|
+
Rake::Task['dynamic_sitemaps:install:assets'].invoke
|
6
|
+
end
|
7
|
+
|
8
|
+
namespace :install do
|
9
|
+
desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
|
10
|
+
task :migrations do
|
11
|
+
source = File.join(File.dirname(__FILE__), '..', '..', 'db')
|
12
|
+
destination = File.join(Rails.root, 'db')
|
13
|
+
puts "INFO: Mirroring assets from #{source} to #{destination}"
|
14
|
+
Spree::FileUtilz.mirror_files(source, destination)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
|
18
|
+
task :assets do
|
19
|
+
source = File.join(File.dirname(__FILE__), '..', '..', 'public')
|
20
|
+
destination = File.join(Rails.root, 'public')
|
21
|
+
puts "INFO: Mirroring assets from #{source} to #{destination}"
|
22
|
+
Spree::FileUtilz.mirror_files(source, destination)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.platform = Gem::Platform::RUBY
|
3
|
+
s.name = 'spree_dynamic_sitemaps'
|
4
|
+
s.version = '0.50.0'
|
5
|
+
s.summary = 'Google sitemap for Spree stores'
|
6
|
+
#s.description = 'Add (optional) gem description here'
|
7
|
+
s.required_ruby_version = '>= 1.8.7'
|
8
|
+
|
9
|
+
s.author = 'bzt'
|
10
|
+
# s.email = ''
|
11
|
+
# s.homepage = ''
|
12
|
+
# s.rubyforge_project = ''
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.require_path = 'lib'
|
17
|
+
s.requirements << 'none'
|
18
|
+
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spree_dynamic_sitemaps
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 50
|
8
|
+
- 0
|
9
|
+
version: 0.50.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- bzt
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-05-01 00:00:00 +04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description:
|
22
|
+
email:
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- README.markdown
|
31
|
+
- Rakefile
|
32
|
+
- app/controllers/sitemap_controller.rb
|
33
|
+
- app/helpers/sitemap_helper.rb
|
34
|
+
- app/views/sitemap/index.html.erb
|
35
|
+
- app/views/sitemap/index.text.erb
|
36
|
+
- app/views/sitemap/index.xml.builder
|
37
|
+
- config/routes.rb
|
38
|
+
- lib/dynamic_sitemaps.rb
|
39
|
+
- lib/tasks/dynamic_sitemaps.rake
|
40
|
+
- lib/tasks/install.rake
|
41
|
+
- spree_dynamic_sitemaps.gemspec
|
42
|
+
has_rdoc: true
|
43
|
+
homepage:
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 1
|
57
|
+
- 8
|
58
|
+
- 7
|
59
|
+
version: 1.8.7
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
version: "0"
|
67
|
+
requirements:
|
68
|
+
- none
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.3.6
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: Google sitemap for Spree stores
|
74
|
+
test_files: []
|
75
|
+
|