Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit.

  • Loading branch information...
commit 7e855c68196a62af4c6cd467f247f7bac462457a 0 parents
Daniel Mircea authored
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2011 Daniel Mircea, The Geeks
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
14 README.rdoc
@@ -0,0 +1,14 @@
+= Sitemap
+
+A simple ruby on rails sitemap generator
+
+
+== Usage
+
+TODO
+
+
+== License
+
+This package is licensed under the MIT license and/or the Creative
+Commons Attribution-ShareAlike.
27 Rakefile
@@ -0,0 +1,27 @@
+require 'rake/rdoctask'
+
+
+spec = Gem::Specification.load(File.expand_path("sitemap.gemspec", File.dirname(__FILE__)))
+
+# Create the documentation.
+Rake::RDocTask.new do |rdoc|
+ rdoc.rdoc_files.include "README.rdoc", "lib/**/*.rb"
+ rdoc.options = spec.rdoc_options
+end
+
+desc "Push new release to rubyforge and git tag"
+task :push do
+ sh "git push"
+ puts "Tagging version #{spec.version} .."
+ sh "git tag v#{spec.version}"
+ sh "git push --tag"
+ puts "Building and pushing gem .."
+ sh "gem build #{spec.name}.gemspec"
+ sh "gem push #{spec.name}-#{spec.version}.gem"
+end
+
+desc "Install #{spec.name} locally"
+task :install do
+ sh "gem build #{spec.name}.gemspec"
+ sh "gem install #{spec.name}-#{spec.version}.gem"
+end
67 lib/sitemap.rb
@@ -0,0 +1,67 @@
+#
+# = sitemap.rb - Sitemap
+#
+# Author:: Daniel Mircea daniel@viseztrance.com
+# Copyright:: Copyright (c) 2011 Daniel Mircea, The Geeks
+# License:: MIT and/or Creative Commons Attribution-ShareAlike
+
+gem "builder", "~> 2.1.2"
+
+require "singleton"
+require "builder"
+
+class Sitemap
+
+ include Singleton
+ include Rails.application.routes.url_helpers
+
+ VERSION = Gem::Specification.load(File.expand_path("../sitemap.gemspec", File.dirname(__FILE__))).version.to_s
+
+ attr_accessor :entries, :host
+
+ def initialize
+ self.entries = []
+ end
+
+ def render(options = {}, &block)
+ options.each do |k, v|
+ self.send("#{k}=", v)
+ end
+ instance_exec(self, &block)
+ end
+
+ def path(object, options = {})
+ self.entries << {
+ :object => object,
+ :options => options.reject { |k, v| k == :host },
+ :host => options[:host]
+ }
+ end
+
+ def collection(type, options = {})
+ objects = options[:objects] ? options[:objects].call : type.to_s.classify.constantize.all
+ objects.each do |object|
+ path(object, options.reject { |k, v| k == :objects })
+ end
+ end
+
+ def build
+ xml = Builder::XmlMarkup.new(:indent => 2)
+ file = File.read(File.expand_path("../views/index.xml.builder", __FILE__))
+ instance_eval file
+ end
+
+ def save(location)
+ file = File.new(location, "w")
+ file.write(build)
+ file.close
+ end
+
+ def get_url(entry)
+ options = {
+ :host => entry[:host] ? entry[:host].call(entry[:object]) : host
+ }
+ polymorphic_url(entry[:object], options)
+ end
+
+end
15 lib/views/index.xml.builder
@@ -0,0 +1,15 @@
+xml.instruct!
+xml.urlset :xmlns => "http://www.sitemaps.org/schemas/sitemap/0.9" do
+
+ entries.each do |entry|
+ xml.url do
+ xml.url get_url(entry)
+ xml.lastmod entry[:object].updated_at.strftime("%Y-%m-%d") unless entry[:object].is_a?(Symbol)
+ entry[:options].each do |type, value|
+ xml.tag! type, value.to_s
+ end
+ end
+ end
+
+end
+
17 sitemap.gemspec
@@ -0,0 +1,17 @@
+spec = Gem::Specification.new do |spec|
+ spec.name = "sitemap"
+ spec.version = "0.0.1"
+ spec.summary = "Sitemap"
+ spec.description = "A simple ruby on rails sitemap generator"
+
+ spec.authors << "Daniel Mircea"
+ spec.email = "daniel@viseztrance.com"
+ spec.homepage = "http://github.com/viseztrance/sitemap"
+
+ spec.files = Dir["{bin,lib,docs}/**/*"] + ["README.rdoc", "LICENSE", "Rakefile", "sitemap.gemspec"]
+
+ spec.has_rdoc = true
+ spec.rdoc_options << "--main" << "README.rdoc" << "--title" << "Sitemap" << "--line-numbers"
+ "--webcvs" << "http://github.com/viseztrance/sitemap"
+ spec.extra_rdoc_files = ["README.rdoc", "LICENSE"]
+end
Please sign in to comment.
Something went wrong with that request. Please try again.