Sha256: 24ad1ac1f6f8c310a1b2824bf1df4cf9f5207d830d92934fdb571e8990c5210c

Contents?: true

Size: 1.03 KB

Versions: 13

Compression:

Stored size: 1.03 KB

Contents

require_relative 'image'

module ImageSite
  class Index < Model
    def self.write_all(options)
      images = Image.all options
      indexes = all images, options
      images.each(&:write)
      indexes.each(&:write)
    end

    def self.all(images, options)
      indexes =
        images.
        each_slice(options.columns * options.rows).
        with_index(1).
        map { |images_for_index, i| Index.new(i, images_for_index, options) }
      indexes.each do |index|
        index.indexes = indexes
        index.images.each { |image| image.index = index }
      end
    end
    private_class_method :all

    def self.template_name
      'index.html.erb'
    end
    private_class_method :template_name

    attr_reader :images
    attr_accessor :indexes

    def initialize(number, images, options)
      super number, options
      @images = images
    end

    def write
      images.each(&:write_thumbnail)
      write_html index: self
    end

    def relative_html
      "index#{if @number > 1 then @number end}.html"
    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
imagesite-1.0.11 lib/image_site/index.rb
imagesite-1.0.10 lib/image_site/index.rb
imagesite-1.0.9 lib/image_site/index.rb
imagesite-1.0.8 lib/image_site/index.rb
imagesite-1.0.7 lib/image_site/index.rb
imagesite-1.0.6 lib/image_site/index.rb
imagesite-1.0.5 lib/image_site/index.rb
imagesite-1.0.4 lib/image_site/index.rb
imagesite-1.0.3 lib/image_site/index.rb
imagesite-1.0.2 lib/image_site/index.rb
imagesite-1.0.1 lib/image_site/index.rb
imagesite-1.0.0 lib/image_site/index.rb
imagesite-1.0.0.pre lib/image_site/index.rb