ssoroka-ruby_textmate 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +3 -0
- data/README +35 -0
- data/Rakefile +1 -1
- data/init.rb +2 -0
- data/lib/ruby_textmate.rb +48 -22
- data/ruby_textmate.gemspec +6 -5
- data/test/ruby_textmate_test.rb +27 -0
- metadata +10 -4
data/Manifest
CHANGED
data/README
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
= Ruby Textmate
|
2
|
+
|
3
|
+
A ruby interface to passing text to textmate. This is not necessarily an api for textmate as much as an easy way to interface with it from code and pass it text.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
sudo gem install ssoroka-ruby_textmate
|
8
|
+
|
9
|
+
or to install it as plugin:
|
10
|
+
|
11
|
+
script/plugin install git://github.com/ssoroka/ruby_textmate.git
|
12
|
+
|
13
|
+
== Usage
|
14
|
+
|
15
|
+
RubyTextmate.open_text("blah blah blah", options)
|
16
|
+
RubyTextmate.open_file('~/.bash_login', options)
|
17
|
+
RubyTextmate.open_url("http://gist.github.com/raw/24825/64ab18a92caa7329a36cfbe68671a8cc10acc225", options)
|
18
|
+
|
19
|
+
and this one is interesting...
|
20
|
+
|
21
|
+
RubyTextmate.with_tempfile('some text') #=> opens textmate with a temp file having contents of 'some text', method returns temp file contents when the user saves and closes textmate, and deletes the temp file for you.
|
22
|
+
|
23
|
+
or try your luck with:
|
24
|
+
|
25
|
+
RubyTextmate.open()
|
26
|
+
|
27
|
+
and it'll try to guess what you're attempting to open and call the right method for you.
|
28
|
+
|
29
|
+
acceptable options are:
|
30
|
+
:async Do not wait for file to be closed by TextMate (default).
|
31
|
+
:wait Wait for file to be closed by TextMate.
|
32
|
+
:line => <number> Place caret on line <number> after loading file.
|
33
|
+
:recent Add file to Open Recent menu.
|
34
|
+
:change_dir Change TextMates working directory to that of the file (only for open_file).
|
35
|
+
:no_reactivation After edit :wait, do not re-activate the calling app (may not work).
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('ruby_textmate', '0.
|
5
|
+
Echoe.new('ruby_textmate', '1.0.0') do |p|
|
6
6
|
p.description = 'a ruby interface to textmate'
|
7
7
|
p.url = 'http://github.com/ssoroka/ruby_textmate'
|
8
8
|
p.author = 'Steven Soroka'
|
data/init.rb
ADDED
data/lib/ruby_textmate.rb
CHANGED
@@ -1,41 +1,67 @@
|
|
1
1
|
require 'tempfile'
|
2
|
+
require 'net/http'
|
3
|
+
require 'net/https'
|
4
|
+
require 'net/ftp'
|
5
|
+
require 'open-uri'
|
6
|
+
require 'open3'
|
7
|
+
|
2
8
|
class RubyTextmate
|
3
9
|
class <<self
|
4
10
|
def open(thing, options = {})
|
5
|
-
if thing
|
6
|
-
|
7
|
-
|
8
|
-
|
11
|
+
if thing
|
12
|
+
if thing =~ /^http\:\/\//i
|
13
|
+
open_url(thing, options)
|
14
|
+
elsif thing !~ /[\s]/ && File.exist?(thing)
|
15
|
+
open_file(thing, options)
|
16
|
+
else
|
17
|
+
open_text(thing, options)
|
18
|
+
end
|
9
19
|
end
|
10
20
|
end
|
11
21
|
|
12
|
-
# acceptable options are:
|
13
|
-
# :async Do not wait for file to be closed by TextMate.
|
14
|
-
# :wait Wait for file to be closed by TextMate.
|
15
|
-
# :line => <number> Place caret on line <number> after loading file.
|
16
|
-
# :recent Add file to Open Recent menu.
|
17
|
-
# :change_dir Change TextMates working directory to that of the file.
|
18
|
-
# :no_reactivation After edit :wait, do not re-activate the calling app.
|
19
22
|
def open_file(filename, options = {})
|
20
|
-
mate_options =
|
21
|
-
mate_options << '-w' if options[:wait]
|
22
|
-
mate_options << '-a' if options[:async]
|
23
|
-
mate_options << "-l #{options[:line]}" if options[:line]
|
24
|
-
mate_options << '-r' if options[:recent]
|
25
|
-
mate_options << '-d' if options[:change_dir]
|
26
|
-
mate_options << '-n' if options[:no_reactivation]
|
23
|
+
mate_options = build_mate_options(options)
|
27
24
|
mate_options << filename
|
28
25
|
system("mate", *mate_options)
|
29
26
|
end
|
30
27
|
|
31
|
-
def
|
28
|
+
def with_tempfile(init_text, options = {})
|
32
29
|
t = Tempfile.open('textmate')
|
33
30
|
filename = t.path
|
34
|
-
t.write(
|
31
|
+
t.write(init_text)
|
32
|
+
t.close
|
33
|
+
open_file(filename, options.merge(:wait => true))
|
34
|
+
t.open
|
35
|
+
result = t.read
|
35
36
|
t.close
|
36
|
-
open_file(filename, options)
|
37
37
|
t.delete
|
38
|
-
|
38
|
+
result
|
39
|
+
end
|
40
|
+
|
41
|
+
def open_text(text, options = {})
|
42
|
+
Open3.popen3("mate #{build_mate_options(options).join(' ')}") do |stdin, stdout, stderr|
|
43
|
+
stdin.write(text)
|
44
|
+
stdin.close_write
|
45
|
+
stdout.read if options[:wait]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def open_url(url, options = {})
|
50
|
+
Kernel.open(url) do |f|
|
51
|
+
open_text(f.read, options)
|
52
|
+
end
|
39
53
|
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def build_mate_options(options)
|
57
|
+
mate_options = []
|
58
|
+
mate_options << '-w' if options[:wait]
|
59
|
+
mate_options << '-a' if options[:async]
|
60
|
+
mate_options << "-l #{options[:line]}" if options[:line]
|
61
|
+
mate_options << '-r' if options[:recent]
|
62
|
+
mate_options << '-d' if options[:change_dir]
|
63
|
+
mate_options << '-n' if options[:no_reactivation]
|
64
|
+
mate_options
|
65
|
+
end
|
40
66
|
end
|
41
67
|
end
|
data/ruby_textmate.gemspec
CHANGED
@@ -2,22 +2,23 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{ruby_textmate}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "1.0.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Steven Soroka"]
|
9
|
-
s.date = %q{2008-12-
|
9
|
+
s.date = %q{2008-12-18}
|
10
10
|
s.description = %q{a ruby interface to textmate}
|
11
11
|
s.email = %q{ssoroka78@gmail.com}
|
12
|
-
s.extra_rdoc_files = ["lib/ruby_textmate.rb"]
|
13
|
-
s.files = ["lib/ruby_textmate.rb", "Manifest", "Rakefile", "ruby_textmate.gemspec"]
|
12
|
+
s.extra_rdoc_files = ["lib/ruby_textmate.rb", "README"]
|
13
|
+
s.files = ["init.rb", "lib/ruby_textmate.rb", "Manifest", "Rakefile", "README", "ruby_textmate.gemspec", "test/ruby_textmate_test.rb"]
|
14
14
|
s.has_rdoc = true
|
15
15
|
s.homepage = %q{http://github.com/ssoroka/ruby_textmate}
|
16
|
-
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Ruby_textmate"]
|
16
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Ruby_textmate", "--main", "README"]
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
s.rubyforge_project = %q{ruby_textmate}
|
19
19
|
s.rubygems_version = %q{1.3.1}
|
20
20
|
s.summary = %q{a ruby interface to textmate}
|
21
|
+
s.test_files = ["test/ruby_textmate_test.rb"]
|
21
22
|
|
22
23
|
if s.respond_to? :specification_version then
|
23
24
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
|
3
|
+
require "ruby_textmate"
|
4
|
+
|
5
|
+
class TestRubyTextmate < Test::Unit::TestCase
|
6
|
+
def test_passing_textmate_a_file
|
7
|
+
RubyTextmate.open_file(File.join(File.dirname(__FILE__), %w(.. README)), :wait => true)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_passing_textmate_some_text
|
11
|
+
text = <<-TEXT
|
12
|
+
This is some
|
13
|
+
multi-line text that I expect
|
14
|
+
\ttextmate\nto handle.
|
15
|
+
TEXT
|
16
|
+
RubyTextmate.open_text(text, :wait => true)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_open_url
|
20
|
+
RubyTextmate.open_url('http://gist.github.com/raw/24825/64ab18a92caa7329a36cfbe68671a8cc10acc225', :wait => true)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_with_tempfile
|
24
|
+
# wait is implied
|
25
|
+
assert_equal RubyTextmate.with_tempfile("delete this line and save or the test will fail.\nbut leave this one"), 'but leave this one'
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ssoroka-ruby_textmate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Soroka
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-12-
|
12
|
+
date: 2008-12-18 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -21,11 +21,15 @@ extensions: []
|
|
21
21
|
|
22
22
|
extra_rdoc_files:
|
23
23
|
- lib/ruby_textmate.rb
|
24
|
+
- README
|
24
25
|
files:
|
26
|
+
- init.rb
|
25
27
|
- lib/ruby_textmate.rb
|
26
28
|
- Manifest
|
27
29
|
- Rakefile
|
30
|
+
- README
|
28
31
|
- ruby_textmate.gemspec
|
32
|
+
- test/ruby_textmate_test.rb
|
29
33
|
has_rdoc: true
|
30
34
|
homepage: http://github.com/ssoroka/ruby_textmate
|
31
35
|
post_install_message:
|
@@ -34,6 +38,8 @@ rdoc_options:
|
|
34
38
|
- --inline-source
|
35
39
|
- --title
|
36
40
|
- Ruby_textmate
|
41
|
+
- --main
|
42
|
+
- README
|
37
43
|
require_paths:
|
38
44
|
- lib
|
39
45
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -55,5 +61,5 @@ rubygems_version: 1.2.0
|
|
55
61
|
signing_key:
|
56
62
|
specification_version: 2
|
57
63
|
summary: a ruby interface to textmate
|
58
|
-
test_files:
|
59
|
-
|
64
|
+
test_files:
|
65
|
+
- test/ruby_textmate_test.rb
|