Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/separate-ap'
Browse files Browse the repository at this point in the history
  • Loading branch information
ursm committed Feb 24, 2015
2 parents 9da3abb + b02d44f commit cd25ac1
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 74 deletions.
15 changes: 9 additions & 6 deletions README.md
Expand Up @@ -21,8 +21,8 @@ See more examples in [spec/acceptance](https://github.com/esminc/tapp/tree/maste

``` ruby
Tapp.configure do |config|
config.default_printer = :awesome_print
config.report_caller = true
config.default_printer = :puts
end
```

Expand All @@ -32,18 +32,21 @@ end
<th>Default</th>
<th>Description</th>
</tr>
<tr>
<td><code>default_printer</code></td>
<td><code>:pretty_print</code></td>
<td><a href="https://github.com/esminc/tapp/blob/master/spec/acceptance/default_printer.feature">default_printer.feature</a></td>
</tr>
<tr>
<td><code>report_caller</code></td>
<td><code>false</code></td>
<td><a href="https://github.com/esminc/tapp/blob/master/spec/acceptance/report_caller.feature">report_caller.feature</a></td>
</tr>
<tr>
<td><code>default_printer</code></td>
<td><code>:pretty_print</code></td>
<td><a href="https://github.com/esminc/tapp/blob/master/spec/acceptance/default_printer.feature">default_printer.feature</a></td>
</tr>
</table>

## Custom Printer
You can define a custom printer. See [custom_printer.feature](https://github.com/esminc/tapp/blob/master/spec/acceptance/custom_printer.feature).

## Note on Patches/Pull Requests

* Fork the project.
Expand Down
4 changes: 3 additions & 1 deletion lib/tapp.rb
@@ -1,7 +1,9 @@
require 'tapp/configuration'
require 'tapp/deprecated'
require 'tapp/object_extension'
require 'tapp/printer'

require 'tapp/printer/pretty_print'
require 'tapp/printer/puts'

module Tapp
extend Deprecated
Expand Down
6 changes: 0 additions & 6 deletions lib/tapp/object_extension.rb
Expand Up @@ -14,11 +14,5 @@ def tapp(printer = Tapp.config.default_printer)
def taputs(&block)
tapp :puts, &block
end

def taap
warn 'DEPRECATION WARNING: `taap` is deprecated. Set `Tapp.config.default_printer = :awesome_print` and use `tapp` instead.'

tapp :awesome_print
end
end
end
21 changes: 8 additions & 13 deletions lib/tapp/printer.rb
Expand Up @@ -2,20 +2,15 @@

module Tapp
module Printer
autoload :AwesomePrint, 'tapp/printer/awesome_print'
autoload :PrettyPrint, 'tapp/printer/pretty_print'
autoload :Puts, 'tapp/printer/puts'
@printers = {}

def self.instance(name)
case name
when :pretty_print
PrettyPrint.instance
when :puts
Puts.instance
when :awesome_print
AwesomePrint.instance
else
raise ArgumentError, "Unknown printer: #{name.inspect}"
class << self
def register(name, printer)
@printers[name] = printer
end

def instance(name)
@printers.fetch(name).instance
end
end

Expand Down
10 changes: 0 additions & 10 deletions lib/tapp/printer/awesome_print.rb

This file was deleted.

15 changes: 13 additions & 2 deletions lib/tapp/printer/pretty_print.rb
@@ -1,10 +1,21 @@
require 'tapp/printer'
require 'pp'

module Tapp::Printer
class PrettyPrint < Base
def print(*args)
pp *args
require 'pp'

self.class.class_eval do
remove_method :print

def print(*args)
pp *args
end
end

print *args
end
end

register :pretty_print, PrettyPrint
end
2 changes: 2 additions & 0 deletions lib/tapp/printer/puts.rb
Expand Up @@ -6,4 +6,6 @@ def print(*args)
puts *args
end
end

register :puts, Puts
end
34 changes: 34 additions & 0 deletions lib/tapp/turnip.rb
@@ -0,0 +1,34 @@
module Tapp
module Turnip
module Steps
step 'I have the following code:' do |code|
@code = code
end

step 'a file named :filename with:' do |filename, code|
@filename, @code = filename, code
end

step 'Ruby it' do
stdout = StringIO.new
$stdout = stdout

begin
if @filename
eval @code, binding, @filename, 1
else
eval @code
end
ensure
$stdout = STDOUT
end

@output = stdout.string.gsub(/\e\[0.*?m/, '').chop
end

step 'I should see:' do |output|
@output.should == output
end
end
end
end
2 changes: 1 addition & 1 deletion lib/tapp/util.rb
Expand Up @@ -4,7 +4,7 @@ module Util

def report_called
inner, outer = caller.partition {|line|
line.include?('/lib/tapp')
line =~ %r(/lib/tapp/(?!turnip))
}

method_quoted = inner.last.split(':in').last.strip
Expand Down
2 changes: 1 addition & 1 deletion lib/tapp/version.rb
@@ -1,3 +1,3 @@
module Tapp
VERSION = '1.4.1'
VERSION = '1.5.0'
end
24 changes: 24 additions & 0 deletions spec/acceptance/custom_printer.feature
@@ -0,0 +1,24 @@
Feature: Custom printer
Scenario: define a custom printer and use it
Given I have the following code:
"""
require 'tapp/printer'
module Tapp::Printer
class MyPrinter < Base
def print(*args)
puts "*** #{args.join(' ')} ***"
end
end
register :my_printer, MyPrinter
end
%w(foo bar).tapp(:my_printer)
"""

When Ruby it
Then I should see:
"""
*** foo bar ***
"""
6 changes: 3 additions & 3 deletions spec/acceptance/default_printer.feature
@@ -1,14 +1,14 @@
Feature: config.default_printer
Scenario: set config.default_printer to :awesome_print and call tapp
Scenario: set config.default_printer to :puts and call tapp
Given I have the following code:
"""
Tapp.config.default_printer = :awesome_print
Tapp.config.default_printer = :puts
'hoge'.tapp
"""

When Ruby it
Then I should see:
"""
"hoge"
hoge
"""
5 changes: 3 additions & 2 deletions spec/spec_helper.rb
@@ -1,8 +1,9 @@
require 'tapp'

Dir[File.expand_path('../steps/**/*.rb', __FILE__)].each {|f| require f }
require 'tapp/turnip'

RSpec.configure do |config|
config.include Tapp::Turnip::Steps

config.before do
Tapp.config.reset
end
Expand Down
28 changes: 0 additions & 28 deletions spec/steps/global_steps.rb

This file was deleted.

1 change: 0 additions & 1 deletion tapp.gemspec
Expand Up @@ -19,5 +19,4 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'thor'

s.add_development_dependency 'turnip'
s.add_development_dependency 'awesome_print'
end

0 comments on commit cd25ac1

Please sign in to comment.