Class: Middleman::Thumbnailer::SitemapExtension

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman-thumbnailer/extension.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ SitemapExtension

Returns a new instance of SitemapExtension.



89
90
91
# File 'lib/middleman-thumbnailer/extension.rb', line 89

def initialize(app)
  @app = app
end

Instance Method Details

#manipulate_resource_list(resources) ⇒ Object

Add sitemap resource for every image in the sprockets load path



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/middleman-thumbnailer/extension.rb', line 94

def manipulate_resource_list(resources)

  images_dir_abs = File.join(@app.source_dir, @app.images_dir)

  images_dir = @app.images_dir

  options = Thumbnailer.options
  dimensions = options[:dimensions]
  namespace = options[:namespace_directory].join(',')

  files = DirGlob.glob(images_dir_abs, options[:namespace_directory], options[:filetypes])

  resource_list = files.map do |file|
    path = file.gsub(@app.source_dir + File::SEPARATOR, '')
    specs = ThumbnailGenerator.specs(path, dimensions)
    specs.map do |name, spec|
      resource = nil
      resource = Middleman::Sitemap::Resource.new(@app.sitemap, spec[:name], File.join(options[:build_dir], spec[:name])) unless name == :original
    end
  end.flatten.reject {|resource| resource.nil? }

  resources + resource_list
end