webri 2.0.0 → 2.2.0
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 +4 -4
- data/exe/webri +17 -10
- data/lib/webri/version.rb +1 -1
- data/lib/webri.rb +137 -21
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f084a9f5fdfc0a04bc93e780f7a73c4fc371c294c99f10290c22174928f34330
|
|
4
|
+
data.tar.gz: 789d05f78b88eafca71373bf3db93ea911bbab28bb34a3a0a180e21054198c8d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f85eddc468ac54ba0bab2d99330442621a365384c5ace19f7679fc67a4d585e5101feb7303f5db37490fefb2082d588f2cd856ba03068918e5e3371a1af3e3eb
|
|
7
|
+
data.tar.gz: b39d8dbde0d310880b6a62383efadaf8509a80c51969c25bcbe64e445e7fa22296abf443b5c5aae13d5d5474b22a6c2cddc5619d6427ffc4935000e04ac76475
|
data/exe/webri
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
require 'optparse'
|
|
6
6
|
require_relative '../lib/webri/version'
|
|
7
7
|
require_relative '../lib/webri'
|
|
8
|
+
require_relative '../lib/scraper'
|
|
8
9
|
|
|
9
10
|
options = {}
|
|
10
11
|
|
|
@@ -12,17 +13,22 @@ parser = OptionParser.new
|
|
|
12
13
|
|
|
13
14
|
parser.version = WebRI::VERSION
|
|
14
15
|
parser.banner = <<-BANNER
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
Console application #{WebRI.webri} displays Ruby online HTML documentation
|
|
17
|
+
in the default web browser.
|
|
17
18
|
|
|
18
|
-
Usage: #{
|
|
19
|
-
|
|
20
|
-
For more information, see https://github.com/BurdetteLamar/webri/blob/main/README.md.
|
|
19
|
+
Usage: #{WebRI.webri} [options] #{WebRI.variable('name')}
|
|
21
20
|
|
|
22
21
|
BANNER
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
RELEASES = Scraper.scrapers.keys.inspect
|
|
24
|
+
|
|
25
|
+
parser.separator("Options:")
|
|
26
|
+
|
|
27
|
+
parser.on('-r', '--release RELEASE',
|
|
28
|
+
"Specify documentation release (one of #{RELEASES}).") do |value|
|
|
29
|
+
options[:release_name] = value
|
|
30
|
+
end
|
|
31
|
+
parser.on('-i', '--info', "Print information about #{WebRI.webri}.") do
|
|
26
32
|
options[:info] = true
|
|
27
33
|
end
|
|
28
34
|
parser.on('--noreline', 'Do not use Reline (useful for testing).') do |value|
|
|
@@ -35,12 +41,13 @@ parser.on('-h', '--help', 'Print this help.') do
|
|
|
35
41
|
puts parser
|
|
36
42
|
exit
|
|
37
43
|
end
|
|
38
|
-
parser.on('-v', '--version',
|
|
44
|
+
parser.on('-v', '--version', "Print the version of #{WebRI.webri}.") do
|
|
39
45
|
puts WebRI::VERSION
|
|
40
46
|
exit
|
|
41
47
|
end
|
|
48
|
+
parser.separator(WebRI::HELP)
|
|
42
49
|
|
|
43
50
|
parser.parse!
|
|
44
51
|
|
|
45
|
-
|
|
46
|
-
WebRI.new(
|
|
52
|
+
name = ARGV[0]
|
|
53
|
+
WebRI.new(name, options)
|
data/lib/webri/version.rb
CHANGED
data/lib/webri.rb
CHANGED
|
@@ -48,7 +48,9 @@ class WebRI
|
|
|
48
48
|
# Site of the official documentation.
|
|
49
49
|
DOC_SITE = 'https://docs.ruby-lang.org/en/'
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
def self.prompt
|
|
52
|
+
"(Type #{WebRI.tokenq('?')} for help, #{WebRI.tokenq('exit')} to exit) #{self.webri}> "
|
|
53
|
+
end
|
|
52
54
|
|
|
53
55
|
CLASS = 'class/module'
|
|
54
56
|
SINGLETON = 'singleton method'
|
|
@@ -61,22 +63,28 @@ class WebRI
|
|
|
61
63
|
:href_for_singleton_method_name,
|
|
62
64
|
:href_for_instance_method_name
|
|
63
65
|
|
|
64
|
-
def initialize(
|
|
65
|
-
self.release_name = set_doc_release(release_name)
|
|
66
|
+
def initialize(name = nil, options = {})
|
|
66
67
|
capture_options(options)
|
|
68
|
+
self.release_name = set_doc_release(@release_name)
|
|
67
69
|
# data_file_path = File.join('data', self.release_name + '.json')
|
|
68
70
|
data_file_path = File.expand_path("../data/#{self.release_name}.json", __dir__)
|
|
69
71
|
json = open(data_file_path).read
|
|
70
72
|
@data = JSON.parse(json, create_additions: true)
|
|
71
73
|
make_groups
|
|
72
74
|
print_info if @info
|
|
73
|
-
if
|
|
75
|
+
if name
|
|
76
|
+
do_name(name)
|
|
77
|
+
elsif os_type == :linux && !@noreline
|
|
74
78
|
repl_reline
|
|
75
79
|
else
|
|
76
80
|
repl_plain
|
|
77
81
|
end
|
|
78
82
|
end
|
|
79
83
|
|
|
84
|
+
def do_name(name)
|
|
85
|
+
show(name)
|
|
86
|
+
end
|
|
87
|
+
|
|
80
88
|
def make_groups
|
|
81
89
|
self.href_for_class_name = {}
|
|
82
90
|
self.href_for_file_name = {}
|
|
@@ -98,7 +106,7 @@ class WebRI
|
|
|
98
106
|
|
|
99
107
|
def repl_plain # Read-evaluate-print loop, without Reline.
|
|
100
108
|
while true
|
|
101
|
-
|
|
109
|
+
$stdout.write(WebRI.prompt)
|
|
102
110
|
$stdout.flush
|
|
103
111
|
response = $stdin.gets.chomp
|
|
104
112
|
exit if response == 'exit'
|
|
@@ -126,7 +134,7 @@ class WebRI
|
|
|
126
134
|
Reline.completion_proc = proc { |word|
|
|
127
135
|
completion_words
|
|
128
136
|
}
|
|
129
|
-
while line = Reline.readline(
|
|
137
|
+
while line = Reline.readline(WebRI.prompt, true)
|
|
130
138
|
case line.chomp
|
|
131
139
|
when 'exit'
|
|
132
140
|
exit 0
|
|
@@ -191,6 +199,7 @@ class WebRI
|
|
|
191
199
|
@noop = options[:noop]
|
|
192
200
|
@info = options[:info]
|
|
193
201
|
@noreline = options[:noreline]
|
|
202
|
+
@release_name = options[:release_name]
|
|
194
203
|
end
|
|
195
204
|
|
|
196
205
|
class Entry
|
|
@@ -418,7 +427,8 @@ class WebRI
|
|
|
418
427
|
until range.include?(index)
|
|
419
428
|
choices.each_with_index do |choice, i|
|
|
420
429
|
s = "%6d" % i
|
|
421
|
-
|
|
430
|
+
token = WebRI.token(choice)
|
|
431
|
+
puts " #{s}: #{token}"
|
|
422
432
|
end
|
|
423
433
|
while true
|
|
424
434
|
message = if required
|
|
@@ -528,30 +538,136 @@ class WebRI
|
|
|
528
538
|
end
|
|
529
539
|
|
|
530
540
|
def help(response)
|
|
531
|
-
|
|
532
|
-
|
|
541
|
+
puts WebRI::HELP
|
|
542
|
+
return
|
|
543
|
+
puts <<HELP
|
|
533
544
|
Type:
|
|
534
|
-
- 'exit' to exit webri.
|
|
545
|
+
- #{WebRI.tokenq('exit')} to exit #{WebRI.webri}.
|
|
535
546
|
- #{CLASS.capitalize} name (full or partial) to see #{CLASS} names:
|
|
536
|
-
- 'Array' (full name, not the start of other names).
|
|
537
|
-
- 'Ar' (partial name).
|
|
547
|
+
- #{WebRI.tokenq('Array')} (full name, not the start of other names).
|
|
548
|
+
- #{WebRI.tokenq('Ar')} (partial name).
|
|
538
549
|
- #{SINGLETON.capitalize} name (full or partial) to see #{SINGLETON} names:
|
|
539
|
-
- '::tanh' (full name, not the start of other names).
|
|
540
|
-
- '::ta' (partial name).
|
|
550
|
+
- #{WebRI.tokenq('::tanh')} (full name, not the start of other names).
|
|
551
|
+
- #{WebRI.tokenq('::ta')} (partial name).
|
|
541
552
|
- #{INSTANCE.capitalize} name (full or partial) to see #{INSTANCE} names:
|
|
542
|
-
- '#query=' (full name, not the start of other names).
|
|
543
|
-
- '#qu' (partial name).
|
|
553
|
+
- #{WebRI.tokenq('#query=')} (full name, not the start of other names).
|
|
554
|
+
- #{WebRI.tokenq('#qu')} (partial name).
|
|
544
555
|
- #{FILE.capitalize}name (full or partial) to see #{FILE} names:
|
|
545
|
-
- 'ruby:syntax_rdoc' (full name, not the start of other names).
|
|
546
|
-
- 'ruby:syntax' (partial name).
|
|
556
|
+
- #{WebRI.tokenq('ruby:syntax_rdoc')} (full name, not the start of other names).
|
|
557
|
+
- #{WebRI.tokenq('ruby:syntax')} (partial name).
|
|
547
558
|
HELP
|
|
548
|
-
else
|
|
549
|
-
p response
|
|
550
|
-
end
|
|
551
559
|
end
|
|
552
560
|
|
|
553
561
|
def help_main
|
|
554
562
|
|
|
555
563
|
end
|
|
556
564
|
|
|
565
|
+
ANSI_COLOR = {
|
|
566
|
+
black: 30,
|
|
567
|
+
red: 31,
|
|
568
|
+
green: 32,
|
|
569
|
+
yellow: 33,
|
|
570
|
+
blue: 34,
|
|
571
|
+
magenta: 35,
|
|
572
|
+
cyan: 36,
|
|
573
|
+
white: 37,
|
|
574
|
+
bright_black: 90,
|
|
575
|
+
bright_red: 91,
|
|
576
|
+
bright_green: 92,
|
|
577
|
+
bright_yellow: 93,
|
|
578
|
+
bright_blue: 94,
|
|
579
|
+
bright_magenta: 95,
|
|
580
|
+
bright_cyan: 96,
|
|
581
|
+
bright_white: 97,
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
def self.ansi_color(s, color)
|
|
585
|
+
return s unless $stdout.tty?
|
|
586
|
+
"\e[#{ANSI_COLOR[color]}m#{s}\e[0m"
|
|
587
|
+
end
|
|
588
|
+
|
|
589
|
+
def self.webri
|
|
590
|
+
self.ansi_color('webri', :blue)
|
|
591
|
+
end
|
|
592
|
+
|
|
593
|
+
def self.variable(s)
|
|
594
|
+
self.ansi_color(s, :yellow)
|
|
595
|
+
end
|
|
596
|
+
|
|
597
|
+
def self.string(s)
|
|
598
|
+
self.ansi_color("'#{s}'", :green)
|
|
599
|
+
end
|
|
600
|
+
|
|
601
|
+
def self.token(s)
|
|
602
|
+
color = case s
|
|
603
|
+
when /^[A-Z]/
|
|
604
|
+
:bright_blue
|
|
605
|
+
when /^::/
|
|
606
|
+
:bright_yellow
|
|
607
|
+
when /^#/
|
|
608
|
+
:bright_green
|
|
609
|
+
when /^ruby:/
|
|
610
|
+
:bright_red
|
|
611
|
+
else
|
|
612
|
+
:bright_cyan
|
|
613
|
+
end
|
|
614
|
+
self.ansi_color("#{s}", color)
|
|
615
|
+
end
|
|
616
|
+
|
|
617
|
+
def WebRI.tokenq(s)
|
|
618
|
+
"'" + WebRI.token("#{s}") + "'"
|
|
619
|
+
end
|
|
620
|
+
|
|
621
|
+
def self.file_name(s)
|
|
622
|
+
self.ansi_color("#{s}", :red)
|
|
623
|
+
end
|
|
624
|
+
|
|
625
|
+
def self.singleton_method_name(s)
|
|
626
|
+
self.ansi_color("#{s}", :magenta)
|
|
627
|
+
end
|
|
628
|
+
|
|
629
|
+
def self.instance_method_name(s)
|
|
630
|
+
self.ansi_color("#{s}", :cyan)
|
|
631
|
+
end
|
|
632
|
+
|
|
633
|
+
def self.class_name(s)
|
|
634
|
+
self.ansi_color("#{s}", :bright_blue)
|
|
635
|
+
end
|
|
636
|
+
|
|
637
|
+
HELP = <<EOT
|
|
638
|
+
|
|
639
|
+
There are four types of #{WebRI.variable('name')}, as determined by prefixes:
|
|
640
|
+
|
|
641
|
+
|------------------|----------------|--------------------|
|
|
642
|
+
| Type | Starts With | Example |
|
|
643
|
+
|------------------|----------------|--------------------|
|
|
644
|
+
| Class/module | Capital letter | #{WebRI.tokenq('Array')} |
|
|
645
|
+
| Singleton method | #{WebRI.tokenq('::')} | #{WebRI.tokenq('::new')} |
|
|
646
|
+
| Instance method | #{WebRI.tokenq('#')} | #{WebRI.tokenq('#inspect')} |
|
|
647
|
+
| Ruby file | #{WebRI.tokenq('ruby:')} | #{WebRI.tokenq('ruby:syntax_rdoc')} |
|
|
648
|
+
|------------------|----------------|--------------------|
|
|
649
|
+
|
|
650
|
+
Note: On the command-line, the instance method prefix should be escaped as #{WebRI.string('\\#')} if your shell requires it.
|
|
651
|
+
|
|
652
|
+
Name handling:
|
|
653
|
+
|
|
654
|
+
- If #{WebRI.variable('name')} is exactly a name of its type (but not the beginning of other such names),
|
|
655
|
+
#{WebRI.webri} opens the page for that name.
|
|
656
|
+
Examples: #{WebRI.tokenq('Array')}, #{WebRI.tokenq('::trap')}, #{WebRI.tokenq('#xmlschema')}, #{WebRI.tokenq('ruby:syntax_rdoc')}.
|
|
657
|
+
- If #{WebRI.variable('name')} is the beginning of exactly one name of its type,
|
|
658
|
+
#{WebRI.webri} asks whether to open the page for that name.
|
|
659
|
+
Examples: #{WebRI.tokenq('Arra')}, #{WebRI.tokenq('::tra')}, #{WebRI.tokenq('#xmlschem')}, #{WebRI.tokenq('ruby:syntax_')}.
|
|
660
|
+
- If #{WebRI.variable('name')} is the beginning of multiple names of its type,
|
|
661
|
+
#{WebRI.webri} displays those names and lets you choose.
|
|
662
|
+
Examples: #{WebRI.tokenq('A')}, #{WebRI.tokenq('::t')}, #{WebRI.tokenq('#')}, #{WebRI.tokenq('ruby:s')}.
|
|
663
|
+
- If #{WebRI.variable('name')} is not a valid name of its type,
|
|
664
|
+
#{WebRI.webri} asks whether show such names.
|
|
665
|
+
Examples: #{WebRI.tokenq('Xyzzy')}, #{WebRI.tokenq('::xyzzy')}, #{WebRI.tokenq('#xyzzy')}, #{WebRI.tokenq('ruby:xyzzy')}.
|
|
666
|
+
- If #{WebRI.variable('name')} is not valid at all (i.e., does not start with any of the prefixes above),
|
|
667
|
+
#{WebRI.webri} prints an error message.
|
|
668
|
+
Examples: #{WebRI.tokenq('nosuch')}, #{WebRI.tokenq('$foo')}, #{WebRI.tokenq('%Bar')}.
|
|
669
|
+
|
|
670
|
+
EOT
|
|
671
|
+
|
|
672
|
+
|
|
557
673
|
end
|