Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Initial commit.

  • Loading branch information...
commit 7e855c68196a62af4c6cd467f247f7bac462457a 0 parents
authored August 25, 2011
20  LICENSE
... ...
@@ -0,0 +1,20 @@
  1
+Copyright (c) 2011 Daniel Mircea, The Geeks
  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.
14  README.rdoc
Source Rendered
... ...
@@ -0,0 +1,14 @@
  1
+= Sitemap
  2
+
  3
+A simple ruby on rails sitemap generator
  4
+
  5
+
  6
+== Usage
  7
+
  8
+TODO
  9
+
  10
+
  11
+== License
  12
+
  13
+This package is licensed under the MIT license and/or the Creative
  14
+Commons Attribution-ShareAlike.
27  Rakefile
... ...
@@ -0,0 +1,27 @@
  1
+require 'rake/rdoctask'
  2
+
  3
+
  4
+spec = Gem::Specification.load(File.expand_path("sitemap.gemspec", File.dirname(__FILE__)))
  5
+
  6
+# Create the documentation.
  7
+Rake::RDocTask.new do |rdoc|
  8
+  rdoc.rdoc_files.include "README.rdoc", "lib/**/*.rb"
  9
+  rdoc.options = spec.rdoc_options
  10
+end
  11
+
  12
+desc "Push new release to rubyforge and git tag"
  13
+task :push do
  14
+  sh "git push"
  15
+  puts "Tagging version #{spec.version} .."
  16
+  sh "git tag v#{spec.version}"
  17
+  sh "git push --tag"
  18
+  puts "Building and pushing gem .."
  19
+  sh "gem build #{spec.name}.gemspec"
  20
+  sh "gem push #{spec.name}-#{spec.version}.gem"
  21
+end
  22
+
  23
+desc "Install #{spec.name} locally"
  24
+task :install do
  25
+  sh "gem build #{spec.name}.gemspec"
  26
+  sh "gem install #{spec.name}-#{spec.version}.gem"
  27
+end
67  lib/sitemap.rb
... ...
@@ -0,0 +1,67 @@
  1
+#
  2
+# = sitemap.rb - Sitemap
  3
+#
  4
+# Author:: Daniel Mircea daniel@viseztrance.com
  5
+# Copyright:: Copyright (c) 2011 Daniel Mircea, The Geeks
  6
+# License:: MIT and/or Creative Commons Attribution-ShareAlike
  7
+
  8
+gem "builder", "~> 2.1.2"
  9
+
  10
+require "singleton"
  11
+require "builder"
  12
+
  13
+class Sitemap
  14
+
  15
+  include Singleton
  16
+  include Rails.application.routes.url_helpers
  17
+
  18
+  VERSION = Gem::Specification.load(File.expand_path("../sitemap.gemspec", File.dirname(__FILE__))).version.to_s
  19
+
  20
+  attr_accessor :entries, :host
  21
+
  22
+  def initialize
  23
+    self.entries = []
  24
+  end
  25
+
  26
+  def render(options = {}, &block)
  27
+    options.each do |k, v|
  28
+      self.send("#{k}=", v)
  29
+    end
  30
+    instance_exec(self, &block)
  31
+  end
  32
+
  33
+  def path(object, options = {})
  34
+    self.entries << {
  35
+      :object => object,
  36
+      :options => options.reject { |k, v| k == :host },
  37
+      :host => options[:host]
  38
+    }
  39
+  end
  40
+
  41
+  def collection(type, options = {})
  42
+    objects = options[:objects] ? options[:objects].call : type.to_s.classify.constantize.all
  43
+    objects.each do |object|
  44
+      path(object, options.reject { |k, v| k == :objects })
  45
+    end
  46
+  end
  47
+
  48
+  def build
  49
+    xml = Builder::XmlMarkup.new(:indent => 2)
  50
+    file = File.read(File.expand_path("../views/index.xml.builder", __FILE__))
  51
+    instance_eval file
  52
+  end
  53
+
  54
+  def save(location)
  55
+    file = File.new(location, "w")
  56
+    file.write(build)
  57
+    file.close
  58
+  end
  59
+
  60
+  def get_url(entry)
  61
+    options = {
  62
+      :host => entry[:host] ? entry[:host].call(entry[:object]) : host
  63
+    }
  64
+    polymorphic_url(entry[:object], options)
  65
+  end
  66
+
  67
+end
15  lib/views/index.xml.builder
... ...
@@ -0,0 +1,15 @@
  1
+xml.instruct!
  2
+xml.urlset :xmlns => "http://www.sitemaps.org/schemas/sitemap/0.9" do
  3
+
  4
+  entries.each do |entry|
  5
+    xml.url do
  6
+      xml.url get_url(entry)
  7
+      xml.lastmod entry[:object].updated_at.strftime("%Y-%m-%d") unless entry[:object].is_a?(Symbol)
  8
+      entry[:options].each do |type, value|
  9
+        xml.tag! type, value.to_s
  10
+      end
  11
+    end
  12
+  end
  13
+
  14
+end
  15
+
17  sitemap.gemspec
... ...
@@ -0,0 +1,17 @@
  1
+spec = Gem::Specification.new do |spec|
  2
+  spec.name = "sitemap"
  3
+  spec.version = "0.0.1"
  4
+  spec.summary = "Sitemap"
  5
+  spec.description = "A simple ruby on rails sitemap generator"
  6
+
  7
+  spec.authors << "Daniel Mircea"
  8
+  spec.email = "daniel@viseztrance.com"
  9
+  spec.homepage = "http://github.com/viseztrance/sitemap"
  10
+
  11
+  spec.files = Dir["{bin,lib,docs}/**/*"] + ["README.rdoc", "LICENSE", "Rakefile", "sitemap.gemspec"]
  12
+
  13
+  spec.has_rdoc = true
  14
+  spec.rdoc_options << "--main" << "README.rdoc" << "--title" <<  "Sitemap" << "--line-numbers"
  15
+                       "--webcvs" << "http://github.com/viseztrance/sitemap"
  16
+  spec.extra_rdoc_files = ["README.rdoc", "LICENSE"]
  17
+end

0 notes on commit 7e855c6

Please sign in to comment.
Something went wrong with that request. Please try again.