initial commit

This commit is contained in:
Josh Nussbaum 2011-01-06 06:19:57 -05:00
commit fbfd7b244d
13 changed files with 277 additions and 0 deletions

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
\#*
*~
.#*
.DS_Store
tmp
*.swp
spec/test_app

23
LICENSE Normal file
View File

@ -0,0 +1,23 @@
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the Rails Dog LLC nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

30
README.md Normal file
View File

@ -0,0 +1,30 @@
Spree Sitemap Generator
=====================
Spree sitemap generator is a sitemap generator based on the sitemap_generator gem http://github.com/kjvarga/sitemap_generator. It adheres to the Sitemap 0.9 protocol specification.
Installation
=======
gem install spree-sitemap-generator
Example goes here.
Setup
======
echo "public/sitemap*" >> .gitignore
Features
=====
- Notifies search engine of new sitemaps (Google, Yahoo, Ask, Bing)
- Compresses sitemaps with gzip
- Provides basic sitemap of a Spree site
- Allows you to easily add additional sitemaps for pages you add to your site
Special Thanks
=====
Copyright (c) 2010 [name of extension creator], released under the New BSD License

31
Rakefile Normal file
View File

@ -0,0 +1,31 @@
require File.expand_path('../../config/application', __FILE__)
require 'rubygems'
require 'rake'
require 'rake/testtask'
require 'rake/packagetask'
require 'rake/gempackagetask'
spec = eval(File.read('spree_sitemap_generator.gemspec'))
Rake::GemPackageTask.new(spec) do |p|
p.gem_spec = spec
end
desc "Release to gemcutter"
task :release => :package do
require 'rake/gemcutter'
Rake::Gemcutter::Tasks.new(spec).define
Rake::Task['gem:push'].invoke
end
desc "Default Task"
task :default => [ :spec ]
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new
# require 'cucumber/rake/task'
# Cucumber::Rake::Task.new do |t|
# t.cucumber_opts = %w{--format pretty}
# end

3
config/routes.rb Normal file
View File

@ -0,0 +1,3 @@
Rails.application.routes.draw do
# Add your extension routes here
end

View File

@ -0,0 +1,13 @@
module SpreeSitemapGenerator
module Generators
class InstallGenerator < Rails::Generators::Base
source_root File.expand_path("../../templates", __FILE__)
desc "Configures your Rails application for use with spree_sitemap_generator"
def copy_config
directory "config"
end
end
end
end

View File

@ -0,0 +1,31 @@
SitemapGenerator::Sitemap.add_links do |sitemap|
# Put links creation logic here.
#
# The root path '/' and sitemap index file are added automatically.
# Links are added to the Sitemap in the order they are specified.
#
# Usage: sitemap.add(path, options={})
# (default options are used if you don't specify)
#
# Defaults: :priority => 0.5, :changefreq => 'weekly',
# :lastmod => Time.now, :host => default_host
#
#
# Examples:
#
# Add '/articles'
#
# sitemap.add articles_path, :priority => 0.7, :changefreq => 'daily'
#
# Add individual articles:
#
# Article.find_each do |article|
# sitemap.add article_path(article), :lastmod => article.updated_at
# end
sitemap.add_login
sitemap.add_signup
sitemap.add_account
sitemap.add_password_reset
sitemap.add_taxons
sitemap.add_products
end

View File

@ -0,0 +1,37 @@
require 'spree_core'
require 'spree_sitemap_generator_hooks'
require 'sitemap_generator'
module SpreeSitemapGenerator
class Engine < Rails::Engine
config.autoload_paths += %W(#{config.root}/lib)
def self.activate
ActiveRecord::Relation.class_eval do
def last_updated
last_update = order('updated_at DESC').first
last_update.try(:updated_at)
end
end
ActiveRecord::Base.class_eval do
def self.last_updated
scoped.last_updated
end
end
SitemapGenerator::Sitemap.default_host = "http://#{Spree::Config[:site_url]}"
require 'spree_sitemap_generator/spree_defaults'
SitemapGenerator::LinkSet.send :include, SpreeSitemapGenerator::SpreeDefaults
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
Rails.env.production? ? require(c) : load(c)
end
end
config.to_prepare &method(:activate).to_proc
end
end

View File

@ -0,0 +1,41 @@
module SpreeSitemapGenerator::SpreeDefaults
def default_url_options
{:host => URI.parse(SitemapGenerator::Sitemap.default_host).host}
end
include ::Rails.application.routes.url_helpers
def add_login(options={})
add(login_path, options)
end
def add_signup(options={})
add(signup_path, options)
end
def add_account(options={})
add(account_path, options)
end
def add_password_reset(options={})
add(new_password_reset_path, options)
end
def add_products(options={})
active_products = Product.active
add(products_path, options.merge(:lastmod => active_products.last_updated))
active_products.each do |product|
add(product_path(product), options.merge(:lastmod => product.updated_at))
end
end
def add_taxons(options={})
Taxon.roots.each {|taxon| add_taxon(taxon, options) }
end
def add_taxon(taxon, options={})
add(nested_taxons_path(taxon.permalink), options.merge(:lastmod => taxon.products.last_updated))
taxon.children.each {|child| add_taxon(child, options) }
end
end

View File

@ -0,0 +1,3 @@
class SpreeSitemapGeneratorHooks < Spree::ThemeSupport::HookListener
# custom hooks go here
end

View File

@ -0,0 +1,5 @@
# add custom rake tasks here
desc 'test it'
task :foo do
puts 1
end

31
spec/spec_helper.rb Normal file
View File

@ -0,0 +1,31 @@
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
# from the project root directory.
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../../config/environment", __FILE__)
require 'rspec/rails'
require 'fabrication'
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
RSpec.configure do |config|
# == Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
config.mock_with :rspec
config.fixture_path = "#{::Rails.root}/spec/fixtures"
#config.include Devise::TestHelpers, :type => :controller
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, comment the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
end
@configuration ||= AppConfiguration.find_or_create_by_name("Default configuration")

View File

@ -0,0 +1,22 @@
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'spree_sitemap_generator'
s.version = '3.0.2'
s.summary = 'Add gem summary here'
#s.description = 'Add (optional) gem description here'
s.required_ruby_version = '>= 1.8.7'
# s.author = 'David Heinemeier Hansson'
# s.email = 'david@loudthinking.com'
# s.homepage = 'http://www.rubyonrails.org'
# s.rubyforge_project = 'actionmailer'
s.files = Dir['CHANGELOG', 'README.md', 'LICENSE', 'lib/**/*', 'app/**/*']
s.require_path = 'lib'
s.requirements << 'none'
s.has_rdoc = true
s.add_dependency('spree_core', '>= 0.30.1')
s.add_dependency('sitemap_generator', '>= 1.3.4')
end