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
3434 gem 'html-pipeline'
3535 gem 'progress_bar', require: false
3636 gem 'unix_utils', require: false
37+ gem 'tty-pager', require: false
3738 end
3839
3940 group :test do
Gemfile.lock+13−0
@@ -78,6 +78,12 @@ GEM · 77 unmodified lines
7878 thor (0.19.1)
7979 thread_safe (0.3.5)
8080 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)
8187 typhoeus (0.8.0)
8288 ethon (>= 0.8.0)
8389 tzinfo (1.2.2)
@@ -85,7 +91,10 @@ GEM · 1 unmodified line
8591 uglifier (2.7.2)
8692 execjs (>= 0.3.0)
8793 json (>= 1.8.0)
94+ unicode_utils (1.4.0)
8895 unix_utils (0.0.15)
96+ verse (0.4.0)
97+ unicode_utils (~> 1.4.0)
8998 yajl-ruby (1.2.1)
9099
91100 PLATFORMS
@@ -113,7 +122,11 @@ DEPENDENCIES · 21 unmodified lines
113122 sprockets-helpers
114123 thin
115124 thor
125+ tty-pager
116126 typhoeus
117127 uglifier
118128 unix_utils
119129 yajl-ruby
130+
131+BUNDLED WITH
132+ 1.11.2
lib/docs/core/doc.rb+4−0
@@ -38,6 +38,10 @@ module Docs · 37 unmodified lines
3838 version.present?
3939 end
4040
41+ def versioned?
42+ @versions.presence
43+ end
44+
4145 def name
4246 @name || super.try(:demodulize)
4347 end
lib/tasks/docs.thor+11−6
@@ -13,12 +13,17 @@ class DocsCLI < Thor · 12 unmodified lines
1313
1414 desc 'list', 'List available documentations'
1515 def list
16− max_length = 0
17− Docs.all.
18− map { |doc| [doc.to_s.demodulize.underscore, doc] }.
19− to_h.
20− each { |name, doc| max_length = name.length if name.length > max_length }.
21− each { |name, doc| puts "#{name.rjust max_length + 1}: #{doc.versions.map { |v| v.release || '-' }.join(', ')}" }
16+ output = Docs.all.flat_map do |doc|
17+ name = doc.to_s.demodulize.underscore
18+ if doc.versioned?
19+ doc.versions.map { |_doc| "#{name}@#{_doc.version}" }
20+ else
21+ name
22+ end
23+ end.join("\n")
24+
25+ require 'tty-pager'
26+ TTY::Pager.new.page(output)
2227 end
2328
2429 desc 'page <doc> [path] [--version] [--verbose] [--debug]', 'Generate a page (no indexing)'