priscilla 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24977731eec6baacf60afe5f0ab13cc82f93559d
4
- data.tar.gz: 762a40e5825c227cc46b61dcbfefcb389b3b8ae8
3
+ metadata.gz: d59fe24452200bf883fb2fd648e2d894ed27cd22
4
+ data.tar.gz: 06e04ee116652d1be50d20d1dbc79698218421c6
5
5
  SHA512:
6
- metadata.gz: 44d1fa95825f84ef73f64c6c65235a349b69bc9db527d4c4cd4c73ee1650b765a6bbc36e7c2964ca070378edfee2388263da075a94235e684b5c830dfd6476eb
7
- data.tar.gz: 7f4e5fec8fff5a2fa2d79c6a747f6a2d28a5113b29cc5fc84ef7f9cc64330116fc9ec1ecc8a31e935816f9a2d205df5cb09077450bfa40aaa5747095dea97590
6
+ metadata.gz: c3d94f11d750cb0386fdb6ebf7d42a84af11bb4fcc0f6bf45c3c5fdae056eb40987d74b274a1e38d65dc12319a8b786c736041e575aea70a2f3b29d62f3d4aa0
7
+ data.tar.gz: f4cd124964ea1e342391663e56e5648ce6bd9fce3ed28453257827f076a252aa29c532d0b7e3a23a6a0e0114ae0bcdf1527984a578502df3e131d880b912c521
data/README.md CHANGED
@@ -65,12 +65,24 @@ Priscilla supports a lot of different decorators:
65
65
 
66
66
  ## Configure
67
67
 
68
- If you're using rails create an initializer in `config/initializers/priscilla.rb`:
68
+ If you're using Rails, create an initializer in `config/initializers/priscilla.rb`:
69
69
 
70
70
  ```ruby
71
+ # This is the default configuration
71
72
  Priscilla.configure do |c|
72
- c.width = 80 # default
73
- c.decorator = ':dancer: ' # default
73
+ c.width = 80
74
+ c.decorator = ':dancer: '
75
+ c.presenter = ->(msg) { puts msg; puts }
76
+ end
77
+ ```
78
+
79
+ If you prefer to use the Rails logger, here is an example:
80
+
81
+ ```ruby
82
+ Priscilla.configure do |c|
83
+ c.width = 80
84
+ c.decorator = ':dancer: '
85
+ c.presenter = ->(msg) { Rails.logger.debug msg }
74
86
  end
75
87
  ```
76
88
 
@@ -17,7 +17,8 @@ end
17
17
 
18
18
  module Kernel
19
19
  def pr(message, options = {})
20
- puts Priscilla::Makeup.new(Priscilla.configuration).decorate(message, options)
21
- puts
20
+ config = Priscilla.configuration
21
+ message = Priscilla::Makeup.new(config).decorate(message, options)
22
+ config.presenter.call(message)
22
23
  end
23
24
  end
@@ -1,13 +1,11 @@
1
1
  module Priscilla
2
2
  class Configuration
3
- DEFAULT_WIDTH = 80
4
- DEFAULT_DECORATOR = ':dancer: '
5
-
6
- attr_accessor :width, :decorator
3
+ attr_accessor :width, :decorator, :presenter
7
4
 
8
5
  def initialize
9
- self.width = DEFAULT_WIDTH
10
- self.decorator = DEFAULT_DECORATOR
6
+ self.width = 80
7
+ self.decorator = ':dancer: '
8
+ self.presenter = ->(msg) { puts msg; puts }
11
9
  end
12
10
 
13
11
  def decorator=(value)
@@ -13,7 +13,9 @@ module Priscilla
13
13
  def decorate(message, options = {})
14
14
  override_config(options)
15
15
  message = message.to_s
16
- [decorated_line, decorate_message(message), decorated_line].join("\n")
16
+
17
+ [decorated_line, decorate_message(message), decorated_line]
18
+ .map { |string| string << "\n" }.join
17
19
  end
18
20
 
19
21
  private
@@ -1,3 +1,3 @@
1
1
  module Priscilla
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
3
3
  end
@@ -16,7 +16,7 @@ describe Priscilla do
16
16
  )
17
17
  end
18
18
 
19
- context "emoji" do
19
+ context 'emoji' do
20
20
  it 'converts decorator symbols to emoji' do
21
21
  Priscilla.configure do |c|
22
22
  c.width = 8
