rib 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/.gitignore +6 -0
  2. data/.gitmodules +3 -0
  3. data/.travis.yml +9 -0
  4. data/2011-02-28.md +203 -0
  5. data/CHANGES +86 -0
  6. data/CONTRIBUTORS +2 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE +201 -0
  9. data/README +190 -0
  10. data/README.md +190 -0
  11. data/Rakefile +20 -0
  12. data/TODO +6 -0
  13. data/lib/rib.rb +42 -0
  14. data/lib/rib/all.rb +4 -0
  15. data/lib/rib/api.rb +105 -0
  16. data/lib/rib/core.rb +5 -0
  17. data/lib/rib/core/completion.rb +22 -0
  18. data/lib/rib/core/history_file.rb +38 -0
  19. data/lib/rib/core/readline.rb +19 -0
  20. data/lib/rib/core/underscore.rb +53 -0
  21. data/lib/rib/debug.rb +3 -0
  22. data/lib/rib/more.rb +12 -0
  23. data/lib/rib/more/color.rb +98 -0
  24. data/lib/rib/more/multiline.rb +77 -0
  25. data/lib/rib/more/multiline_history.rb +31 -0
  26. data/lib/rib/more/multiline_history_file.rb +37 -0
  27. data/lib/rib/more/squeeze_history.rb +37 -0
  28. data/lib/rib/more/strip_backtrace.rb +43 -0
  29. data/lib/rib/plugin.rb +56 -0
  30. data/lib/rib/runner.rb +106 -0
  31. data/lib/rib/shell.rb +43 -0
  32. data/lib/rib/test.rb +25 -0
  33. data/lib/rib/version.rb +4 -0
  34. data/lib/rib/zore.rb +3 -0
  35. data/lib/rib/zore/anchor.rb +69 -0
  36. data/lib/rib/zore/edit.rb +33 -0
  37. data/rib.gemspec +104 -0
  38. data/screenshot.png +0 -0
  39. data/task/.gitignore +1 -0
  40. data/task/gemgem.rb +182 -0
  41. data/test/core/test_completion.rb +18 -0
  42. data/test/core/test_history_file.rb +57 -0
  43. data/test/core/test_readline.rb +21 -0
  44. data/test/core/test_underscore.rb +41 -0
  45. data/test/more/test_color.rb +28 -0
  46. data/test/more/test_squeeze_history.rb +43 -0
  47. data/test/test_api.rb +20 -0
  48. data/test/test_plugin.rb +38 -0
  49. data/test/test_shell.rb +82 -0
  50. metadata +77 -13
