History

Improve 'docs:list' command

Ref #25.

Thibaut Courouble committed 10 years ago

Commit 4f3ea921 parent b04dba04 files · +29 −6Browse files

Unified · Split

4 files
  1. Gemfile +1 −0
  2. Gemfile.lock +13 −0
  3. lib/docs/core/doc.rb +4 −0
  4. lib/tasks/docs.thor +11 −6
Gemfile+1−0
@@ -34,6 +34,7 @@ group :docs do · 33 unmodified lines
34 gem 'html-pipeline'34 gem 'html-pipeline'
35 gem 'progress_bar', require: false35 gem 'progress_bar', require: false
36 gem 'unix_utils', require: false36 gem 'unix_utils', require: false
37 gem 'tty-pager', require: false
37end38end
38 39
39group :test do40group :test do
Gemfile.lock+13−0
@@ -78,6 +78,12 @@ GEM · 77 unmodified lines
78 thor (0.19.1)78 thor (0.19.1)
79 thread_safe (0.3.5)79 thread_safe (0.3.5)
80 tilt (2.0.2)80 tilt (2.0.2)
81 tty-pager (0.3.0)
82 tty-screen (~> 0.4.0)
83 tty-which (~> 0.1.0)
84 verse (~> 0.4.0)
85 tty-screen (0.4.3)
86 tty-which (0.1.0)
81 typhoeus (0.8.0)87 typhoeus (0.8.0)
82 ethon (>= 0.8.0)88 ethon (>= 0.8.0)
83 tzinfo (1.2.2)89 tzinfo (1.2.2)
@@ -85,7 +91,10 @@ GEM · 1 unmodified line
85 uglifier (2.7.2)91 uglifier (2.7.2)
86 execjs (>= 0.3.0)92 execjs (>= 0.3.0)
87 json (>= 1.8.0)93 json (>= 1.8.0)
94 unicode_utils (1.4.0)
88 unix_utils (0.0.15)95 unix_utils (0.0.15)
96 verse (0.4.0)
97 unicode_utils (~> 1.4.0)
89 yajl-ruby (1.2.1)98 yajl-ruby (1.2.1)
90 99
91PLATFORMS100PLATFORMS
@@ -113,7 +122,11 @@ DEPENDENCIES · 21 unmodified lines
113 sprockets-helpers122 sprockets-helpers
114 thin123 thin
115 thor124 thor
125 tty-pager
116 typhoeus126 typhoeus
117 uglifier127 uglifier
118 unix_utils128 unix_utils
119 yajl-ruby129 yajl-ruby
130
131BUNDLED WITH
132 1.11.2
lib/docs/core/doc.rb+4−0
@@ -38,6 +38,10 @@ module Docs · 37 unmodified lines
38 version.present?38 version.present?
39 end39 end
40 40
41 def versioned?
42 @versions.presence
43 end
44
41 def name45 def name
42 @name || super.try(:demodulize)46 @name || super.try(:demodulize)
43 end47 end
lib/tasks/docs.thor+11−6
@@ -13,12 +13,17 @@ class DocsCLI < Thor · 12 unmodified lines
13 13
14 desc 'list', 'List available documentations'14 desc 'list', 'List available documentations'
15 def list15 def list
16 max_length = 016 output = Docs.all.flat_map do |doc|
17 Docs.all.17 name = doc.to_s.demodulize.underscore
18 map { |doc| [doc.to_s.demodulize.underscore, doc] }.18 if doc.versioned?
19 to_h.19 doc.versions.map { |_doc| "#{name}@#{_doc.version}" }
20 each { |name, doc| max_length = name.length if name.length > max_length }.20 else
21 each { |name, doc| puts "#{name.rjust max_length + 1}: #{doc.versions.map { |v| v.release || '-' }.join(', ')}" }21 name
22 end
23 end.join("\n")
24
25 require 'tty-pager'
26 TTY::Pager.new.page(output)
22 end27 end
23 28
24 desc 'page <doc> [path] [--version] [--verbose] [--debug]', 'Generate a page (no indexing)'29 desc 'page <doc> [path] [--version] [--verbose] [--debug]', 'Generate a page (no indexing)'