webri 1.0.1 → 1.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c4bc8110feecac22d65e1e47e5fda7dc5315ea7dd4f1d4ab67c62d30af6bb8cb
4
- data.tar.gz: 9574bb0c08d78ffd32a6627d0c19ecf0f81e7f7ba0303d64c0b6e92e93f2395f
3
+ metadata.gz: 6c3d0d85a57c242ce0e81aa73823aef986a893a1f48e1d675d6b4d5a268cbb45
4
+ data.tar.gz: '050383f4ecf292a67ab9445f7fbbf5b1523be63062a642b4d74eaf9f20b766e8'
5
5
  SHA512:
6
- metadata.gz: c7b52fa6deb5b9b2029d70ff7ea2b226b2734aa39a2cd6aeb8dce1e7ee2f3e6a687321997beea7b9d958a11cf3b8017d149bcd8dee82a5a98e645619be50db48
7
- data.tar.gz: 1942e35d5aca012c2c8843cdf222502e787226ee5834b10d88409d0a4ccde8178c874a79a52d38c0bf36325a01ca5dcfec4ff6188360493ba2d2f3b5cd42e9f6
6
+ metadata.gz: f859eb825ce282a5198e7e50ee3114f71ecd39098b6416fa2538c79507cacf942366aa8c2c46e7c14b6d06e66b90f908fa8b756ce61d9c055920ba354fd60295
7
+ data.tar.gz: 8c31cc2229776e28c6f47320c7a2cdc8eb1d61157d3c10c10492e0dc7b682394c414a87bff694b25d21d3fad60ee2c82c2fe8ccc89dde7c69838177428bddc89
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
- ## [Unreleased]
1
+ ## Releases
2
2
 
3
- ## [0.1.0] - 2024-11-28
3
+ ## [1.0.1] - 2025-06-13
4
4
 
5
5
  - Initial release
6
+
7
+ ## [1.0.2] - 2025-06-14
8
+
9
+ - Clarify concept: Ruby page (not Ruby file).
10
+
11
+ ## [1.0.3] - 2025-06-16
12
+
13
+ - Add support for Reline.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # WebRI
1
+ # WebRI - Quick Access to Ruby Online Documentation
2
2
 
3
3
  WebRI has a command-line utility, `webri`, for displaying Ruby online documentation.
4
4
 
@@ -14,7 +14,7 @@ WebRI displays documentation for:
14
14
 
15
15
  - A **class** or **module**: opens its web page.
16
16
  - A **method**: opens the web page for its class/module _scrolled to the method's documentation_.
17
- - A Ruby **file**: opens a free-standing web page.
17
+ - A Ruby **page**: opens a free-standing web page.
18
18
 
19
19
  ## Usage
20
20
 
@@ -43,7 +43,7 @@ At the prompt, you can type:
43
43
  - The name of a [class or module][1].
44
44
  - The name of a [singleton method][2].
45
45
  - The name of an [instance method][3].
46
- - The name of a [Ruby file][4].
46
+ - The name of a [Ruby page][4].
47
47
  - An abbreviation of any of the above.
48
48
  - One of the [special names][5] `@help` or `@readme`.
49
49
 
@@ -196,19 +196,19 @@ Found no instance method name starting with '#nosuch'.
196
196
  Show names of all 10370 instance methods? (y or n): n
197
197
  ```
198
198
 
199
- ### Ruby 'File'
199
+ ### Ruby Page
200
200
 
201
201
  For a name beginning with `ruby:`,
202
- finds the names of ruby files beginning
202
+ finds the names of ruby pages beginning
203
203
  with that name.
204
204
 
205
- When exactly one such file name is found:
205
+ When exactly one such page name is found:
206
206
 
207
207
  - If the name is the exact name of the found name, opens its page:
208
208
 
209
209
  ```
210
210
  webri> ruby:operators
211
- Found one file name starting with 'operators'
211
+ Found one page name starting with 'operators'
212
212
  operators (syntax/operators_rdoc.html)
213
213
  ```
214
214
 
@@ -216,18 +216,18 @@ Found one file name starting with 'operators'
216
216
 
217
217
  ```
