|
@@ -7,43 +7,49 @@ module Fotos
|
|
|
|
|
|
|
|
def initialize(options)
|
|
def initialize(options)
|
|
|
@source_dir = Fotos::SourceDirectory.new(options[:source])
|
|
@source_dir = Fotos::SourceDirectory.new(options[:source])
|
|
|
|
|
+ @dest_dir = Fotos::SourceDirectory.new(options[:dest])
|
|
|
@generate_thumbnails = options[:thumbnails]
|
|
@generate_thumbnails = options[:thumbnails]
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
def call
|
|
def call
|
|
|
|
|
+ html_output = []
|
|
|
|
|
+ html_output << render_period(@source_dir.dates)
|
|
|
@source_dir.files_by_date.each do |date, assets|
|
|
@source_dir.files_by_date.each do |date, assets|
|
|
|
- puts "<h2 id=\"#{date}\">#{date} <small><a href=\"#toc\">top</a></small></h2>"
|
|
|
|
|
|
|
+ html_output << "<h2 id=\"#{date}\">#{date} <small><a href=\"#toc\">top</a></small></h2>"
|
|
|
assets.reject(&:is_thumbnail?).each do |asset|
|
|
assets.reject(&:is_thumbnail?).each do |asset|
|
|
|
if File.exist?(asset.thumbnail_path)
|
|
if File.exist?(asset.thumbnail_path)
|
|
|
- puts "<a href=\"#{asset.path}\"><img src=\"#{asset.thumbnail_path}\" /></a>"
|
|
|
|
|
|
|
+ html_output << "<a href=\"#{asset.path}\"><img src=\"#{asset.thumbnail_path}\" /></a>"
|
|
|
else
|
|
else
|
|
|
if @generate_thumbnails
|
|
if @generate_thumbnails
|
|
|
Fotos::Thumbnail.new(asset).create
|
|
Fotos::Thumbnail.new(asset).create
|
|
|
redo
|
|
redo
|
|
|
end
|
|
end
|
|
|
- puts "<a href=\"#{asset.dirname}/#{asset.file_name}\"><img src=\"#{asset.path}\" /></a>"
|
|
|
|
|
|
|
+ html_output << "<a href=\"#{asset.dirname}/#{asset.file_name}\"><img src=\"#{asset.path}\" /></a>"
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
- render_template('footer')
|
|
|
|
|
|
|
+ html_output << render_template('footer')
|
|
|
|
|
+ puts html_output.join("\n")
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
private
|
|
private
|
|
|
def render_period(dates)
|
|
def render_period(dates)
|
|
|
|
|
+ output = []
|
|
|
dates.group_by(&:year).each do |year, y_dates|
|
|
dates.group_by(&:year).each do |year, y_dates|
|
|
|
puts "<h2>#{year}</h2>"
|
|
puts "<h2>#{year}</h2>"
|
|
|
y_dates.group_by(&:month).each do |month, m_dates|
|
|
y_dates.group_by(&:month).each do |month, m_dates|
|
|
|
month_name = MONTHS[month - 1]
|
|
month_name = MONTHS[month - 1]
|
|
|
- render_template('month', month: month_name, m_dates: m_dates)
|
|
|
|
|
|
|
+ output << render_template('month', month: month_name, m_dates: m_dates)
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
+ output.join("\n")
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
def render_template(name, context = {})
|
|
def render_template(name, context = {})
|
|
|
path = Pathname.new(__FILE__).join('..', '..', '..', 'templates', "_#{name}.html.erb")
|
|
path = Pathname.new(__FILE__).join('..', '..', '..', 'templates', "_#{name}.html.erb")
|
|
|
template = ERB.new(File.read(path))
|
|
template = ERB.new(File.read(path))
|
|
|
- puts template.result_with_hash(context)
|
|
|
|
|
|
|
+ template.result_with_hash(context)
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
end
|
|
end
|