@@ -0,0 +1,33 @@
1
+
2
+ require 'rib'
3
+ require 'tempfile'
4
+
5
+ module Rib::Edit
6
+ include Rib::Plugin
7
+ Shell.use(self)
8
+
9
+ module EditImp
10
+ def edit
11
+ return if Rib::Edit.disabled?
12
+ file = Tempfile.new(['rib.edit', '.rb'])
13
+ file.puts(Rib.vars[:edit])
14
+ file.close
15
+
16
+ system("$EDITOR #{file.path}")
17
+
18
+ if (shell = Rib.shell).running?
19
+ shell.send(:multiline_buffer).pop
20
+ else
21
+ shell.before_loop
22
+ end
23
+
24
+ shell.loop_eval(Rib.vars[:edit] = File.read(file.path))
25
+
26
+ ensure
27
+ file.close
28
+ file.unlink
29
+ end
30
+ end
31
+
32
+ Rib.extend(EditImp)
33
+ end
@@ -0,0 +1,104 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{rib}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = [%q{Lin Jen-Shin (godfat)}]
9
+ s.date = %q{2011-08-06}
10
+ s.description = %q{ripl plugins collection, take you want, leave you don't.}
11
+ s.email = [%q{godfat (XD) godfat.org}]
12
+ s.executables = [%q{rib}]
13
+ s.extra_rdoc_files = [
14
+ %q{CHANGES},
15
+ %q{CONTRIBUTORS},
16
+ %q{LICENSE},
17
+ %q{TODO}]
18
+ s.files = [
19
+ %q{.gitignore},
20
+ %q{.gitmodules},
21
+ %q{.travis.yml},
22
+ %q{2011-02-28.md},
23
+ %q{CHANGES},
24
+ %q{CONTRIBUTORS},
25
+ %q{Gemfile},
26
+ %q{LICENSE},
27
+ %q{README},
28
+ %q{README.md},
29
+ %q{Rakefile},
30
+ %q{TODO},
31
+ %q{bin/rib},
32
+ %q{lib/rib.rb},
33
+ %q{lib/rib/all.rb},
34
+ %q{lib/rib/api.rb},
35
+ %q{lib/rib/core.rb},
36
+ %q{lib/rib/core/completion.rb},
37
+ %q{lib/rib/core/history_file.rb},
38
+ %q{lib/rib/core/readline.rb},
39
+ %q{lib/rib/core/underscore.rb},
40
+ %q{lib/rib/debug.rb},
41
+ %q{lib/rib/more.rb},
42
+ %q{lib/rib/more/color.rb},
43
+ %q{lib/rib/more/multiline.rb},
44
+ %q{lib/rib/more/multiline_history.rb},
45
+ %q{lib/rib/more/multiline_history_file.rb},
46
+ %q{lib/rib/more/squeeze_history.rb},
47
+ %q{lib/rib/more/strip_backtrace.rb},
48
+ %q{lib/rib/plugin.rb},
49
+ %q{lib/rib/runner.rb},
50
+ %q{lib/rib/shell.rb},
51
+ %q{lib/rib/test.rb},
52
+ %q{lib/rib/version.rb},
53
+ %q{lib/rib/zore.rb},
54
+ %q{lib/rib/zore/anchor.rb},
55
+ %q{lib/rib/zore/edit.rb},
56
+ %q{rib.gemspec},
57
+ %q{screenshot.png},
58
+ %q{task/.gitignore},
59
+ %q{task/gemgem.rb},
60
+ %q{test/core/test_completion.rb},
61
+ %q{test/core/test_history_file.rb},
62
+ %q{test/core/test_readline.rb},
63
+ %q{test/core/test_underscore.rb},
64
+ %q{test/more/test_color.rb},
65
+ %q{test/more/test_squeeze_history.rb},
66
+ %q{test/test_api.rb},
67
+ %q{test/test_plugin.rb},
68
+ %q{test/test_shell.rb}]
69
+ s.homepage = %q{https://github.com/godfat/rib}
70
+ s.rdoc_options = [
71
+ %q{--main},
72
+ %q{README}]
73
+ s.require_paths = [%q{lib}]
74
+ s.rubygems_version = %q{1.8.7}
75
+ s.summary = %q{ripl plugins collection, take you want, leave you don't.}
76
+ s.test_files = [
77
+ %q{test/core/test_completion.rb},
78
+ %q{test/core/test_history_file.rb},
79
+ %q{test/core/test_readline.rb},
80
+ %q{test/core/test_underscore.rb},
81
+ %q{test/more/test_color.rb},
82
+ %q{test/more/test_squeeze_history.rb},
83
+ %q{test/test_api.rb},
84
+ %q{test/test_plugin.rb},
85
+ %q{test/test_shell.rb}]
86
+
87
+ if s.respond_to? :specification_version then
88
+ s.specification_version = 3
89
+
90
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
91
+ s.add_runtime_dependency(%q<bond>, [">= 0"])
92
+ s.add_development_dependency(%q<bacon>, [">= 0"])
93
+ s.add_development_dependency(%q<rr>, [">= 0"])
94
+ else
95
+ s.add_dependency(%q<bond>, [">= 0"])
96
+ s.add_dependency(%q<bacon>, [">= 0"])
97
+ s.add_dependency(%q<rr>, [">= 0"])
98
+ end
99
+ else
100
+ s.add_dependency(%q<bond>, [">= 0"])
101
+ s.add_dependency(%q<bacon>, [">= 0"])
102
+ s.add_dependency(%q<rr>, [">= 0"])
103
+ end
104
+ end
Binary file
@@ -0,0 +1 @@
1
+ *.rbc
@@ -0,0 +1,182 @@
1
+
2
+ require 'pathname'
3
+
4
+ module Gemgem
5
+ class << self
6
+ attr_accessor :dir, :spec
7
+ end
8
+
9
+ module_function
10
+ def create
11
+ yield(spec = Gem::Specification.new{ |s|
12
+ s.authors = ['Lin Jen-Shin (godfat)']
13
+ s.email = ['godfat (XD) godfat.org']
14
+
15
+ description = File.read("#{Gemgem.dir}/README").
16
+ match(/DESCRIPTION:\n\n(.+?)(?=\n\n[^\n]+:\n)/m)[1].
17
+ lines.to_a
18
+
19
+ s.description = description.join
20
+ s.summary = description.first
21
+
22
+ s.extra_rdoc_files = %w[CHANGES CONTRIBUTORS LICENSE TODO].select{ |f|
23
+ File.exist?(f) }
24
+ s.rdoc_options = %w[--main README]
25
+ s.rubygems_version = Gem::VERSION
26
+ s.date = Time.now.strftime('%Y-%m-%d')
27
+ s.files = gem_files
28
+ s.test_files = gem_files.grep(%r{^test/(.+?/)*test_.+?\.rb$})
29
+ s.require_paths = %w[lib]
30
+ })
31
+ spec.homepage ||= "https://github.com/godfat/#{spec.name}"
32
+ spec
33
+ end
34
+
35
+ def gem_tag
36
+ "#{spec.name}-#{spec.version}"
37
+ end
38
+
39
+ def write
40
+ File.open("#{dir}/#{spec.name}.gemspec", 'w'){ |f|
41
+ f << split_lines(spec.to_ruby) }
42
+ end
43
+
44
+ def split_lines ruby
45
+ ruby.gsub(/(.+?)\[(.+?)\]/){ |s|
46
+ if $2.index(',')
47
+ "#{$1}[\n #{$2.split(',').map(&:strip).join(",\n ")}]"
48
+ else
49
+ s
50
+ end
51
+ }
52
+ end
53
+
54
+ def all_files
55
+ @all_files ||= find_files(Pathname.new(dir)).map{ |file|
56
+ if file.to_s =~ %r{\.git/}
57
+ nil
58
+ else
59
+ file.to_s
60
+ end
61
+ }.compact.sort
62
+ end
63
+
64
+ def gem_files
65
+ @gem_files ||= all_files - ignored_files
66
+ end
67
+
68
+ def ignored_files
69
+ @ignored_file ||= all_files.select{ |path| ignore_patterns.find{ |ignore|
70
+ path =~ ignore && !git_files.include?(path)}}
71
+ end
72
+
73
+ def git_files
74
+ @git_files ||= if File.exist?("#{dir}/.git")
75
+ `git ls-files`.split("\n")
76
+ else
77
+ []
78
+ end
79
+ end
80
+
81
+ # protected
82
+ def find_files path
83
+ path.children.select(&:file?).map{|file| file.to_s[(dir.size+1)..-1]} +
84
+ path.children.select(&:directory?).map{|dir| find_files(dir)}.flatten
85
+ end
86
+
87
+ def ignore_patterns
88
+ @ignore_files ||= expand_patterns(
89
+ File.read("#{dir}/.gitignore").split("\n").reject{ |pattern|
90
+ pattern.strip == ''
91
+ }).map{ |pattern| %r{^([^/]+/)*?#{Regexp.escape(pattern)}(/[^/]+)*?$} }
92
+ end
93
+
94
+ def expand_patterns pathes
95
+ pathes.map{ |path|
96
+ if path !~ /\*/
97
+ path
98
+ else
99
+ expand_patterns(
100
+ Dir[path] +
101
+ Pathname.new(File.dirname(path)).children.select(&:directory?).
102
+ map{ |prefix| "#{prefix}/#{File.basename(path)}" })
103
+ end
104
+ }.flatten
105
+ end
106
+ end
107
+
108
+ namespace :gem do
109
+
110
+ desc 'Install gem'
111
+ task :install => [:build] do
112
+ sh("#{Gem.ruby} -S gem install pkg/#{Gemgem.gem_tag}")
113
+ end
114
+
115
+ desc 'Build gem'
116
+ task :build => [:spec] do
117
+ sh("#{Gem.ruby} -S gem build #{Gemgem.spec.name}.gemspec")
118
+ sh("mkdir -p pkg")
119
+ sh("mv #{Gemgem.gem_tag}.gem pkg/")
120
+ end
121
+
122
+ desc 'Release gem'
123
+ task :release => [:spec, :check, :build] do
124
+ sh("git tag #{Gemgem.gem_tag}")
125
+ sh("git push")
126
+ sh("git push --tags")
127
+ sh("#{Gem.ruby} -S gem push pkg/#{Gemgem.gem_tag}.gem")
128
+ end
129
+
130
+ task :check do
131
+ ver = Gemgem.spec.version.to_s
132
+
133
+ if ENV['VERSION'].nil?
134
+ puts("\x1b[35mExpected " \
135
+ "\x1b[33mVERSION\x1b[35m=\x1b[33m#{ver}\x1b[m")
136
+ exit(1)
137
+
138
+ elsif ENV['VERSION'] != ver
139
+ puts("\x1b[35mExpected \x1b[33mVERSION\x1b[35m=\x1b[33m#{ver} " \
140
+ "\x1b[35mbut got\n " \
141
+ "\x1b[33mVERSION\x1b[35m=\x1b[33m#{ENV['VERSION']}\x1b[m")
142
+ exit(2)
143
+ end
144
+ end
145
+
146
+ end # of gem namespace
147
+
148
+ desc 'Run tests in memory'
149
+ task :test do
150
+ require 'bacon'
151
+ Bacon.extend(Bacon::TestUnitOutput)
152
+ Bacon.summary_on_exit
153
+ $LOAD_PATH.unshift('lib')
154
+ Dir['test/**/test_*.rb'].each{ |file| load file }
155
+ end
156
+
157
+ desc 'Run tests with shell'
158
+ task 'test:shell', :RUBY_OPTS do |t, args|
159
+ files = Dir['test/**/test_*.rb'].join(' ')
160
+
161
+ cmd = [Gem.ruby, args[:RUBY_OPTS],
162
+ '-I', 'lib', '-S', 'bacon', '--quiet', files]
163
+
164
+ sh(cmd.compact.join(' '))
165
+ end
166
+
167
+ desc 'Generate rdoc'
168
+ task :doc => ['gem:spec'] do
169
+ sh("yardoc -o rdoc --main README.md" \
170
+ " --files #{Gemgem.spec.extra_rdoc_files.join(',')}")
171
+ end
172
+
173
+ desc 'Removed ignored files'
174
+ task :clean => ['gem:spec'] do
175
+ trash = "~/.Trash/#{Gemgem.spec.name}/"
176
+ sh "mkdir -p #{trash}" unless File.exist?(File.expand_path(trash))
177
+ Gemgem.ignored_files.each{ |file| sh "mv #{file} #{trash}" }
178
+ end
179
+
180
+ task :default do
181
+ puts `#{Gem.ruby} -S #{$PROGRAM_NAME} -T`
182
+ end
@@ -0,0 +1,18 @@
1
+
2
+ require 'rib/test'
3
+ require 'rib/core/completion'
4
+
5
+ describe Rib::Completion do
6
+ behaves_like :rib
7
+
8
+ before do
9
+ @completion = Class.new do
10
+ include Rib::Completion
11
+ end.new
12
+ end
13
+
14
+ should 'find correct ripl plugins' do
15
+ $LOADED_FEATURES << '/dir/ripl/some_plugin.rb'
16
+ @completion.send(:ripl_plugins).should.eq ['ripl/some_plugin.rb']
17
+ end
18
+ end
@@ -0,0 +1,57 @@
1
+
2
+ require 'rib/test'
3
+ require 'rib/core/history_file'
4
+
5
+ describe Rib::HistoryFile do
6
+ behaves_like :rib
7
+
8
+ before do
9
+ Rib::HistoryFile.enable
10
+ @history = "/tmp/test_rib_#{rand}"
11
+ @shell = Rib::Shell.new(:history_file => @history).before_loop
12
+ end
13
+
14
+ after do
15
+ FileUtils.rm_f(@history)
16
+ end
17
+
18
+ should '#after_loop save history' do
19
+ inputs = %w[blih blah]
20
+ @shell.history.replace(inputs)
21
+ @shell.after_loop
22
+ File.read(@history).should.eq "#{inputs.join("\n")}\n"
23
+ end
24
+
25
+ should '#before_loop load previous history' do
26
+ File.open(@history, 'w'){ |f| f.write "check\nthe\nmike" }
27
+ @shell.before_loop
28
+ @shell.history.to_a.should.eq %w[check the mike]
29
+ end
30
+
31
+ should '#before_loop have empty history if no history file exists' do
32
+ @shell.before_loop
33
+ @shell.history.to_a.should.eq []
34
+ end
35
+
36
+ should '#read_history be accessible to plugins in #before_loop' do
37
+ mod = Module.new do
38
+ def read_history
39
+ @history = ['pong_read_history']
40
+ end
41
+ end
42
+ shell = Rib::Shell.dup
43
+ shell.use(mod)
44
+ shell.new.before_loop.history.should.eq ['pong_read_history']
45
+ end
46
+
47
+ should '#write_history be accessible to plugins in #after_loop' do
48
+ mod = Module.new do
49
+ def write_history
50
+ @history = ['pong_write_history']
51
+ end
52
+ end
53
+ shell = Rib::Shell.dup
54
+ shell.use(mod)
55
+ shell.new.before_loop.after_loop.history.should.eq ['pong_write_history']
56
+ end
57
+ end
@@ -0,0 +1,21 @@
1
+
2
+ require 'rib/test'
3
+ require 'rib/core/readline'
4
+
5
+ describe Rib::Readline do
6
+ behaves_like :rib
7
+
8
+ before do
9
+ Rib::Readline.enable
10
+ @shell = Rib::Shell.new.before_loop
11
+ end
12
+
13
+ should '#before_loop set @history' do
14
+ @shell.history.should.eq Readline::HISTORY
15
+ end
16
+
17
+ should '#get_input calling Readline.readline' do
18
+ mock(Readline).readline(@shell.prompt, true){'ok'}
19
+ @shell.get_input.should.eq 'ok'
20
+ end
21
+ end
@@ -0,0 +1,41 @@
1
+
2
+ require 'rib/test'
3
+ require 'rib/core/underscore'
4
+
5
+ describe Rib::Underscore do
6
+ behaves_like :rib
7
+
8
+ before do
9
+ Rib::Underscore.enable
10
+ end
11
+
12
+ def setup bound=Object.new
13
+ @shell = Rib::Shell.new(
14
+ :binding => bound.instance_eval{binding}).before_loop
15
+ end
16
+
17
+ should 'set _' do
18
+ setup
19
+ @shell.eval_input('_').should.eq nil
20
+ @shell.eval_input('10 ** 2')
21
+ @shell.eval_input('_').should.eq 100
22
+ end
23
+
24
+ should 'not set _ if already there' do
25
+ bound = Object.new
26
+ def bound._
27
+ 'hey'
28
+ end
29
+ setup(bound)
30
+ @shell.eval_input('_').should.eq 'hey'
31
+ @shell.eval_input('10 ** 2')
32
+ @shell.eval_input('_').should.eq 'hey'
33
+ end
34
+
35
+ should 'set __' do
36
+ setup
37
+ stub(@shell).warn
38
+ @shell.eval_input('XD')
39
+ @shell.eval_input('__').should.kind_of?(NameError)
40
+ end
41
+ end