Skip to content
Browse files

Drop dependency on `terminal-table` and use `formatador` instead. (Cl…

…oses #400)
  • Loading branch information...
1 parent 878953d commit 49d160bd01c2ed33c4c80f9e1bb6152e3b95aecf @netzpirat netzpirat committed Mar 5, 2013
View
6 CHANGELOG.md
@@ -1,3 +1,9 @@
+## Master
+
+### Improvements
+
+- [#400][] Drop dependency on `terminal-table` and use `formatador` instead. ([@netzpirat][])
+
## 1.6.2 - 27 January, 2013
### Improvements
View
6 README.md
@@ -473,8 +473,6 @@ You can list the available plugins with the `list` task:
```bash
$ guard list
+----------+--------------+
-| Available Guard plugins |
-+----------+--------------+
| Plugin | In Guardfile |
+----------+--------------+
| Compass ||
@@ -494,18 +492,16 @@ You can show the structure of the groups and their plugins with the `show` task:
```bash
$ guard show
+---------+--------+-----------------+----------------------------+
-| Guardfile structure |
-+---------+--------+-----------------+----------------------------+
| Group | Plugin | Option | Value |
+---------+--------+-----------------+----------------------------+
-| Default | | | |
| Specs | Rspec | all_after_pass | true |
| | | all_on_start | true |
| | | cli | "--fail-fast --format doc" |
| | | focus_on_failed | false |
| | | keep_failed | true |
| | | run_all | {} |
| | | spec_paths | ["spec"] |
++---------+--------+-----------------+----------------------------+
| Docs | Ronn | | |
+---------+--------+-----------------+----------------------------+
```
View
2 guard.gemspec
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
s.add_dependency 'listen', '>= 0.6.0'
s.add_dependency 'pry', '>= 0.9.10'
s.add_dependency 'lumberjack', '>= 1.0.2'
- s.add_dependency 'terminal-table', '>= 1.4.3'
+ s.add_dependency 'formatador', '>= 0.2.4'
s.add_development_dependency 'bundler'
s.add_development_dependency 'rspec', '~> 2.13.0'
View
4 lib/guard/cli.rb
@@ -124,7 +124,7 @@ def start
# @see Guard::DslDescriber.list
#
def list
- puts ::Guard::DslDescriber.list(options)
+ ::Guard::DslDescriber.list(options)
end
desc 'version', 'Show the Guard version'
@@ -180,7 +180,7 @@ def init(*guard_names)
# @see Guard::DslDescriber.show
#
def show
- puts ::Guard::DslDescriber.show(options)
+ ::Guard::DslDescriber.show(options)
end
private
View
2 lib/guard/commands/show.rb
@@ -16,7 +16,7 @@ class Interactor
BANNER
def process
- output.puts ::Guard::DslDescriber.show(::Guard.options)
+ ::Guard::DslDescriber.show(::Guard.options)
end
end
end
View
33 lib/guard/dsl_describer.rb
@@ -14,7 +14,7 @@ class DslDescriber < Dsl
require 'guard/dsl'
require 'guard/ui'
- require 'terminal-table'
+ require 'formatador'
class << self
@@ -42,10 +42,10 @@ def list(options)
evaluate_guardfile(options)
rows = ::Guard.guard_gem_names.sort.uniq.inject([]) do |rows, name|
- rows << [name.capitalize, ::Guard.guards(name) ? '' : '']
+ rows << { :Plugin => name.capitalize, :Guardfile => ::Guard.guards(name) ? '' : '' }
end
- Terminal::Table.new(:title => 'Available Guard plugins', :headings => ['Plugin', 'In Guardfile'], :rows => rows)
+ Formatador.display_compact_table(rows, [:Plugin, :Guardfile])
end
# Shows all Guard plugins and their options that are defined in
@@ -57,23 +57,28 @@ def show(options)
evaluate_guardfile(options)
rows = ::Guard.groups.inject([]) do |rows, group|
- plugins = ''
- options = ''
- values = ''
-
::Guard.guards({ :group => group.name }).each do |plugin|
- plugins << plugin.to_s
-
- plugin.options.inject({}) { |o, (k, v)| o[k.to_s] = v; o }.sort.each do |name, value|
- options << name.to_s << "\n"
- values << value.inspect << "\n"
+ options = plugin.options.inject({}) { |o, (k, v)| o[k.to_s] = v; o }.sort
+
+ if options.empty?
+ rows << :split
+ rows << { :Group => group.to_s, :Plugin => plugin.to_s, :Option => '', :Value => '' }
+ else
+ options.each_with_index do |(option, value), index|
+ if index == 0
+ rows << :split
+ rows << { :Group => group.to_s, :Plugin => plugin.to_s, :Option => option.to_s, :Value => value.inspect }
+ else
+ rows << { :Group => '', :Plugin => '', :Option => option.to_s, :Value => value.inspect }
+ end
+ end
end
end
- rows << [group.to_s, plugins, options, values]
+ rows
end
- Terminal::Table.new(:title => 'Guardfile structure', :headings => %w(Group Plugin Option Value), :rows => rows)
+ Formatador.display_compact_table(rows.drop(1), [:Group, :Plugin, :Option, :Value])
end
end
View
6 spec/guard/cli_spec.rb
@@ -71,8 +71,7 @@
describe '#list' do
it 'outputs the Guard::DslDescriber.list result' do
- ::Guard::DslDescriber.should_receive(:list).and_return 'LIST OUTPUT'
- subject.should_receive(:puts).with 'LIST OUTPUT'
+ ::Guard::DslDescriber.should_receive(:list)
subject.list
end
end
@@ -160,8 +159,7 @@
describe '#show' do
it 'outputs the Guard::DslDescriber.list result' do
- ::Guard::DslDescriber.should_receive(:list).and_return 'SHOW OUTPUT'
- subject.should_receive(:puts).with 'SHOW OUTPUT'
+ ::Guard::DslDescriber.should_receive(:list)
subject.list
end
end
View
3 spec/guard/commands/show_spec.rb
@@ -4,8 +4,7 @@
describe '#perform' do
it 'outputs the DSL description' do
- ::Guard::DslDescriber.should_receive(:show).and_return 'SHOW OUTPUT'
- Pry.output.should_receive(:puts).with 'SHOW OUTPUT'
+ ::Guard::DslDescriber.should_receive(:show)
Pry.run_command 'show'
end
end
View
67 spec/guard/dsl_describer_spec.rb
@@ -1,6 +1,7 @@
# encoding: utf-8
require 'spec_helper'
+require 'formatador'
describe Guard::DslDescriber do
@@ -27,21 +28,30 @@
before do
stub_const 'Guard::Test', Class.new(Guard::Guard)
stub_const 'Guard::Another', Class.new(Guard::Guard)
+
+ @output = ''
+
+ # Strip escape sequences
+ STDOUT.stub(:tty?).and_return false
+
+ # Capture formatador output
+ Thread.current[:formatador] = Formatador.new
+ Thread.current[:formatador].stub(:print) do |msg|
+ @output << msg
+ end
end
describe '.list' do
- let(:output) do
- <<-OUTPUT.gsub(/^\s+|\n$/, '')
- +------------+--------------+
- | Available Guard plugins |
- +------------+--------------+
- | Plugin | In Guardfile |
- +------------+--------------+
- | Another | ✔ |
- | Even | ✘ |
- | More | ✘ |
- | Test | ✔ |
- +------------+--------------+
+ let(:result) do
+ <<-OUTPUT
+ +---------+-----------+
+ | Plugin | Guardfile |
+ +---------+-----------+
+ | Another | ✔ |
+ | Even | ✘ |
+ | More | ✘ |
+ | Test | ✔ |
+ +---------+-----------+
OUTPUT
end
@@ -50,30 +60,31 @@
end
it 'lists the available Guards when they\'re declared as strings or symbols' do
- # Delete is needed for 1.8.7 compatibility only
- ::Guard::DslDescriber.list(:guardfile_contents => guardfile).to_s.delete(' ').should eq(output.delete(' '))
+ ::Guard::DslDescriber.list(:guardfile_contents => guardfile)
+ @output.should eql(result)
end
end
describe '.show' do
- let(:output) do
- <<-OUTPUT.gsub(/^\s+|\n$/, '')
- +---------+---------+--------+-------+
- | Guardfile structure |
- +---------+---------+--------+-------+
- | Group | Plugin | Option | Value |
- +---------+---------+--------+-------+
- | Default | Test | a | :b |
- | | | c | :d |
- | A | Test | x | 1 |
- | | | y | 2 |
- | B | Another | | |
- +---------+---------+--------+-------+
+ let(:result) do
+ <<-OUTPUT
+ +---------+---------+--------+-------+
+ | Group | Plugin | Option | Value |
+ +---------+---------+--------+-------+
+ | Default | Test | a | :b |
+ | | | c | :d |
+ +---------+---------+--------+-------+
+ | A | Test | x | 1 |
+ | | | y | 2 |
+ +---------+---------+--------+-------+
+ | B | Another | | |
+ +---------+---------+--------+-------+
OUTPUT
end
it 'shows the Guards and their options' do
- ::Guard::DslDescriber.show(:guardfile_contents => guardfile).to_s.should eq(output)
+ ::Guard::DslDescriber.show(:guardfile_contents => guardfile)
+ @output.should eql(result)
end
end

0 comments on commit 49d160b

Please sign in to comment.
Something went wrong with that request. Please try again.