Sha256: cad2d68953385caa41234ae09a2e8288a70e3fea4fcdf209e0a355b0b7e37703

Contents?: true

Size: 787 Bytes

Versions: 1

Compression:

Stored size: 787 Bytes

Contents

module Middleman::Features::SitemapTree
  class << self
    def registered(app)
      app.helpers Helpers
    end
    alias :included :registered
  end
  
  module Helpers
    def sitemap_tree(regex=nil)
      @sitemap_tree_cache = {}
      
      key = regex.nil? ? "all" : regex
      
      if !@sitemap_tree_cache.has_key?(key)
        auto_hash = Hash.new{ |h,k| h[k] = Hash.new &h.default_proc }

        app.sitemap.all_paths.each do |path|
          next if !regex.nil? && !path.match(regex)
          sub = auto_hash
          path.split( "/" ).each{ |dir| sub[dir]; sub = sub[dir] }
        end
      
        @sitemap_tree_cache[key] = auto_hash
      end
      
      @sitemap_tree_cache[key]
    end
    
    def html_sitemap
      sitemap_tree(/\.html$/)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
middleman-3.0.0.alpha.2 lib/middleman/features/sitemap_tree.rb