string_to_editor 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Tom ten Thij
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = string_to_editor
2
+
3
+ Adds an :edit method to strings which send it to the default editor
4
+ (set in ENV['EDITOR']). Mostly for debugging purposes.
5
+
6
+ == Note on Patches/Pull Requests
7
+
8
+ * Fork the project.
9
+ * Make your feature addition or bug fix.
10
+ * Add tests for it. This is important so I don't break it in a
11
+ future version unintentionally.
12
+ * Commit, do not mess with rakefile, version, or history.
13
+ (if you want to have your own version, that is fine but
14
+ bump version in a commit by itself I can ignore when I pull)
15
+ * Send me a pull request. Bonus points for topic branches.
16
+
17
+ == Copyright
18
+
19
+ Copyright (c) 2009 Tom ten Thij. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "string_to_editor"
8
+ gem.summary = %Q{Send ruby strings to your editor or a file}
9
+ gem.description = %Q{Send ruby strings to your editor or a file}
10
+ gem.email = "string_to_editor@tomtenthij.nl"
11
+ gem.homepage = "http://github.com/tomtt/string_to_editor"
12
+ gem.authors = ["Tom ten Thij"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_development_dependency "cucumber", ">= 0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ begin
37
+ require 'cucumber/rake/task'
38
+ Cucumber::Rake::Task.new(:features)
39
+
40
+ task :features => :check_dependencies
41
+ rescue LoadError
42
+ task :features do
43
+ abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
44
+ end
45
+ end
46
+
47
+ task :default => :spec
48
+
49
+ require 'rake/rdoctask'
50
+ Rake::RDocTask.new do |rdoc|
51
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
52
+
53
+ rdoc.rdoc_dir = 'rdoc'
54
+ rdoc.title = "string_to_editor #{version}"
55
+ rdoc.rdoc_files.include('README*')
56
+ rdoc.rdoc_files.include('lib/**/*.rb')
57
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,9 @@
1
+ Feature: something something
2
+ In order to something something
3
+ A user something something
4
+ something something something
5
+
6
+ Scenario: something something
7
+ Given inspiration
8
+ When I create a sweet new gem
9
+ Then everyone should see how awesome I am
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'string_to_editor'
3
+
4
+ require 'spec/expectations'
@@ -0,0 +1,24 @@
1
+ require 'tempfile'
2
+
3
+ module OpenStringInEditor
4
+ def write_to_tmp_file
5
+ return @path_of_tmp_file_for_string_to_editor if @path_of_tmp_file_for_string_to_editor
6
+ Tempfile.open('ruby_string') do |tempfile|
7
+ tempfile.puts self
8
+ @path_of_tmp_file_for_string_to_editor = tempfile.path
9
+ end
10
+ end
11
+
12
+ def edit
13
+ if ENV['EDITOR']
14
+ write_to_tmp_file
15
+ system("#{ENV['EDITOR']} #{@path_of_tmp_file_for_string_to_editor} &")
16
+ else
17
+ raise "edit was called for a String, but the EDITOR variable was not set in ENV"
18
+ end
19
+ end
20
+ end
21
+
22
+ class String
23
+ include OpenStringInEditor
24
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'string_to_editor'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
@@ -0,0 +1,73 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ require 'tempfile'
4
+ require 'string_to_editor'
5
+
6
+ describe "StringToEditor" do
7
+ before do
8
+ @mock_temp_file = mock('temp file',
9
+ :path => '/path/to/temp_file',
10
+ :puts => nil)
11
+ Tempfile.stub!(:open).and_yield @mock_temp_file
12
+ end
13
+
14
+ describe "write_to_tmp_file" do
15
+ it "should open a temporary file to write to" do
16
+ Tempfile.should_receive(:open).with('ruby_string')
17
+ "bla".write_to_tmp_file
18
+ end
19
+
20
+ it "should write the string to the temporary file" do
21
+ @mock_temp_file.should_receive(:puts).with "pooh"
22
+ "pooh".write_to_tmp_file
23
+ end
24
+
25
+ it "should store the path of the temporary file in @path_of_tmp_file_for_string_to_editor" do
26
+ s = "honey"
27
+ s.write_to_tmp_file
28
+ s.instance_variable_get('@path_of_tmp_file_for_string_to_editor').should == '/path/to/temp_file'
29
+ end
30
+
31
+ it "should return the path of the temporary file" do
32
+ s = "honey"
33
+ s.write_to_tmp_file.should == '/path/to/temp_file'
34
+ end
35
+
36
+ it "should write to a tmp file only once" do
37
+ s = "mash"
38
+ s.write_to_tmp_file
39
+ Tempfile.should_not_receive(:open)
40
+ s.write_to_tmp_file
41
+ end
42
+
43
+ it "should return the path of the temporary file if it was already written to a temporary file" do
44
+ s = "honey"
45
+ s.write_to_tmp_file
46
+ s.write_to_tmp_file.should == '/path/to/temp_file'
47
+ end
48
+ end
49
+
50
+ describe "edit" do
51
+ describe "if no editor command is specified in ENV['EDITOR']" do
52
+ before do
53
+ ENV.delete('EDITOR')
54
+ end
55
+
56
+ it "should raise an error" do
57
+ lambda { "breakfast".edit }.should raise_error
58
+ end
59
+ end
60
+
61
+ describe "if ENV['EDITOR'] contains an editor command" do
62
+ before do
63
+ ENV['EDITOR'] = '/bin/editor/command'
64
+ end
65
+
66
+ it "should send a string to the edit command in the background" do
67
+ s = "sausage"
68
+ s.should_receive(:system).with('/bin/editor/command /path/to/temp_file &')
69
+ s.edit
70
+ end
71
+ end
72
+ end
73
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: string_to_editor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tom ten Thij
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-08 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.9
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: cucumber
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: Send ruby strings to your editor or a file
36
+ email: string_to_editor@tomtenthij.nl
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - features/step_definitions/string_to_editor_steps.rb
52
+ - features/string_to_editor.feature
53
+ - features/support/env.rb
54
+ - lib/string_to_editor.rb
55
+ - spec/spec.opts
56
+ - spec/spec_helper.rb
57
+ - spec/string_to_editor_spec.rb
58
+ has_rdoc: true
59
+ homepage: http://github.com/tomtt/string_to_editor
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --charset=UTF-8
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ requirements: []
80
+
81
+ rubyforge_project:
82
+ rubygems_version: 1.3.5
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Send ruby strings to your editor or a file
86
+ test_files:
87
+ - spec/spec_helper.rb
88
+ - spec/string_to_editor_spec.rb