@@ -36,12 +36,34 @@ describe Priscilla do
36
36
  c.decorator = ':zap: :dancer: :no_good: :frog: '
37
37
  end
38
38
 
39
- expect(capture_stdout { pr("DO IT") }).to eq(
39
+ expect(capture_stdout { pr('DO IT') }).to eq(
40
40
  "⚡ 💃 🙅 🐸 ⚡ 💃 🙅 🐸 ⚡ 💃 🙅 🐸 \n" +
41
41
  "⚡ 💃 🙅 🐸 DO IT ⚡ 💃 🙅 🐸 \n" +
42
42
  "⚡ 💃 🙅 🐸 ⚡ 💃 🙅 🐸 ⚡ 💃 🙅 🐸 \n\n"
43
43
  )
44
44
  end
45
45
  end
46
+
47
+ context 'presenter' do
48
+ it 'allows a custom presenter method' do
49
+ Priscilla.configure do |c|
50
+ c.width = 14
51
+ c.decorator = '°'
52
+ c.presenter = lambda do |msg|
53
+ puts 'ABBA ABBA ABBA'
54
+ puts msg
55
+ puts 'ABBA ABBA ABBA'
56
+ end
57
+ end
58
+
59
+ expect(capture_stdout { pr('MAMMA MIA') }).to eq(
60
+ "ABBA ABBA ABBA\n" +
61
+ "°°°°°°°°°°°°°°\n" +
62
+ "° MAMMA MIA °\n" +
63
+ "°°°°°°°°°°°°°°\n" +
64
+ "ABBA ABBA ABBA\n"
65
+ )
66
+ end
67
+ end
46
68
  end
47
69
  end
@@ -25,7 +25,7 @@ module Priscilla
25
25
  expect(output).to eq(
26
26
  "===================================\n" +
27
27
  "= A cock in a frock on a rock =\n" +
28
- "==================================="
28
+ "===================================\n"
29
29
  )
30
30
  end
31
31
 
@@ -37,7 +37,7 @@ module Priscilla
37
37
  expect(output).to eq(
38
38
  "=======\n" +
39
39
  "= 450 =\n" +
40
- "======="
40
+ "=======\n"
41
41
  )
42
42
  end
43
43
  end
@@ -49,7 +49,7 @@ module Priscilla
49
49
  expect(output).to eq(
50
50
  "===================================\n" +
51
51
  "My name is Inigo Montoya, you killed my father, prepare to die\n" +
52
- "==================================="
52
+ "===================================\n"
53
53
  )
54
54
  end
55
55
  end
@@ -61,7 +61,7 @@ module Priscilla
61
61
  expect(output).to eq(
62
62
  "<><><><><><><><><><><><><><><><><>\n" +
63
63
  "<> A cock in a frock on a rock <>\n" +
64
- "<><><><><><><><><><><><><><><><><>"
64
+ "<><><><><><><><><><><><><><><><><>\n"
65
65
  )
66
66
  end
67
67
  end
@@ -73,7 +73,7 @@ module Priscilla
73
73
  expect(output.uncolorize).to eq(
74
74
  "[][][][][][][][][][][][][][][][][]\n" +
75
75
  "[] A cock in a frock on a rock []\n" +
76
- "[][][][][][][][][][][][][][][][][]"
76
+ "[][][][][][][][][][][][][][][][][]\n"
77
77
  )
78
78
  end
79
79
  end
@@ -83,7 +83,7 @@ module Priscilla
83
83
  expect(subject.decorate(message, decorator: "€")).to eq(
84
84
  "€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€\n" +
85
85
  "€ A cock in a frock on a rock €\n" +
86
- "€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€"
86
+ "€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€\n"
87
87
  )
88
88
  end
89
89
 
@@ -101,7 +101,7 @@ module Priscilla
101
101
  expect(output).to eq(
102
102
  "⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ \n" +
103
103
  "⚡ A cock in a frock on a rock ⚡ \n" +
104
- "⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ "
104
+ "⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ ⚡ \n"
105
105
  )
106
106
  end
107
107
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: priscilla
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ju Liu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-02 00:00:00.000000000 Z
11
+ date: 2014-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -136,4 +136,3 @@ test_files:
136
136
  - spec/priscilla/simple_emoji_spec.rb
137
137
  - spec/priscilla_spec.rb
138
138
  - spec/spec_helper.rb
139
- has_rdoc: