Class: RubyTextmate
- Inherits:
-
Object
- Object
- RubyTextmate
- Defined in:
- lib/ruby_textmate.rb
Class Method Summary collapse
- .open(thing, options = {}) ⇒ Object
- .open_file(filename, options = {}) ⇒ Object
- .open_text(text, options = {}) ⇒ Object
- .open_url(url, options = {}) ⇒ Object
- .with_tempfile(init_text, options = {}) ⇒ Object
Class Method Details
.open(thing, options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ruby_textmate.rb', line 10 def open(thing, = {}) if thing if thing =~ /^http\:\/\//i open_url(thing, ) elsif thing !~ /[\s]/ && File.exist?(thing) open_file(thing, ) else open_text(thing, ) end end end |
.open_file(filename, options = {}) ⇒ Object
22 23 24 25 26 |
# File 'lib/ruby_textmate.rb', line 22 def open_file(filename, = {}) = () << filename system("mate", *) end |
.open_text(text, options = {}) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/ruby_textmate.rb', line 41 def open_text(text, = {}) Open3.popen3("mate #{().join(' ')}") do |stdin, stdout, stderr| stdin.write(text) stdin.close_write stdout.read if [:wait] end end |
.open_url(url, options = {}) ⇒ Object
49 50 51 52 53 |
# File 'lib/ruby_textmate.rb', line 49 def open_url(url, = {}) Kernel.open(url) do |f| open_text(f.read, ) end end |
.with_tempfile(init_text, options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ruby_textmate.rb', line 28 def with_tempfile(init_text, = {}) t = Tempfile.open('textmate') filename = t.path t.write(init_text) t.close open_file(filename, .merge(:wait => true)) t.open result = t.read t.close t.delete result end |