rib 0.9.5 → 0.9.9

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/CHANGES.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Rib CHANGES
2
2
 
3
+ ## Rib 0.9.9 -- 2011-10-26
4
+
5
+ ### Bugs fixes
6
+
7
+ * [more/color] Fixed Windows coloring support.
8
+ * [more/color] Properly reset ANSI sequence.
9
+
10
+ ### Enhancement
11
+
12
+ * [commands] Extract commands description under `__END__` in the commands.
13
+ Please read [rib-rest-core][] as an example.
14
+ * [rib] Always show original errors if anything is wrong.
15
+
16
+ [rib-rest-core]: https://github.com/cardinalblue/rest-core/blob/rest-core-0.7.0/bin/rib-rest-core#L21-22
17
+
3
18
  ## Rib 0.9.5 -- 2011-09-03
4
19
 
5
20
  * [rib-rails] Fixed Rails3 (sandbox) and Rails2 (env) console. Thanks bootleq
data/Rakefile CHANGED
@@ -8,8 +8,8 @@ desc 'Generate gemspec'
8
8
  task 'gem:spec' do
9
9
  Gemgem.spec = Gemgem.create do |s|
10
10
  require 'rib/version'
11
- s.name = 'rib'
12
- s.version = Rib::VERSION
11
+ s.name = 'rib'
12
+ s.version = Rib::VERSION
13
13
 
14
14
  %w[].each{ |g| s.add_runtime_dependency(g) }
15
15
  end
@@ -16,7 +16,7 @@ module Rib::Auto
16
16
  begin
17
17
  app.load
18
18
  rescue LoadError => e
19
- Rib.warn("Is this a #{app} app?\n #{e}")
19
+ Rib.warn("Error: #{e}", "Is this a #{app} app?")
20
20
  end
21
21
  else
22
22
  Rib.warn("No app found")
@@ -5,7 +5,7 @@ module Rib::Rails
5
5
  def load
6
6
  load_rails
7
7
  rescue LoadError => e
8
- Rib.abort("Is this a Rails app?\n #{e}")
8
+ Rib.abort("Error: #{e}", "Is this a Rails app?")
9
9
  end
10
10
 
11
11
  def load_rails
@@ -5,7 +5,7 @@ module Rib::Ramaze
5
5
  def load
6
6
  load_ramaze
7
7
  rescue LoadError => e
8
- Rib.abort("Is this a Ramaze app?\n #{e}")
8
+ Rib.abort("Error: #{e}", "Is this a Ramaze app?")
9
9
  end
10
10
 
11
11
  def load_ramaze
@@ -26,9 +26,10 @@ end
26
26
 
27
27
  begin
28
28
  Rib.silence{require 'bond'}
29
- rescue LoadError
30
- Rib.warn("Please install bond to use completion plugin:\n",
31
- " gem install bond\n",
32
- "Or add bond to Gemfile if that's the case")
29
+ rescue LoadError => e
30
+ Rib.warn("Error: #{e}" ,
31
+ "Please install bond to use completion plugin:\n",
32
+ " gem install bond\n" ,
33
+ "Or add bond to Gemfile if that's the case" )
33
34
  Rib::Completion.disable
34
35
  end
@@ -155,9 +155,10 @@ end
155
155
 
156
156
  begin
157
157
  require 'readline_buffer'
158
- rescue LoadError
159
- Rib.warn("Please install readline_buffer to use autoindent plugin:\n",
160
- " gem install readline_buffer\n",
161
- "Or add readline_buffer to Gemfile if that's the case")
158
+ rescue LoadError => e
159
+ Rib.warn("Error: #{e}" ,
160
+ "Please install readline_buffer to use autoindent plugin:\n",
161
+ " gem install readline_buffer\n" ,
162
+ "Or add readline_buffer to Gemfile if that's the case" )
162
163
  Rib::Autoindent.disable
163
164
  end
@@ -18,9 +18,10 @@ begin
18
18
  require 'hirb'
19
19
  ::Hirb.enable
20
20
  }
21
- rescue LoadError
22
- Rib.warn("Please install hirb to use hirb plugin:\n",
23
- " gem install hirb\n",
21
+ rescue LoadError => e
22
+ Rib.warn("Error: #{e}" ,
23
+ "Please install hirb to use hirb plugin:\n",
24
+ " gem install hirb\n" ,
24
25
  "Or add hirb to Gemfile if that's the case")
25
26
  Rib::Hirb.disable
26
27
  end
@@ -18,7 +18,7 @@ module Rib::Anchor
18
18
 
19
19
  def prompt
20
20
  return super if Rib::Anchor.disabled?
21
- return super unless config[:anchor]
21
+ return super unless config[:prompt_anchor]
22
22
 
23
23
  level = "(#{Rib.shells.size - 1})"
24
24
  if Rib.const_defined?(:Color) &&
@@ -53,16 +53,18 @@ module Rib::Anchor
53
53
  end
54
54
 
55
55
  module Imp
56
- def anchor obj_or_binding
56
+ def anchor obj_or_binding, opts={}
57
57
  return if Rib::Anchor.disabled?
58
58
 
59
59
  if Rib.shell.running?
60
60
  Rib.shells << Rib::Shell.new(
61
- Rib.shell.config.merge( :binding => obj_or_binding,
62
- :anchor => true ))
61
+ Rib.shell.config.merge( :binding => obj_or_binding,
62
+ :prompt_anchor => true ).
63
+ merge(opts))
63
64
  else
64
- Rib.shell.config.merge!(:binding => obj_or_binding,
65
- :anchor => true )
65
+ Rib.shell.config.merge!(:binding => obj_or_binding,
66
+ :prompt_anchor => true ).
67
+ merge!(opts)
66
68
  end
67
69
 
68
70
  Rib.shell.loop
@@ -84,7 +84,7 @@ module Rib::Color
84
84
  end
85
85
 
86
86
  def color rgb
87
- "\x1b[#{rgb}m" + (block_given? ? "#{yield}#{reset}" : '')
87
+ "\e[#{rgb}m" + if block_given? then "#{yield}#{reset}" else '' end
88
88
  end
89
89
 
90
90
  def black &block; color(30, &block); end
@@ -95,5 +95,15 @@ module Rib::Color
95
95
  def magenta &block; color(35, &block); end
96
96
  def cyan &block; color(36, &block); end
97
97
  def white &block; color(37, &block); end
98
- def reset &block; color('', &block); end
98
+ def reset &block; color( 0, &block); end
99
+ end
100
+
101
+ begin
102
+ require 'win32console' if defined?(Gem) && Gem.win_platform?
103
+ rescue LoadError => e
104
+ Rib.warn("Error: #{e}" ,
105
+ "Please install win32console to use color plugin on Windows:\n",
106
+ " gem install win32console\n" ,
107
+ "Or add win32console to Gemfile if that's the case" )
108
+ Rib::Color.disable
99
109
  end
@@ -32,14 +32,17 @@ module Rib::Runner
32
32
 
33
33
  def commands
34
34
  @commands ||=
35
- command_names.map{ |n| [n, command_descriptions[n] || ' '] }
35
+ command_paths.map{ |path|
36
+ name = File.basename(path)[/^rib\-(.+)$/, 1]
37
+ [name, command_descriptions[name] ||
38
+ command_descriptions_find(path) || ' '] }
36
39
  end
37
40
 
38
- def command_names
39
- @command_names ||=
41
+ def command_paths
42
+ @command_paths ||=
40
43
  Gem.path.map{ |path|
41
44
  Dir["#{path}/bin/*"].map{ |f|
42
- (File.executable?(f) && File.basename(f) =~ /^rib\-(\w+)$/ && $1) ||
45
+ (File.executable?(f) && File.basename(f) =~ /^rib\-.+$/ && f) ||
43
46
  nil # a trick to make false to be nil and then
44
47
  }.compact # this compact could eliminate them
45
48
  }.flatten
@@ -54,6 +57,12 @@ module Rib::Runner
54
57
  'ramaze' => 'Run as Ramaze console' }
55
58
  end
56
59
 
