open_gemdocs 0.1.0 → 0.2.1

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: 0f80355f3c2bf3eb6fccbfae95a5bcf2306493d19680820f74c30ebc8d1fbe25
4
- data.tar.gz: 3624db7fb13cb8784e5db06f2a6ebf0a21858cec666b79efafa4daa5b38104e0
3
+ metadata.gz: caa6b9319f8f30e6cd853d913be8d48cdbf7391795141d427f5a8fcbb281857c
4
+ data.tar.gz: b7645ceac6e716e4cc04f5a4fc5e773246d461228c3573b7a0edc1765c50d56a
5
5
  SHA512:
6
- metadata.gz: 460e8b98333345f461e962e14c739d3f88b202b6a24e897d91050e05d2bc9f6f41ea746bb95a689c61577dafe2b3590cb68baaf83641755fa8ec3660972af10d
7
- data.tar.gz: f13cffee516d76f47f7a1673fa68fee48e9308b286155cc3eb900d833692baa46a27ada5ecd9c48302bbad52f304de192085c105a04e1e343712d86294ced34a
6
+ metadata.gz: da408504c8dd77206dfe9b277887514e5c46ebe5004ef3e3b629c8163d4c3e119758c66e859a07a312150ec98013cdecc1a98bd042b25851429d9aa61cedd318
7
+ data.tar.gz: 951fb401b1bc62bd133bb96bfe2cff936eef72acf3852ede3fc111892e8cd79b5a24088bc7465195d91b595e1bba93e5c02838f929041d1562a5b0d45653643e
checksums.yaml.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -1,6 +1,14 @@
1
1
  # OpenGemdocs
2
2
 