218
218
  webri> ruby:opera
219
- Found one file name starting with 'opera'
219
+ Found one page name starting with 'opera'
220
220
  operators (syntax/operators_rdoc.html)
221
221
  Open page syntax/operators_rdoc.html? (y or n): y
222
222
  Opening web page https://docs.ruby-lang.org/en/3.4/syntax/operators_rdoc.html.
223
223
 
224
224
  ```
225
225
 
226
- When multiple such file names are found offer to list the found names:
226
+ When multiple such page names are found offer to list the found names:
227
227
 
228
228
  ```
229
229
  webri> ruby:o
230
- Found 4 file names starting with 'o'.
230
+ Found 4 page names starting with 'o'.
231
231
  Show 4 names?' (y or n): y
232
232
  0: operators (syntax/operators_rdoc.html)
233
233
  1: option_dump (ruby/option_dump_md.html)
@@ -237,12 +237,12 @@ Type a number to choose, or Return to skip: 2
237
237
 
238
238
  ```
239
239
 
240
- When no such file name is found, offers to list all file names:
240
+ When no such page name is found, offers to list all page names:
241
241
 
242
242
  ```
243
243
  webri> ruby:nosuch
244
- Found no file name starting with 'nosuch'.
245
- Show names of all 83 files? (y or n): y
244
+ Found no page name starting with 'nosuch'.
245
+ Show names of all 83 pages? (y or n): y
246
246
  0: COPYING (COPYING.html)
247
247
  1: COPYING.ja (COPYING_ja.html)
248
248
  2: LEGAL (LEGAL.html)
@@ -335,6 +335,7 @@ Opening web page https://docs.ruby-lang.org/en/3.4/regexp/unicode_properties_rdo
335
335
  To display the WebRI help text, use the special name `@help`:
336
336
 
337
337
  ```
338
+ $ ruby bin/webri
338
339
  webri> @help
339
340
  Showing help.
340
341
  webri is a console application for displaying Ruby online HTML documentation.
@@ -347,6 +348,7 @@ For more information, see https://github.com/BurdetteLamar/webri/blob/main/READM
347
348
  Options:
348
349
  -i, --info Prints information about webri.
349
350
  -r, --release=RELEASE Sets the Ruby release to document.
351
+ --noreline Does not use Reline (helps testing).
350
352
  -n, --noop Does not actually open web pages.
351
353
  -h, --help Prints this help.
352
354
  -v, --version Prints the version of webri.
@@ -359,6 +361,14 @@ webri> @readme
359
361
  Opening web page https://github.com/BurdetteLamar/webri/blob/main/README.md.
360
362
  ```
361
363
 