60
+ # Extract the text below __END__ in the bin file as the description
61
+ def command_descriptions_find path
62
+ File.read(path) =~ /Gem\.bin_path\(['"](.+)['"], ['"](.+)['"],/
63
+ File.read(Gem.bin_path($1, $2))[/\n__END__\n(.+)$/m, 1].strip
64
+ end
65
+
57
66
  def run argv=ARGV
58
67
  (@running_commands ||= []) << Rib.config[:name]
59
68
  unused = parse(argv)
@@ -71,36 +80,36 @@ module Rib::Runner
71
80
  unused = []
72
81
  until argv.empty?
73
82
  case arg = argv.shift
74
- when /-e=?(.+)?/, /--eval=?(.+)?/
83
+ when /^-e=?(.+)?/, /^--eval=?(.+)?/
75
84
  eval($1 || argv.shift, binding, __FILE__, __LINE__)
76
85
 
77
- when /-d/, '--debug'
86
+ when /^-d/, '--debug'
78
87
  $DEBUG = true
79
88
  argv.unshift("-#{arg[2..-1]}") if arg.size > 2
80
89
 
81
- when /-w/, '--warn'
90
+ when /^-w/, '--warn'
82
91
  $-w, $VERBOSE = true, true
83
92
  argv.unshift("-#{arg[2..-1]}") if arg.size > 2
84
93
 
85
- when /-I=?(.+)?/, /--include=?(.+)?/
94
+ when /^-I=?(.+)?/, /^--include=?(.+)?/
86
95
  paths = ($1 || argv.shift).split(':')
87
96
  $LOAD_PATH.unshift(*paths)
88
97
 
89
- when /-r=?(.+)?/, /--require=?(.+)?/
98
+ when /^-r=?(.+)?/, /^--require=?(.+)?/
90
99
  require($1 || argv.shift)
91
100
 
92
- when /-c=?(.+)?/, /--config=?(.+)?/
101
+ when /^-c=?(.+)?/, /^--config=?(.+)?/
93
102
  Rib.config[:config] = $1 || argv.shift
94
103
 
95
- when /-n/, '--no-config'
104
+ when /^-n/, '--no-config'
96
105
  Rib.config.delete(:config)
97
106
  argv.unshift("-#{arg[2..-1]}") if arg.size > 2
98
107
 
99
- when /-h/, '--help'
108
+ when /^-h/, '--help'
100
109
  puts(help)
101
110
  exit
102
111
 
103
- when /-v/, '--version'
112
+ when /^-v/, '--version'
104
113
  require 'rib/version'
105
114
  puts(Rib::VERSION)
106
115
  exit
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Rib
3
- VERSION = '0.9.5'
3
+ VERSION = '0.9.9'
4
4
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "rib"
5
- s.version = "0.9.5"
5
+ s.version = "0.9.9"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Lin Jen-Shin (godfat)"]
9
- s.date = "2011-09-03"
9
+ s.date = "2011-10-26"
10
10
  s.description = "Ruby-Interactive-ruBy -- Yet another interactive Ruby shell\n\nRib is based on the design of [ripl][] and the work of [ripl-rc][], some of\nthe features are also inspired by [pry][]. The aim of Rib is to be fully\nfeatured and yet very easy to opt-out or opt-in other features. It shall\nbe simple, lightweight and modular so that everyone could customize Rib.\n\n[ripl]: https://github.com/cldwalker/ripl\n[ripl-rc]: https://github.com/godfat/ripl-rc\n[pry]: https://github.com/pry/pry"
11
11
  s.email = ["godfat (XD) godfat.org"]
12
12
  s.executables = [
@@ -81,7 +81,7 @@ Gem::Specification.new do |s|
81
81
  "test/test_shell.rb"]
82
82
  s.homepage = "https://github.com/godfat/rib"
83
83
  s.require_paths = ["lib"]
84
- s.rubygems_version = "1.8.10"
84
+ s.rubygems_version = "1.8.11"
85
85
  s.summary = "Ruby-Interactive-ruBy -- Yet another interactive Ruby shell"
86
86
  s.test_files = [
87
87
  "test/core/test_completion.rb",
@@ -12,10 +12,6 @@ module Gemgem
12
12
  s.authors = ['Lin Jen-Shin (godfat)']
13
13
  s.email = ['godfat (XD) godfat.org']
14
14
 
15
- description = readme.
16
- match(/DESCRIPTION:\n\n(.+?)(?=\n\n[^\n]+:\n)/m)[1].
17
- lines.to_a
18
-
19
15
  s.description = description.join
20
16
  s.summary = description.first
21
17
 
@@ -34,13 +30,68 @@ module Gemgem
34
30
  path = %w[README.md README].find{ |name|
35
31
  File.exist?("#{Gemgem.dir}/#{name}")
36
32
  }
37
- if path
38
- File.read(path)
39
- else
40
- "DESCRIPTION:\n\n \n\nEND:\n"
33
+ @readme ||=
34
+ if path
35
+ ps = File.read(path).scan(/#+[^\n]+\n\n.+?(?=\n\n#+[^\n]+\n)/m)
36
+ ps.inject({'HEADER' => ps.first}){ |r, s, i|
37
+ r[s[/\w+/]] = s
38
+ r
39
+ }
40
+ else
41
+ {}
42
+ end
43
+ end
44
+
45
+ def description
46
+ @description ||= (readme['DESCRIPTION']||'').sub(/.+\n\n/, '').lines.to_a
47
+ end
48
+
49
+ def changes
50
+ path = %w[CHANGES.md CHANGES].find{ |name|
51
+ File.exist?("#{Gemgem.dir}/#{name}")
52
+ }
53
+ @changes ||=
54
+ if path
55
+ date = '\d+{4}\-\d+{2}\-\d{2}'
56
+ File.read(path).match(
57
+ /([^\n]+#{date}\n\n(.+?))(?=\n\n[^\n]+#{date}\n|\Z)/m)[1]
58
+ else
59
+ ''
60
+ end
61
+ end
62
+
63
+ def ann_md
64
+ "##{readme['HEADER'].sub(/([\w\-]+)/, "[\\1](#{spec.homepage})")}\n\n" \
65
+ "##{readme['DESCRIPTION'][/[^\n]+\n\n[^\n]+/]}\n\n" \
66
+ "### CHANGES:\n\n" \
67
+ "###{changes}\n\n" \
68
+ "##{readme['INSTALLATION']}\n\n" +
69
+ if readme['SYNOPSIS'] then "##{readme['SYNOPSIS']}" else '' end
70
+ end
71
+
72
+ def ann_html
73
+ gem 'nokogiri'
74
+ gem 'kramdown'
75
+
76
+ IO.popen('kramdown', 'r+') do |md|
77
+ md.puts Gemgem.ann_md
78
+ md.close_write
79
+ require 'nokogiri'
80
+ html = Nokogiri::XML.parse("<gemgem>#{md.read}</gemgem>")
81
+ html.css('*').each{ |n| n.delete('id') }
82
+ html.root.children.to_html
41
83
  end
42
84
  end
43
85
 
86
+ def ann_email
87
+ "#{readme['HEADER'].sub(/([\w\-]+)/, "\\1 <#{spec.homepage}>")}\n\n" \
88
+ "#{readme['DESCRIPTION']}\n\n" \
89
+ "#{readme['INSTALLATION']}\n\n" +
90
+ if readme['SYNOPSIS'] then "##{readme['SYNOPSIS']}\n\n" else '' end +
91
+ "## CHANGES:\n\n" \
92
+ "##{changes}\n\n"
93
+ end
94
+
44
95
  def gem_tag
45
96
  "#{spec.name}-#{spec.version}"
46
97
  end
@@ -95,7 +146,7 @@ module Gemgem
95
146
 
96
147
  def ignore_patterns
97
148
  @ignore_files ||= expand_patterns(
98
- File.read("#{dir}/.gitignore").split("\n").reject{ |pattern|
149
+ gitignore.split("\n").reject{ |pattern|
99
150
  pattern.strip == ''
100
151
  }).map{ |pattern| %r{^([^/]+/)*?#{Regexp.escape(pattern)}(/[^/]+)*?$} }
101
152
  end
@@ -112,6 +163,14 @@ module Gemgem
112
163
  end
113
164
  }.flatten
114
165
  end
166
+
167
+ def gitignore
168
+ if File.exist?(path = "#{dir}/.gitignore")
169
+ File.read(path)
170
+ else
171
+ ''
172
+ end
173
+ end
115
174
  end
116
175
 
117
176
  namespace :gem do
@@ -140,14 +199,14 @@ task :check do
140
199
  ver = Gemgem.spec.version.to_s
141
200
 
142
201
  if ENV['VERSION'].nil?
143
- puts("\x1b[35mExpected " \
144
- "\x1b[33mVERSION\x1b[35m=\x1b[33m#{ver}\x1b[m")
202
+ puts("\e[35mExpected " \
203
+ "\e[33mVERSION\e[35m=\e[33m#{ver}\e[0m")
145
204
  exit(1)
146
205
 
147
206
  elsif ENV['VERSION'] != ver
148
- puts("\x1b[35mExpected \x1b[33mVERSION\x1b[35m=\x1b[33m#{ver} " \
149
- "\x1b[35mbut got\n " \
150
- "\x1b[33mVERSION\x1b[35m=\x1b[33m#{ENV['VERSION']}\x1b[m")
207
+ puts("\e[35mExpected \e[33mVERSION\e[35m=\e[33m#{ver} " \
208
+ "\e[35mbut got\n " \
209
+ "\e[33mVERSION\e[35m=\e[33m#{ENV['VERSION']}\e[0m")
151
210
  exit(2)
152
211
  end
153
212
  end
@@ -173,13 +232,28 @@ task 'test:shell', :RUBY_OPTS do |t, args|
173
232
  sh(cmd.compact.join(' '))
174
233
  end
175
234
 
235
+ desc 'Generate ann markdown'
236
+ task 'ann:md' => ['gem:spec'] do
237
+ puts Gemgem.ann_md
238
+ end
239
+
240
+ desc 'Generate ann html'
241
+ task 'ann:html' => ['gem:spec'] do
242
+ puts Gemgem.ann_html
243
+ end
244
+
245
+ desc 'Generate ann email'
246
+ task 'ann:email' => ['gem:spec'] do
247
+ puts Gemgem.ann_email
248
+ end
249
+
176
250
  desc 'Generate rdoc'
177
251
  task :doc => ['gem:spec'] do
178
252
  sh("yardoc -o rdoc --main README.md" \
179
253
  " --files #{Gemgem.spec.extra_rdoc_files.join(',')}")
180
254
  end
181
255
 
182
- desc 'Removed ignored files'
256
+ desc 'Remove ignored files'
183
257
  task :clean => ['gem:spec'] do
184
258
  trash = "~/.Trash/#{Gemgem.spec.name}/"
185
259
  sh "mkdir -p #{trash}" unless File.exist?(File.expand_path(trash))
@@ -18,11 +18,11 @@ describe Rib::Color do
18
18
  @color.send(:format_color,
19
19
  [{0 => :a}, 'b', [nil, {false => Object}], {true => Exception.new}]).
20
20
  should.eq \
21
- "\e[34m[\e[m\e[34m{\e[m\e[31m0\e[m\e[34m=>\e[m\e[36m:a\e[m\e[" \
22
- "34m}\e[m\e[34m, \e[m\e[32m\"b\"\e[m\e[34m, \e[m\e[34m[\e[m\e" \
23
- "[35mnil\e[m\e[34m, \e[m\e[34m{\e[m\e[35mfalse\e[m\e[34m=>\e[" \
24
- "m\e[33mObject\e[m\e[34m}\e[m\e[34m]\e[m\e[34m, \e[m\e[34m{\e" \
25
- "[m\e[35mtrue\e[m\e[34m=>\e[m\e[35m#<Exception: Exception>\e[" \
26
- "m\e[34m}\e[m\e[34m]\e[m"
21
+ "\e[34m[\e[0m\e[34m{\e[0m\e[31m0\e[0m\e[34m=>\e[0m\e[36m:a\e[0m\e" \
22
+ "[34m}\e[0m\e[34m, \e[0m\e[32m\"b\"\e[0m\e[34m, \e[0m\e[34m[\e[0m" \
23
+ "\e[35mnil\e[0m\e[34m, \e[0m\e[34m{\e[0m\e[35mfalse\e[0m\e[34m=>" \
24
+ "\e[0m\e[33mObject\e[0m\e[34m}\e[0m\e[34m]\e[0m\e[34m, \e[0m\e[34m"\
25
+ "{\e[0m\e[35mtrue\e[0m\e[34m=>\e[0m\e[35m#<Exception: Exception>" \
26
+ "\e[0m\e[34m}\e[0m\e[34m]\e[0m"
27
27
  end
28
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.9.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-03 00:00:00.000000000 Z
12
+ date: 2011-10-26 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: ! 'Ruby-Interactive-ruBy -- Yet another interactive Ruby shell
15
15
 
@@ -122,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
122
  version: '0'
123
123
  requirements: []
124
124
  rubyforge_project:
125
- rubygems_version: 1.8.10
125
+ rubygems_version: 1.8.11
126
126
  signing_key:
127
127
  specification_version: 3
128
128
  summary: Ruby-Interactive-ruBy -- Yet another interactive Ruby shell