Class RuGPost::Post
In: lib/rugpost/post.rb
Parent: Object

Methods

draft   get_site   move_html   move_source   new   publish   remove   set_body   set_html   set_meta   set_subj  

Attributes

draft  [RW] 
html_o  [RW] 
metaops  [RW] 
pwd  [RW] 
src_body  [RW] 
subject  [RW] 

Public Class methods

[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

[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

[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

[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

[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

[Source]

# File lib/rugpost/post.rb, line 49
                def move_source
                        FileUtils.mv(@draft,@metaops[:site]/SOURCE)
                end

[Source]

# File lib/rugpost/post.rb, line 58
                def remove
                        FileUtils.remove_file(@draft)
                end

[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

[Source]

# File lib/rugpost/post.rb, line 45
                def set_html
                        @html_o = RedCloth.new(@src_body).to_html            
                end

[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

[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

[Validate]