webri 2.1.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 +6 -33
- data/lib/webri/version.rb +1 -1
- data/lib/webri.rb +127 -18
- 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
|
@@ -7,55 +7,28 @@ require_relative '../lib/webri/version'
|
|
|
7
7
|
require_relative '../lib/webri'
|
|
8
8
|
require_relative '../lib/scraper'
|
|
9
9
|
|
|
10
|
-
NAME = <<EOT
|
|
11
|
-
|
|
12
|
-
Name:
|
|
13
|
-
|
|
14
|
-
There are four types of names, as determined by prefixes:
|
|
15
|
-
|
|
16
|
-
- Class or module: starts with a capital letter; e.g., 'Array'.
|
|
17
|
-
- Singleton method: starts with '::'; e.g., '::new'.
|
|
18
|
-
- Instance method: starts with '#' (escaped as '\\#', if your shell requires it);
|
|
19
|
-
e.g., '#inspect'.
|
|
20
|
-
- Ruby file: starts with 'ruby:'; e.g., 'ruby:syntax_rdoc'.
|
|
21
|
-
|
|
22
|
-
Name handling:
|
|
23
|
-
|
|
24
|
-
- If name is a complete name of its type (and not also the start of other such names),
|
|
25
|
-
webri opens the page for that name.
|
|
26
|
-
- If name is incomplete, but is the start of only one name of its type,
|
|
27
|
-
webri asks whether to open the page for that name.
|
|
28
|
-
- If name is incomplete, but is the start of multiple names of its type,
|
|
29
|
-
webri displays those names and lets you choose.
|
|
30
|
-
- If name is not a valid name of its type, webri asks whether show such names.
|
|
31
|
-
- If name is not valid at all (i.e., does not start with any of the prefixes above),
|
|
32
|
-
webri prints an error message.
|
|
33
|
-
|
|
34
|
-
EOT
|
|
35
10
|
options = {}
|
|
36
11
|
|
|
37
12
|
parser = OptionParser.new
|
|
38
13
|
|
|
39
14
|
parser.version = WebRI::VERSION
|
|
40
15
|
parser.banner = <<-BANNER
|
|
41
|
-
|
|
42
|
-
|
|
16
|
+
Console application #{WebRI.webri} displays Ruby online HTML documentation
|
|
17
|
+
in the default web browser.
|
|
43
18
|
|
|
44
|
-
Usage: #{
|
|
19
|
+
Usage: #{WebRI.webri} [options] #{WebRI.variable('name')}
|
|
45
20
|
|
|
46
21
|
BANNER
|
|
47
22
|
|
|
48
23
|
RELEASES = Scraper.scrapers.keys.inspect
|
|
49
24
|
|
|
50
25
|
parser.separator("Options:")
|
|
51
|
-
release_description = <<-EOT
|
|
52
26
|
|
|
53
|
-
EOT
|
|
54
27
|
parser.on('-r', '--release RELEASE',
|
|
55
28
|
"Specify documentation release (one of #{RELEASES}).") do |value|
|
|
56
29
|
options[:release_name] = value
|
|
57
30
|
end
|
|
58
|
-
parser.on('-i', '--info',
|
|
31
|
+
parser.on('-i', '--info', "Print information about #{WebRI.webri}.") do
|
|
59
32
|
options[:info] = true
|
|
60
33
|
end
|
|
61
34
|
parser.on('--noreline', 'Do not use Reline (useful for testing).') do |value|
|
|
@@ -68,11 +41,11 @@ parser.on('-h', '--help', 'Print this help.') do
|
|
|
68
41
|
puts parser
|
|
69
42
|
exit
|
|
70
43
|
end
|
|
71
|
-
parser.on('-v', '--version',
|
|
44
|
+
parser.on('-v', '--version', "Print the version of #{WebRI.webri}.") do
|
|
72
45
|
puts WebRI::VERSION
|
|
73
46
|
exit
|
|
74
47
|
end
|
|
75
|
-
parser.separator(
|
|
48
|
+
parser.separator(WebRI::HELP)
|
|
76
49
|
|
|
77
50
|
parser.parse!
|
|
78
51
|
|
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'
|
|
@@ -104,7 +106,7 @@ class WebRI
|
|
|
104
106
|
|
|
105
107
|
def repl_plain # Read-evaluate-print loop, without Reline.
|
|
106
108
|
while true
|
|
107
|
-
$stdout.write(
|
|
109
|
+
$stdout.write(WebRI.prompt)
|
|
108
110
|
$stdout.flush
|
|
109
111
|
response = $stdin.gets.chomp
|
|
110
112
|
exit if response == 'exit'
|
|
@@ -132,7 +134,7 @@ class WebRI
|
|
|
132
134
|
Reline.completion_proc = proc { |word|
|
|
133
135
|
completion_words
|
|
134
136
|
}
|
|
135
|
-
while line = Reline.readline(
|
|
137
|
+
while line = Reline.readline(WebRI.prompt, true)
|
|
136
138
|
case line.chomp
|
|
137
139
|
when 'exit'
|
|
138
140
|
exit 0
|
|
@@ -425,7 +427,8 @@ class WebRI
|
|
|
425
427
|
until range.include?(index)
|
|
426
428
|
choices.each_with_index do |choice, i|
|
|
427
429
|
s = "%6d" % i
|
|
428
|
-
|
|
430
|
+
token = WebRI.token(choice)
|
|
431
|
+
puts " #{s}: #{token}"
|
|
429
432
|
end
|
|
430
433
|
while true
|
|
431
434
|
message = if required
|
|
@@ -535,30 +538,136 @@ class WebRI
|
|
|
535
538
|
end
|
|
536
539
|
|
|
537
540
|
def help(response)
|
|
538
|
-
|
|
539
|
-
|
|
541
|
+
puts WebRI::HELP
|
|
542
|
+
return
|
|
543
|
+
puts <<HELP
|
|
540
544
|
Type:
|
|
541
|
-
- 'exit' to exit webri.
|
|
545
|
+
- #{WebRI.tokenq('exit')} to exit #{WebRI.webri}.
|
|
542
546
|
- #{CLASS.capitalize} name (full or partial) to see #{CLASS} names:
|
|
543
|
-
- 'Array' (full name, not the start of other names).
|
|
544
|
-
- 'Ar' (partial name).
|
|
547
|
+
- #{WebRI.tokenq('Array')} (full name, not the start of other names).
|
|
548
|
+
- #{WebRI.tokenq('Ar')} (partial name).
|
|
545
549
|
- #{SINGLETON.capitalize} name (full or partial) to see #{SINGLETON} names:
|
|
546
|
-
- '::tanh' (full name, not the start of other names).
|
|
547
|
-
- '::ta' (partial name).
|
|
550
|
+
- #{WebRI.tokenq('::tanh')} (full name, not the start of other names).
|
|
551
|
+
- #{WebRI.tokenq('::ta')} (partial name).
|
|
548
552
|
- #{INSTANCE.capitalize} name (full or partial) to see #{INSTANCE} names:
|
|
549
|
-
- '#query=' (full name, not the start of other names).
|
|
550
|
-
- '#qu' (partial name).
|
|
553
|
+
- #{WebRI.tokenq('#query=')} (full name, not the start of other names).
|
|
554
|
+
- #{WebRI.tokenq('#qu')} (partial name).
|
|
551
555
|
- #{FILE.capitalize}name (full or partial) to see #{FILE} names:
|
|
552
|
-
- 'ruby:syntax_rdoc' (full name, not the start of other names).
|
|
553
|
-
- '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).
|
|
554
558
|
HELP
|
|
555
|
-
else
|
|
556
|
-
p response
|
|
557
|
-
end
|
|
558
559
|
end
|
|
559
560
|
|
|
560
561
|
def help_main
|
|
561
562
|
|
|
562
563
|
end
|
|
563
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
|
+
|
|
564
673
|
end
|