Improve 'docs:list' command

Ref #25.
pull/308/merge
Thibaut Courouble 9 years ago
parent b04dba012e
commit 4f3ea92bea

@ -34,6 +34,7 @@ group :docs do
gem 'html-pipeline' gem 'html-pipeline'
gem 'progress_bar', require: false gem 'progress_bar', require: false
gem 'unix_utils', require: false gem 'unix_utils', require: false
gem 'tty-pager', require: false
end end
group :test do group :test do

@ -78,6 +78,12 @@ GEM
thor (0.19.1) thor (0.19.1)
thread_safe (0.3.5) thread_safe (0.3.5)
tilt (2.0.2) tilt (2.0.2)
tty-pager (0.3.0)
tty-screen (~> 0.4.0)
tty-which (~> 0.1.0)
verse (~> 0.4.0)
tty-screen (0.4.3)
tty-which (0.1.0)
typhoeus (0.8.0) typhoeus (0.8.0)
ethon (>= 0.8.0) ethon (>= 0.8.0)
tzinfo (1.2.2) tzinfo (1.2.2)
@ -85,7 +91,10 @@ GEM
uglifier (2.7.2) uglifier (2.7.2)
execjs (>= 0.3.0) execjs (>= 0.3.0)
json (>= 1.8.0) json (>= 1.8.0)
unicode_utils (1.4.0)
unix_utils (0.0.15) unix_utils (0.0.15)
verse (0.4.0)
unicode_utils (~> 1.4.0)
yajl-ruby (1.2.1) yajl-ruby (1.2.1)
PLATFORMS PLATFORMS
@ -113,7 +122,11 @@ DEPENDENCIES
sprockets-helpers sprockets-helpers
thin thin
thor thor
tty-pager
typhoeus typhoeus
uglifier uglifier
unix_utils unix_utils
yajl-ruby yajl-ruby
BUNDLED WITH
1.11.2

@ -38,6 +38,10 @@ module Docs
version.present? version.present?
end end
def versioned?
@versions.presence
end
def name def name
@name || super.try(:demodulize) @name || super.try(:demodulize)
end end

@ -13,12 +13,17 @@ class DocsCLI < Thor
desc 'list', 'List available documentations' desc 'list', 'List available documentations'
def list def list
max_length = 0 output = Docs.all.flat_map do |doc|
Docs.all. name = doc.to_s.demodulize.underscore
map { |doc| [doc.to_s.demodulize.underscore, doc] }. if doc.versioned?
to_h. doc.versions.map { |_doc| "#{name}@#{_doc.version}" }
each { |name, doc| max_length = name.length if name.length > max_length }. else
each { |name, doc| puts "#{name.rjust max_length + 1}: #{doc.versions.map { |v| v.release || '-' }.join(', ')}" } name
end
end.join("\n")
require 'tty-pager'
TTY::Pager.new.page(output)
end end
desc 'page <doc> [path] [--version] [--verbose] [--debug]', 'Generate a page (no indexing)' desc 'page <doc> [path] [--version] [--verbose] [--debug]', 'Generate a page (no indexing)'

Loading…
Cancel
Save