소스 검색

Improve 'docs:list' command

Ref #25.
Thibaut Courouble 10 년 전
부모
커밋
4f3ea92bea
4개의 변경된 파일29개의 추가작업 그리고 6개의 파일을 삭제
  1. 1 0
      Gemfile
  2. 13 0
      Gemfile.lock
  3. 4 0
      lib/docs/core/doc.rb
  4. 11 6
      lib/tasks/docs.thor

+ 1 - 0
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

+ 13 - 0
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

+ 4 - 0
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

+ 11 - 6
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 <doc> [path] [--version] [--verbose] [--debug]', 'Generate a page (no indexing)'