364
+ ### Reline
365
+
366
+ `webri` uses [Reline](https://ruby.github.io/reline/Reline.html)
367
+ (on Linux, but not on other OS platforms).
368
+
369
+ Reline enables editing of text at the `webri` prompt (use left- and right-arrows),
370
+ and gives access to history (use up-arrow).
371
+
362
372
  ### Options
363
373
 
364
374
  Option `--info` prints information about WebRI,
@@ -374,7 +384,7 @@ Names:
374
384
  1364 class names
375
385
  1175 singleton_method names
376
386
  4407 instance_method names
377
- 81 file names
387
+ 81 page names
378
388
  ```
379
389
 
380
390
  Option `--release` sets the release of the documentation to be used.
@@ -389,7 +399,7 @@ Names:
389
399
  1262 class names
390
400
  1301 singleton_method names
391
401
  4397 instance_method names
392
- 73 file names
402
+ 73 page names
393
403
  $ webri --release=3.3 --info
394
404
  Ruby documentation release: '3.3'
395
405
  Ruby documentation URL: 'https://docs.ruby-lang.org/en/3.3/table_of_contents.html'
@@ -398,7 +408,7 @@ Names:
398
408
  1469 class names
399
409
  1270 singleton_method names
400
410
  4638 instance_method names
401
- 77 file names
411
+ 77 page names
402
412
  ```
403
413
 
404
414
  Issues a message if the given release is unknown:
@@ -422,6 +432,8 @@ Opening web page https://docs.ruby-lang.org/en/3.4/Array.html.
422
432
  Command: 'start https://docs.ruby-lang.org/en/3.4/Array.html'
423
433
  ```
424
434
 
435
+ Option `--noreline` blocks Reline behavior; see [Reline][6].
436
+
425
437
  Option `--help` prints the WebRI help text.
426
438
 
427
439
  Option `--version` prints the WebRI version.
@@ -452,5 +464,6 @@ to follow the [code of conduct](https://github.com/BurdetteLamar/webri/blob/mast
452
464
  [1]: rdoc-ref:README.md@Class+or+Module
453
465
  [2]: rdoc-ref:README.md@Singleton+Method
454
466
  [3]: rdoc-ref:README.md@Instance+Method
455
- [4]: rdoc-ref:README.md@Ruby+File
467
+ [4]: rdoc-ref:README.md@Ruby+Page
456
468
  [5]: rdoc-ref:README.md@Special+Names
469
+ [6]: rdoc-ref:README.md@Reline
data/bin/webri CHANGED
@@ -28,6 +28,9 @@ end
28
28
  parser.on('-r=RELEASE', '--release=RELEASE', 'Sets the Ruby release to document.') do |value|
29
29
  options[:release] = value
30
30
  end
31
+ parser.on('--noreline', 'Does not use Reline (helps testing).') do |value|
32
+ options[:noreline] = true
33
+ end
31
34
  parser.on('-n', '--noop', 'Does not actually open web pages.') do |value|
32
35
  options[:noop] = true
33
36
  end
data/lib/webri/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class WebRI
4
- VERSION = "1.0.1"
4
+ VERSION = "1.0.3"
5
5
  end
data/lib/webri.rb CHANGED
@@ -4,18 +4,16 @@ require 'rbconfig'
4
4
  require 'open-uri'
5
5
  require 'rexml'
6
6
  require 'cgi'
7
+ require 'reline'
7
8
 
8
9
  # TODO: Use reline.
9
10
  #
10
11
  # TODO: Subroutinize.
11
12
  # TODO: Make initialization faster.
12
13
 
13
- # TODO: Build test names from ruby-lang.org (not webri).
14
- #
15
14
  # TODO: Choose dynamically the test names (rather than fixed)?
16
- # TODO: Test methods with trailing special chars, and with all special chars
17
15
  # TODO: Test on Linux.
18
- # TODO: Test all releases.
16
+ # TODO: Test all releases(?).
19
17
  # TODO: Test all pages(?).
20
18
 
21
19
  # TODO: Make it work for naked method ('parse') or dotted method ('.parse').
@@ -40,6 +38,15 @@ class WebRI
40
38
  get_toc_html
41
39
  build_indexes
42
40
  print_info if @info
41
+ print @noreline
42
+ if os_type == :linux && !@noreline
43
+ repl_reline
44
+ else
45
+ repl_plain
46
+ end
47
+ end
48
+
49
+ def repl_plain # Read-evaluate-print loop, without Reline.
43
50
  while true
44
51
  $stdout.write('webri> ')
45
52
  $stdout.flush
@@ -54,6 +61,46 @@ class WebRI
54
61
  end
55
62
  end
56
63
 
64
+ def repl_reline # Read-evaluate-print loop, with Reline.
65
+ begin
66
+ stty_save = `stty -g`.chomp
67
+ rescue
68
+ end
69
+
70
+ begin
71
+ completion_words= []
72
+ @index_for_type.each_pair do |type, index|
73
+ if type == :page
74
+ completion_words += index.keys.map {|name| 'ruby:' + name }
75
+ else
76
+ completion_words += index.keys
77
+ end
78
+ end
79
+ Reline.completion_proc = proc { |word|
80
+ completion_words
81
+ }
82
+ while line = Reline.readline("webri> ", true)
83
+ case line.chomp
84
+ when 'exit'
85
+ exit 0
86
+ when ''
87
+ # NOOP
88
+ else
89
+ if line.split(' ').size > 1
90
+ puts "One name at a time, please."
91
+ next
92
+ end
93
+ show(line)
94
+ end
95
+ end
96
+ rescue Interrupt
97
+ puts '^C'
98
+ `stty #{stty_save}` if stty_save
99
+ exit 0
100
+ end
101
+ puts
102
+ end
103
+
57
104
  def set_doc_release
58
105
  supported_releases = []
59
106
  unsupported_releases = []
@@ -104,7 +151,7 @@ class WebRI
104
151
  class: {}, # Has both classes and modules.
105
152
  singleton_method: {},
106
153
  instance_method: {},
107
- file: {},
154
+ page: {},
108
155
  }
