interactive_editor 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
File without changes
data/README.md ADDED
@@ -0,0 +1,9 @@
1
+
2
+ # Interactive editor
3
+
4
+ cf. my blog post: [Integrating vim and irb](http://zegoggl.es/2009/04/integrating-vim-and-irb.html).
5
+
6
+
7
+ # Credits
8
+
9
+ Giles Bowkett, Greg Brown, and several audience members from Giles' Ruby East presentation [Use vi or any text editor from within IRB](http://gilesbowkett.blogspot.com/2007/10/use-vi-or-any-text-editor-from-within.html).
data/Rakefile ADDED
@@ -0,0 +1,117 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'date'
4
+
5
+ #############################################################################
6
+ #
7
+ # Helper functions
8
+ #
9
+ #############################################################################
10
+
11
+ def name
12
+ @name ||= Dir['*.gemspec'].first.split('.').first
13
+ end
14
+
15
+ def version
16
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
17
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
18
+ end
19
+
20
+ def date
21
+ Date.today.to_s
22
+ end
23
+
24
+ def rubyforge_project
25
+ name
26
+ end
27
+
28
+ def gemspec_file
29
+ "#{name}.gemspec"
30
+ end
31
+
32
+ def gem_file
33
+ "#{name}-#{version}.gem"
34
+ end
35
+
36
+ def replace_header(head, header_name)
37
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
38
+ end
39
+
40
+ #############################################################################
41
+ #
42
+ # Standard tasks
43
+ #
44
+ #############################################################################
45
+
46
+ task :default => :test
47
+
48
+ desc "Open an irb session preloaded with this library"
49
+ task :console do
50
+ sh "irb -rubygems -r ./lib/#{name}.rb"
51
+ end
52
+
53
+
54
+
55
+ #############################################################################
56
+ #
57
+ # Packaging tasks
58
+ #
59
+ #############################################################################
60
+
61
+ task :release => :build do
62
+ unless `git branch` =~ /^\* master$/
63
+ puts "You must be on the master branch to release!"
64
+ exit!
65
+ end
66
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
67
+ sh "git tag v#{version}"
68
+ sh "git push origin master"
69
+ sh "git push v#{version}"
70
+ sh "gem push pkg/#{name}-#{version}.gem"
71
+ end
72
+
73
+ task :build => :gemspec do
74
+ sh "mkdir -p pkg"
75
+ sh "gem build #{gemspec_file}"
76
+ sh "mv #{gem_file} pkg"
77
+ end
78
+
79
+ task :gemspec => :validate do
80
+ # read spec file and split out manifest section
81
+ spec = File.read(gemspec_file)
82
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
83
+
84
+ # replace name version and date
85
+ replace_header(head, :name)
86
+ replace_header(head, :version)
87
+ replace_header(head, :date)
88
+ #comment this out if your rubyforge_project has a different name
89
+ replace_header(head, :rubyforge_project)
90
+
91
+ # determine file list from git ls-files
92
+ files = `git ls-files`.
93
+ split("\n").
94
+ sort.
95
+ reject { |file| file =~ /^\./ }.
96
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
97
+ map { |file| " #{file}" }.
98
+ join("\n")
99
+
100
+ # piece file back together and write
101
+ manifest = " s.files = %w[\n#{files}\n ]\n"
102
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
103
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
104
+ puts "Updated #{gemspec_file}"
105
+ end
106
+
107
+ task :validate do
108
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb"]
109
+ unless libfiles.empty?
110
+ puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
111
+ exit!
112
+ end
113
+ unless Dir['VERSION*'].empty?
114
+ puts "A `VERSION` file at root level violates Gem best practices."
115
+ exit!
116
+ end
117
+ end
@@ -0,0 +1,49 @@
1
+ Gem::Specification.new do |s|
2
+ s.specification_version = 2 if s.respond_to? :specification_version=
3
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
4
+ s.rubygems_version = '1.3.5'
5
+
6
+ ## Leave these as is they will be modified for you by the rake gemspec task.
7
+ ## If your rubyforge_project name is different, then edit it and comment out
8
+ ## the sub! line in the Rakefile
9
+ s.name = 'interactive_editor'
10
+ s.version = '0.0.1'
11
+ s.date = '2010-05-16'
12
+ s.rubyforge_project = 'interactive_editor'
13
+
14
+ ## Make sure your summary is short. The description may be as long
15
+ ## as you like.
16
+ s.summary = "Interactive editing in irb."
17
+ s.description = "Use vim (or any other text editor) from inside irb to quickly test & write new code."
18
+
19
+ ## List the primary authors. If there are a bunch of authors, it's probably
20
+ ## better to set the email to an email list or something. If you don't have
21
+ ## a custom homepage, consider using your GitHub URL or the like.
22
+ s.authors = ["Jan Berkel"]
23
+ s.email = 'jan.berkel@gmail.com'
24
+ s.homepage = 'http://github.com/jberkel/interactive_editor'
25
+
26
+ s.require_paths = %w[lib]
27
+
28
+ s.rdoc_options = ["--charset=UTF-8"]
29
+ s.extra_rdoc_files = %w[README.md LICENSE]
30
+
31
+ s.add_dependency('spoon', [">= 0.0.1"])
32
+
33
+ ## Leave this section as-is. It will be automatically generated from the
34
+ ## contents of your Git repository via the gemspec task. DO NOT REMOVE
35
+ ## THE MANIFEST COMMENTS, they are used as delimiters by the task.
36
+ # = MANIFEST =
37
+ s.files = %w[
38
+ LICENSE
39
+ README.md
40
+ Rakefile
41
+ interactive_editor.gemspec
42
+ lib/interactive_editor.rb
43
+ ]
44
+ # = MANIFEST =
45
+
46
+ ## Test files will be grabbed from the file list. Make sure the path glob
47
+ ## matches what you actually use.
48
+ s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
49
+ end
@@ -0,0 +1,78 @@
1
+ # vim: set syntax=ruby :
2
+ # Giles Bowkett, Greg Brown, and several audience members from Giles' Ruby East presentation.
3
+ # http://gilesbowkett.blogspot.com/2007/10/use-vi-or-any-text-editor-from-within.html
4
+
5
+ require 'irb'
6
+ require 'fileutils'
7
+ require 'tempfile'
8
+
9
+ class InteractiveEditor
10
+ VERSION = '0.0.1'
11
+
12
+ attr_accessor :editor
13
+
14
+ def initialize(editor)
15
+ @editor = editor.to_s
16
+ end
17
+
18
+ def edit(file=nil)
19
+ @file = if file
20
+ FileUtils.touch(file) unless File.exist?(file)
21
+ File.new(file)
22
+ else
23
+ (@file && File.exist?(@file.path)) ? @file : Tempfile.new(["irb_tempfile", ".rb"])
24
+ end
25
+ mtime = File.stat(@file.path).mtime
26
+ Exec.system(@editor, @file.path)
27
+
28
+ execute if mtime < File.stat(@file.path).mtime
29
+ end
30
+
31
+ def execute
32
+ Object.class_eval(IO.read(@file.path))
33
+ end
34
+
35
+ def self.edit(editor, file=nil)
36
+ #idea serialise last file to disk, for recovery
37
+ unless IRB.conf[:interactive_editors] && IRB.conf[:interactive_editors][editor]
38
+ IRB.conf[:interactive_editors] ||= {}
39
+ IRB.conf[:interactive_editors][editor] = InteractiveEditor.new(editor)
40
+ end
41
+ IRB.conf[:interactive_editors][editor].edit(file)
42
+ end
43
+
44
+ module Exec
45
+ extend self
46
+
47
+ if RUBY_PLATFORM =~ /java/
48
+ #http://github.com/headius/spoon
49
+ require 'rubygems'
50
+ require 'spoon'
51
+
52
+ def system(*args)
53
+ Process.waitpid(Spoon.spawnp(*args))
54
+ end
55
+ else
56
+ def system(file, *args)
57
+ Kernel::system(file, *args)
58
+ end
59
+ end
60
+ end
61
+
62
+ module Editors
63
+ {
64
+ :vi => nil,
65
+ :vim => nil,
66
+ :emacs => nil,
67
+ :nano => nil,
68
+ :mate => 'mate -w'
69
+ }.each do |k,v|
70
+ define_method(k) do |*args|
71
+ InteractiveEditor.edit(v || k, *args)
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ Object.send(:include, InteractiveEditor::Editors)
78
+
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: interactive_editor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jan Berkel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-05-16 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: spoon
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.1
24
+ version:
25
+ description: Use vim (or any other text editor) from inside irb to quickly test & write new code.
26
+ email: jan.berkel@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.md
33
+ - LICENSE
34
+ files:
35
+ - LICENSE
36
+ - README.md
37
+ - Rakefile
38
+ - interactive_editor.gemspec
39
+ - lib/interactive_editor.rb
40
+ has_rdoc: true
41
+ homepage: http://github.com/jberkel/interactive_editor
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --charset=UTF-8
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ requirements: []
62
+
63
+ rubyforge_project: interactive_editor
64
+ rubygems_version: 1.3.5
65
+ signing_key:
66
+ specification_version: 2
67
+ summary: Interactive editing in irb.
68
+ test_files: []
69
+