3
- This is a simple command line tool that helps open gem documentation on https://gemdocs.org.
3
+ This is a simple command line tool that helps open gem documentation. There are two documentation sources this gem supports.
4
+
5
+ 1. local gems served with the yarn gem
6
+ 2. [https://gemdocs.org](https://gemdocs.org) - a good ruby gem documentation host
7
+
8
+ * If ran from a directory with a Gemfile.lock, it will open the documentation for the version specified in Gemfile.lock. When using the online source, you can specify `--latest` or `--version` options.
9
+ * Defaults to open the latest version of the documentation if not `--local` or a `Gemfile.lock` is not found in the current directory.
10
+ * Can specify a version of the docs to view
11
+ * When ran with `--local`, it will either serve docs for all gems you have installed or the versions specified in your Gemfile.
4
12
 
5
13
  ## Installation
6
14
 
@@ -20,15 +28,39 @@ gem install open_gemdocs
20
28
 
21
29
  Currently, this only works on Macs because of the `open` command. It opens the documentation for a gem in your default web browser.
22
30
 
23
- For terminal use:
31
+ To see the available options.
32
+ ```bash
33
+ open-gem-docs --help
34
+ ```
24
35
 
36
+ ### Example usage
37
+ If you are in a directory with a Gemfile.lock, it will open the documentation for the version of the gem you are using unless you specify `--latest` or `--version` options.
38
+
39
+ If you are not in a directory with a Gemfile.lock, it will open the latest version of the documentation.
25
40
  ```bash
26
- open_gemdocs --help
41
+ open-gem-docs rspec
27
42
  ```
43
+ (Assuming you are in a directory with a Gemfile.lock, it will open the rspec docs for the version you are using.)
28
44
 
29
- To see the available options.
45
+ Open a specific version (regardless of what is in your Gemfile.lock)
46
+ ```bash
47
+ open-gem-docs -v 3.12.0 rspec
48
+ ```
30
49
 
31
- If you pass in the name of a gem from a directory that contains a Gemfile.lock file, it will determine what version of the gem you are using when it opens the online documentation.
50
+ Open the latest version of the documentation
51
+ ```bash
52
+ open-gem-docs --latest rspec
53
+ ```
54
+
55
+ To use a local documentation server. Run the following command from a directory where Gemfile.lock exists. This will serves the documentation for your currently installed gems.
56
+ ```bash
57
+ open-gem-docs --local
58
+ ```
59
+
60
+ You can also jump directly to a local doc gem page:
61
+ ```bash
62
+ open-gem-docs --local rspec
63
+ ```
32
64
 
33
65
  ## Development
34
66
 
@@ -0,0 +1 @@
1
+ d38b05b2644370819c8ace560260816630b1c77dba752edeab3f4a8fc7d32dcf914582ff054a48ff61d6f904a513f46279273eaf3e686611df51724dc94ad1ed
@@ -0,0 +1 @@
1
+ 47c51e49929fa17823bb73e851d2647a3cba1f2e70bba6da9b23cf9881a0ad96add9d6b585bd9d4594383f9ee965e756fc739b452f38033c41c1b1ed22af8458
data/exe/open-gem-docs CHANGED
@@ -12,11 +12,14 @@ options = {}
12
12
  OptionParser.new do |opts|
13
13
  opts.banner = 'Usage: open-gem-docs [options] <gem_name>'
14
14
 
15
+ opts.on('--local', 'Use local documentation') do
16
+ options[:local] = true
17
+ end
15
18
  opts.on('-v', '--version VERSION', 'Specify the version') do |version|
16
19
  options[:version] = version
17
20
  end
18
21
 
19
- opts.on('-l', '--latest', 'Use the latest version') do
22
+ opts.on('--latest', 'Use the latest version') do
20
23
  options[:latest] = true
21
24
  end
22
25
 
@@ -24,10 +27,34 @@ OptionParser.new do |opts|
24
27
  puts opts
25
28
  exit
26
29
  end
30
+
31
+ opts.on('-s', '--stop', 'stops the yarn server') do
32
+ OpenGemdocs::Yard.stop_server
33
+ exit
34
+ end
27
35
  end.parse!
28
36
 
29
37
  begin
30
- OpenGemdocs::Browser.new(gem_name: ARGV[0], version: options[:version], use_latest: options[:latest]).open_browser
38
+ if options[:local]
39
+ unless OpenGemdocs::Yard.yard_installed?
40
+ puts 'To use the local documentation, you need to install Yard.'
41
+ puts 'Please install yard with `gem install yard`.'
42
+ puts 'Would you like to install it now? (y/n)'
43
+ case gets.chomp.downcase
44
+ when 'y'
45
+ system('gem install yard')
46
+ puts 'Yard installed successfully.'
47
+ puts 'Now you can use the local documentation with `open-gem-docs --local <gem_name>`'
48
+ else
49
+ puts 'Yard is required to use the local documentation.'
50
+ puts 'Please install it and try again.'
51
+ end
52
+ exit 0
53
+ end
54
+ OpenGemdocs::Yard.browse_gem(ARGV[0])
55
+ else
56
+ OpenGemdocs::Browser.new(gem_name: ARGV[0], version: options[:version], use_latest: options[:latest]).open_browser
57
+ end
31
58
  rescue OpenGemdocs::Error, ArgumentError => e
32
59
  puts e.message
33
60
  exit 1
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenGemdocs
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.1"
5
5
  end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenGemdocs
4
+ module Yard
5
+ extend self
6
+ SERVER_COMMAND = 'yard server --daemon'
7
+
8
+ def browse_gem(gem_name)
9
+ if server_running?
10
+ puts "Yard server is already running. Opening browser..."
11
+ system("open http://localhost:8808/docs/#{gem_name}")
12
+ else
13
+ puts "Starting Yard server in the background..."
14
+ start_yard_server
15
+ sleep 2 # Give the server some time to start
16
+ system("open http://localhost:8808/docs/#{gem_name}")
17
+ end
18
+ puts " When you're done, remember to stop the server with `open-gem-docs --stop`"
19
+ end
20
+
21
+ def yard_installed?
22
+ `gem list yard -i`.strip == 'true'
23
+ end
24
+
25
+ def start_yard_server
26
+ if File.exist?('Gemfile.lock')
27
+ `#{SERVER_COMMAND} --gemfile`
28
+ else
29
+ `#{SERVER_COMMAND} --gems`
30
+ end
31
+ end
32
+
33
+ def server_running? = find_yard_pids.any?
34
+
35
+ def find_yard_pids
36
+ # Find pids bound to port 8808
37
+ `lsof -i TCP:8808 | grep -E "^ruby.*:8808"`.strip.split("\n").map { |line| line.split(/\s+/)[1] }
38
+ end
39
+
40
+ def stop_server
41
+ yard_pids = find_yard_pids
42
+ if yard_pids.any?
43
+ puts "Stopping Yard server processes: #{yard_pids.join(', ')}"
44
+ `kill #{yard_pids.join(' ')}`
45
+ puts "Yard server processes stopped."
46
+ else
47
+ puts "No Yard server processes found to stop"
48
+ end
49
+ end
50
+ end
51
+ end
data/lib/open_gemdocs.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative 'open_gemdocs/version'
4
4
  require_relative 'open_gemdocs/browser'
5
+ require_relative 'open_gemdocs/yard'
5
6
 
6
7
  module OpenGemdocs
7
8
  class Error < StandardError; end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open_gemdocs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean McCleary
@@ -52,10 +52,13 @@ files:
52
52
  - Rakefile
53
53
  - certs/mrinterweb.pem
54
54
  - checksums/open_gemdocs-0.1.0.gem.sha512
55
+ - checksums/open_gemdocs-0.2.0.gem.sha512
56
+ - checksums/open_gemdocs-0.2.1.gem.sha512
55
57
  - exe/open-gem-docs
56
58
  - lib/open_gemdocs.rb
57
59
  - lib/open_gemdocs/browser.rb
58
60
  - lib/open_gemdocs/version.rb
61
+ - lib/open_gemdocs/yard.rb
59
62
  - sig/open_gemdocs.rbs
60
63
  homepage: https://github.com/mrinterweb/open_gemdocs
61
64
  licenses:
metadata.gz.sig CHANGED
Binary file