class Contraption::Repository
Attributes
formatter[R]
Public Class Methods
new(path)
click to toggle source
# File lib/contraption/repository.rb, line 9 def initialize path @path = path validate construct_locations @formatter = Formatter.new @formats_source end
Public Instance Methods
clone()
click to toggle source
# File lib/contraption/repository.rb, line 16 def clone new_path = @path.cd "../.tmp_#{Time.now.to_i}" `cp -r #{@path.path}/* #{new_path.path}` Repository.new new_path end
completed_drafts()
click to toggle source
# File lib/contraption/repository.rb, line 57 def completed_drafts drafts.map{|draft| [draft, @drafts_source.read(draft)]} .each_with_object([]) do |draft, result| result << draft.first if Post.build(draft.last).new? end end
construct_locations()
click to toggle source
# File lib/contraption/repository.rb, line 72 def construct_locations @drafts_source = @path.cd("drafts") @posts_source = @path.cd("posts") @formats_source = @path.cd("formats") @static_source = @path.cd("static") end
destroy()
click to toggle source
# File lib/contraption/repository.rb, line 22 def destroy @path.destroy end
drafts()
click to toggle source
# File lib/contraption/repository.rb, line 34 def drafts @drafts_source.list end
finalize_completed_drafts(link_handlers=[])
click to toggle source
# File lib/contraption/repository.rb, line 64 def finalize_completed_drafts link_handlers=[] completed_drafts.map{|draft| [draft, Post.build(@drafts_source.read(draft)).publish(link_handlers)]} .each do |filename, post| @posts_source.write post.publication_date.strftime("%Y%m%d-")+post.filename, @formatter.format(post, :raw) @drafts_source.remove filename end end
posts()
click to toggle source
# File lib/contraption/repository.rb, line 38 def posts Catalog.new( @posts_source.list.map do |p| begin Post.build(@posts_source.read p) rescue ArgumentError => e STDERR.puts "Invalid post #{p}" end end.select{|p| p.title != ''} ) end
static_file_path()
click to toggle source
# File lib/contraption/repository.rb, line 49 def static_file_path @static_source.path end
static_files()
click to toggle source
# File lib/contraption/repository.rb, line 53 def static_files @static_source.entries end
valid_layout?()
click to toggle source
# File lib/contraption/repository.rb, line 30 def valid_layout? @path.exist? and @path.list.include? "drafts" and @path.list.include? "posts" end
validate()
click to toggle source
# File lib/contraption/repository.rb, line 26 def validate raise "Invalid source directory structure in #{@path}" unless valid_layout? end