class Contraption::Site
Public Class Methods
new(location, posts, formats)
click to toggle source
# File lib/contraption/site.rb, line 6 def initialize location, posts, formats @location = location @formats = formats @posts = posts end
Public Instance Methods
build_all_individuals()
click to toggle source
# File lib/contraption/site.rb, line 12 def build_all_individuals @posts.each.to_a.each { |i| build_individual i } end
build_individual(i)
click to toggle source
# File lib/contraption/site.rb, line 16 def build_individual i post_location = @location.cd(post_path i) context = build i page = @formats.format(context, :page) post_location.write(i.filename('.html'), page) end
build_landing()
click to toggle source
# File lib/contraption/site.rb, line 41 def build_landing content = @formats.format({most_recent: @posts.most_recent.first}, :landing_page) @location.write('index.html', content) end
build_month_pages()
click to toggle source
# File lib/contraption/site.rb, line 23 def build_month_pages build_pages_by(:month) {|m| "#{m.year}/#{"%02d" % m.month}"} end
build_recent()
click to toggle source
# File lib/contraption/site.rb, line 35 def build_recent recent_posts = @posts.most_recent 8 combined_posts = build recent_posts write_as_page combined_posts, @location, 'recent.html' end
build_rss()
click to toggle source
# File lib/contraption/site.rb, line 53 def build_rss feed = RSSBuilder.new(@posts).to_rss @location.write 'rss', feed end
build_tag_cloud()
click to toggle source
# File lib/contraption/site.rb, line 46 def build_tag_cloud tag_cloud = TagCloud.new @posts content = @formats.format({content: tag_cloud.to_s}, :tag_cloud) path = @location.cd 'tags' write_as_page content, path end
build_tag_pages()
click to toggle source
# File lib/contraption/site.rb, line 31 def build_tag_pages build_pages_by(:tag) {|t| "tags/#{Tag.new(t).to_url}"} end
build_year_pages()
click to toggle source
# File lib/contraption/site.rb, line 27 def build_year_pages build_pages_by(:year) {|y| y.year.to_s} end
location()
click to toggle source
# File lib/contraption/site.rb, line 71 def location @location end
root()
click to toggle source
# File lib/contraption/site.rb, line 67 def root @location.path end
Private Instance Methods
build(collection)
click to toggle source
# File lib/contraption/site.rb, line 76 def build collection Array(collection).map {|p| @formats.format p}.join end
build_pages_by(type, &determine_path)
click to toggle source
# File lib/contraption/site.rb, line 80 def build_pages_by type, &determine_path @posts.public_send("by_#{type}".to_sym).each_pair do |key, posts| path = @location.cd determine_path.call key combined_posts = build posts intermediate_page = @formats.format({content: combined_posts, key: key}, type.to_sym) write_as_page intermediate_page, path end end
post_path(post)
click to toggle source
# File lib/contraption/site.rb, line 89 def post_path post post.publication_date.strftime('%Y') + '/' + post.publication_date.strftime('%m') end
write_as_page(content, path, name='index.html')
click to toggle source
# File lib/contraption/site.rb, line 93 def write_as_page content, path, name='index.html' page = @formats.format(content, :page) path.write(name, page) end