109
156
  # Iterate over the lines of the TOC page.
110
157
  lines = @toc_html.split("\n")
@@ -139,7 +186,7 @@ class WebRI
139
186
  end
140
187
  entry.paths.push(path) unless entry.paths.include?(path)
141
188
  when 'file'
142
- index = @index_for_type[:file]
189
+ index = @index_for_type[:page]
143
190
  if index.include?(full_name)
144
191
  entry = index[full_name]
145
192
  else
@@ -179,6 +226,7 @@ class WebRI
179
226
  def capture_options(options)
180
227
  @noop = options[:noop]
181
228
  @info = options[:info]
229
+ @noreline = options[:noreline]
182
230
  @doc_release = options[:release]
183
231
  end
184
232
 
@@ -277,7 +325,7 @@ class WebRI
277
325
  when %w[fatal fata fat fa f].include?(name)
278
326
  show_class(name, @index_for_type[:class])
279
327
  when name.start_with?('ruby:')
280
- show_file(name, @index_for_type[:file])
328
+ show_file(name, @index_for_type[:page])
281
329
  when name.start_with?('::')
282
330
  show_singleton_method(name, @index_for_type[:singleton_method])
283
331
  when name.start_with?('#')
@@ -342,11 +390,11 @@ class WebRI
342
390
  open_page(name, uri)
343
391
  end
344
392
 
345
- # Show file.
393
+ # Show page.
346
394
  def show_file(name, file_index)
347
395
  # Target page is a free-standing page such as 'COPYING'.
348
396
  name = name.sub(/^ruby:/, '') # Discard leading 'ruby:'
349
- all_entries = @index_for_type[:file]
397
+ all_entries = @index_for_type[:page]
350
398
  all_choices = FileEntry.choices(all_entries)
351
399
  # Find entries whose names that start with name.
352
400
  selected_entries = all_entries.select do |key, value|
@@ -364,7 +412,7 @@ class WebRI
364
412
  selected_choices = FileEntry.choices(selected_entries)
365
413
  choice = selected_choices.keys.first
366
414
  path = selected_choices.values.first
367
- puts "Found one file name starting with '#{name}'\n #{choice}"
415
+ puts "Found one page name starting with '#{name}'\n #{choice}"
368
416
  full_name = FileEntry.full_name_for_choice(choice)
369
417
  if name != full_name
370
418
  message = "Open page #{path}?"
@@ -372,15 +420,15 @@ class WebRI
372
420
  end
373
421
  path
374
422
  when 0
375
- puts "Found no file name starting with '#{name}'."
376
- message = "Show names of all #{all_choices.size} files?"
423
+ puts "Found no page name starting with '#{name}'."
424
+ message = "Show names of all #{all_choices.size} pages?"
377
425
  return unless get_boolean_answer(message)
378
426
  key = get_choice(all_choices.keys)
379
427
  return if key.nil?
380
428
  path = all_choices[key]
381
429
  else
382
430
  selected_choices = FileEntry.choices(selected_entries)
383
- puts "Found #{selected_choices.size} file names starting with '#{name}'."
431
+ puts "Found #{selected_choices.size} page names starting with '#{name}'."
384
432
  message = "Show #{selected_choices.size} names?'"
385
433
  return unless get_boolean_answer(message)
386
434
  key = get_choice(selected_choices.keys)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webri
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - BurdetteLamar
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-06-13 00:00:00.000000000 Z
10
+ date: 2025-06-16 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: Command-line utility for displaying Ruby online documentation
13
13
  email: