Sha256: 93a666a8fb8f91488cc1e05b98ed1be4b522ef480342e363a996aaecac17f253

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

# automate creating pasties
%w{platform net/http flyrb}.each {|lib| require lib}
Flyrb.equip(:clipboard)

module Flyrb
  module Pastie
    def pastie(stuff_to_paste = nil)
      stuff_to_paste ||= Clipboard.read if Clipboard.available?
      # return nil unless stuff_to_paste

      pastie_url = Net::HTTP.post_form(URI.parse("http://pastie.caboo.se/pastes/create"),
                                       {"paste_parser" => "ruby",
                                        "paste[authorization]" => "burger",
                                        "paste[body]" => stuff_to_paste}).body.match(/href="([^\"]+)"/)[1]

      Clipboard.write(pastie_url) if Clipboard.available?
      
      case Platform::IMPL
      when :macosx
        Kernel.system("open #{pastie_url}")
      when :mswin
        pastie_url = pastie_url.chop if pastie_url[-1].chr == "\000"
        Kernel.system("start #{pastie_url}")
      end

      return pastie_url
    end
    alias :pst :pastie
  end
end

class Object
  include Flyrb::Pastie
end if Object.const_defined? :IRB

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
flyrb-1.0.0.c lib/flyrb/pastie.rb
flyrb-1.0.0.b lib/flyrb/pastie.rb
flyrb-1.0.0.a lib/flyrb/pastie.rb