Class: Sitemap
- Inherits:
-
Middleman::Extension
- Object
- Middleman::Extension
- Sitemap
- Defined in:
- lib/middleman-sitemap.rb
Overview
Extension namespace
Instance Method Summary collapse
- #after_build ⇒ Object
- #gzip_file(sitemap) ⇒ Object
-
#initialize(app, options_hash = {}, &block) ⇒ Sitemap
constructor
A new instance of Sitemap.
Constructor Details
#initialize(app, options_hash = {}, &block) ⇒ Sitemap
Returns a new instance of Sitemap.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/middleman-sitemap.rb', line 9 def initialize(app, ={}, &block) # Call super to build options from the options_hash super # Require libraries only when activated # require 'necessary/library' # set up your extension # puts options.my_option end |
Instance Method Details
#after_build ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/middleman-sitemap.rb', line 20 def after_build require 'erb' @pages = app.sitemap.resources.find_all{ |p| p.source_file.match(/\.html/) } @hostname = .hostname template = Tilt::ERBTemplate.new(File.(File.join("#{File.dirname(__FILE__)}", "../templates/sitemap.xml.erb"))) sitemap = template.render(self) outfile = File.join(app.build_dir, "sitemap.xml") File.open(outfile, 'w') {|f| f.write(sitemap) } if .gzip gzip_file(File.read(outfile)) end end |
#gzip_file(sitemap) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/middleman-sitemap.rb', line 33 def gzip_file(sitemap) require 'zlib' File.open(File.join(@app.build_dir, "sitemap.xml.gz"), 'wb') do |f| gz = Zlib::GzipWriter.new(f, Zlib::BEST_COMPRESSION) gz.write sitemap gz.close end end |