class RuGPost::Post
Attributes
draft[RW]
html_o[RW]
metaops[RW]
pwd[RW]
src_body[RW]
subject[RW]
Public Class Methods
draft(args,ops)
click to toggle source
# File lib/rugpost/post.rb, line 62 def Post.draft(args,ops) ops[:site]=Post.get_site(ops) raise "Please provide draft name!" if !args[0] target_file = ops[:site]/'drafts'/args[0]+'.textile' puts "Adding draft '#{args[0]}' to site repo '#{ops[:site]}'..." raise "File already exists!\n\t#{target_file}\n\tPlease indicate a different draft name." if File.exists?(target_file) FileUtils.copy_file(TEMPLATE, target_file) end
get_site(ops)
click to toggle source
# File lib/rugpost/post.rb, line 86 def Post.get_site(ops) if ops[:site]==nil then ops[:site]=Dir.glob('*').select {|d| File.directory? d}[0] puts "No site name option provided, switching to default...'#{ops[:site]}'" end return ops[:site] end
new(args,ops)
click to toggle source
# File lib/rugpost/post.rb, line 14 def initialize(args,ops) ops[:site]=Post.get_site(ops) @draftid = args[0] @pwd = args[1] @draft = Dir.glob(ops[:site]/DRAFTS/@draftid+".*") raise "Draft not found! Searched for '#{args[0]}' in '#{ops[:site]}/drafts'" unless @draft @draft = @draft[0] set_body set_html set_meta ops set_subj end
publish(post)
click to toggle source
# File lib/rugpost/post.rb, line 71 def Post.publish(post) account = "#{post.metaops[:gmail]}@gmail.com" gmail = Gmail.new(account,post.pwd) gmail.deliver do to "#{post.metaops[:site]}@posterous.com" subject post.subject text_part do body post.html_o end end gmail.logout post.move_source post.move_html end
Public Instance Methods
move_html()
click to toggle source
# File lib/rugpost/post.rb, line 53 def move_html target = @metaops[:site]/OUTPUT/@draftid+'.html' File.open( target, 'w' ) {|f| f.write(@html_o)} end
move_source()
click to toggle source
# File lib/rugpost/post.rb, line 49 def move_source FileUtils.mv(@draft,@metaops[:site]/SOURCE) end
remove()
click to toggle source
# File lib/rugpost/post.rb, line 58 def remove FileUtils.remove_file(@draft) end
set_body()
click to toggle source
# File lib/rugpost/post.rb, line 39 def set_body cnt = "" File.open( @draft, 'r' ) { |str| cnt << str.read() } @src_body = cnt.sub META, "" end
set_html()
click to toggle source
# File lib/rugpost/post.rb, line 45 def set_html @html_o = RedCloth.new(@src_body).to_html end
set_meta(ops)
click to toggle source
# File lib/rugpost/post.rb, line 27 def set_meta ops projectops = YAML.load_file(CONFIG) @metaops = YAML.load_file(@draft) @metaops.merge! projectops @metaops.merge! ops end
set_subj()
click to toggle source
# File lib/rugpost/post.rb, line 34 def set_subj @subject = "#{@metaops[:title]} ((tags:#{@metaops[:tags].join(',')}))" @subject += "((delay:#{@metaops[:delay]}))" if @metaops[:delay] end