diff --git a/Gemfile b/Gemfile index cf87db06..f2958d3d 100644 --- a/Gemfile +++ b/Gemfile @@ -34,6 +34,7 @@ group :docs do gem 'html-pipeline' gem 'progress_bar', require: false gem 'unix_utils', require: false + gem 'tty-pager', require: false end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index 21eb62dd..50b3930d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -78,6 +78,12 @@ GEM thor (0.19.1) thread_safe (0.3.5) 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) ethon (>= 0.8.0) tzinfo (1.2.2) @@ -85,7 +91,10 @@ GEM uglifier (2.7.2) execjs (>= 0.3.0) json (>= 1.8.0) + unicode_utils (1.4.0) unix_utils (0.0.15) + verse (0.4.0) + unicode_utils (~> 1.4.0) yajl-ruby (1.2.1) PLATFORMS @@ -113,7 +122,11 @@ DEPENDENCIES sprockets-helpers thin thor + tty-pager typhoeus uglifier unix_utils yajl-ruby + +BUNDLED WITH + 1.11.2 diff --git a/lib/docs/core/doc.rb b/lib/docs/core/doc.rb index 69eb67a0..e98ec8b2 100644 --- a/lib/docs/core/doc.rb +++ b/lib/docs/core/doc.rb @@ -38,6 +38,10 @@ module Docs version.present? end + def versioned? + @versions.presence + end + def name @name || super.try(:demodulize) end diff --git a/lib/tasks/docs.thor b/lib/tasks/docs.thor index 7db94855..1191b748 100644 --- a/lib/tasks/docs.thor +++ b/lib/tasks/docs.thor @@ -13,12 +13,17 @@ class DocsCLI < Thor desc 'list', 'List available documentations' def list - max_length = 0 - Docs.all. - map { |doc| [doc.to_s.demodulize.underscore, doc] }. - to_h. - each { |name, doc| max_length = name.length if name.length > max_length }. - each { |name, doc| puts "#{name.rjust max_length + 1}: #{doc.versions.map { |v| v.release || '-' }.join(', ')}" } + output = Docs.all.flat_map do |doc| + name = doc.to_s.demodulize.underscore + if doc.versioned? + doc.versions.map { |_doc| "#{name}@#{_doc.version}" } + else + name + end + end.join("\n") + + require 'tty-pager' + TTY::Pager.new.page(output) end desc 'page [path] [--version] [--verbose] [--debug]', 'Generate a page (no indexing)'