priscilla 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/priscilla/configuration.rb +21 -0
- data/lib/priscilla/makeup.rb +62 -0
- data/lib/priscilla/version.rb +3 -0
- data/lib/priscilla.rb +12 -0
- data/priscilla.gemspec +26 -0
- data/spec/priscilla/configuration_spec.rb +20 -0
- data/spec/priscilla/makeup_spec.rb +98 -0
- data/spec/priscilla_spec.rb +13 -0
- data/spec/spec_helper.rb +18 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2a5cce59a7dc7bf7419147704a5be9de5ca419cc
|
4
|
+
data.tar.gz: c253d820579c8623962923d45d1adf8bd11c02b6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 608f35c0a914ca795414d3203b4271f361792735e936af124ae38512e9a00dd99d47cf993488a1b9a92259cfc47012b800fe86d0772e6b162556ce210e159358
|
7
|
+
data.tar.gz: f44d2a52cbba062e64f170cf67bf8789b93aaf3538d154964fb0a9caad0ec2dc2846f859b46b1178b1d0935f80a10b6eb4713aab2b20d8837c50fd7370b3ebfd
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Ju Liu
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Priscilla
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'priscilla'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install priscilla
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( http://github.com/<my-github-username>/priscilla/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Priscilla
|
2
|
+
def self.configuration
|
3
|
+
@configuration ||= Configuration.new
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.configure
|
7
|
+
yield(configuration)
|
8
|
+
end
|
9
|
+
|
10
|
+
class Configuration
|
11
|
+
DEFAULT_WIDTH = 80
|
12
|
+
DEFAULT_DECORATOR = "⚡ ".on_blue
|
13
|
+
|
14
|
+
attr_accessor :width, :decorator
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@width = DEFAULT_WIDTH
|
18
|
+
@decorator = DEFAULT_DECORATOR
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module Priscilla
|
4
|
+
class Makeup
|
5
|
+
extend Forwardable
|
6
|
+
attr_reader :config
|
7
|
+
def_delegators :@config, :width, :decorator
|
8
|
+
|
9
|
+
def initialize(config)
|
10
|
+
@config = config.clone
|
11
|
+
end
|
12
|
+
|
13
|
+
def decorate(message, **options)
|
14
|
+
override_config(options)
|
15
|
+
message = message.to_s
|
16
|
+
[ decorated_line, decorate_message(message), decorated_line ].join("\n")
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def decorator_length
|
22
|
+
decorator.uncolorize.length
|
23
|
+
end
|
24
|
+
|
25
|
+
def decoratable_width
|
26
|
+
(width / decorator_length) * decorator_length
|
27
|
+
end
|
28
|
+
|
29
|
+
def decorated_line
|
30
|
+
decorator * (decoratable_width / decorator_length)
|
31
|
+
end
|
32
|
+
|
33
|
+
def decoratable?(message)
|
34
|
+
minimum_decorated_length(message) <= decoratable_width
|
35
|
+
end
|
36
|
+
|
37
|
+
def minimum_decorated_length(message)
|
38
|
+
# add two decorators and two wrapping spaces
|
39
|
+
message.length + (decorator_length * 2) + 2
|
40
|
+
end
|
41
|
+
|
42
|
+
def message_template(message)
|
43
|
+
padding = space_for(decoratable_width - minimum_decorated_length(message))
|
44
|
+
"#{decorator} #{message} #{padding}#{decorator}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def space_for(times)
|
48
|
+
' ' * times
|
49
|
+
end
|
50
|
+
|
51
|
+
def decorate_message(message)
|
52
|
+
return message unless decoratable?(message)
|
53
|
+
message_template(message)
|
54
|
+
end
|
55
|
+
|
56
|
+
def override_config(options)
|
57
|
+
options.each do |key, value|
|
58
|
+
config.send("#{key}=", value)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/priscilla.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
|
3
|
+
require "priscilla/version"
|
4
|
+
require "priscilla/configuration"
|
5
|
+
require "priscilla/makeup"
|
6
|
+
|
7
|
+
module Kernel
|
8
|
+
def pr(message, **options)
|
9
|
+
puts Priscilla::Makeup.new(Priscilla.configuration).decorate(message, options)
|
10
|
+
puts
|
11
|
+
end
|
12
|
+
end
|
data/priscilla.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'priscilla/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "priscilla"
|
8
|
+
spec.version = Priscilla::VERSION
|
9
|
+
spec.authors = ["Ju Liu"]
|
10
|
+
spec.email = ["ju.liu@welaika.com"]
|
11
|
+
spec.summary = %q{Frock up your messages}
|
12
|
+
spec.description = %q{Make your messages stand out from the crowd}
|
13
|
+
spec.homepage = "http://github.com/Arkham/priscilla"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "colorize", "~> 0.7"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.1"
|
25
|
+
spec.add_development_dependency "rspec", "~> 2.14"
|
26
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Priscilla do
|
4
|
+
describe "::configure" do
|
5
|
+
before do
|
6
|
+
Priscilla.configure do |c|
|
7
|
+
c.width = 5
|
8
|
+
c.decorator = "*"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "allows to configure options" do
|
13
|
+
expect(capture_stdout { pr("1") }).to eq(
|
14
|
+
"*****\n" +
|
15
|
+
"* 1 *\n" +
|
16
|
+
"*****\n\n"
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
module Priscilla
|
5
|
+
describe Makeup do
|
6
|
+
describe "#decorate" do
|
7
|
+
let(:width) { 35 }
|
8
|
+
let(:decorator) { "=" }
|
9
|
+
let(:config) {
|
10
|
+
OpenStruct.new(
|
11
|
+
width: width,
|
12
|
+
decorator: decorator
|
13
|
+
)
|
14
|
+
}
|
15
|
+
|
16
|
+
subject do
|
17
|
+
described_class.new(config)
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:message) { "A cock in a frock on a rock" }
|
21
|
+
let(:output) { subject.decorate(message) }
|
22
|
+
|
23
|
+
it "makes a nice header around the message" do
|
24
|
+
expect(output).to eq(
|
25
|
+
"===================================\n" +
|
26
|
+
"= A cock in a frock on a rock =\n" +
|
27
|
+
"==================================="
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when passed a non-string" do
|
32
|
+
let(:width) { 7 }
|
33
|
+
let(:message) { 450 }
|
34
|
+
|
35
|
+
it "converts to string and decorates" do
|
36
|
+
expect(output).to eq(
|
37
|
+
"=======\n" +
|
38
|
+
"= 450 =\n" +
|
39
|
+
"======="
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "when message is longer than given width" do
|
45
|
+
let(:message) { "My name is Inigo Montoya, you killed my father, prepare to die" }
|
46
|
+
|
47
|
+
it "does not decorate the message" do
|
48
|
+
expect(output).to eq(
|
49
|
+
"===================================\n" +
|
50
|
+
"My name is Inigo Montoya, you killed my father, prepare to die\n" +
|
51
|
+
"==================================="
|
52
|
+
)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when decorator is more than a single character" do
|
57
|
+
let(:decorator) { "<>" }
|
58
|
+
|
59
|
+
it "scales the decoration accordingly" do
|
60
|
+
expect(output).to eq(
|
61
|
+
"<><><><><><><><><><><><><><><><><>\n" +
|
62
|
+
"<> A cock in a frock on a rock <>\n" +
|
63
|
+
"<><><><><><><><><><><><><><><><><>"
|
64
|
+
)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "when decorator is a colorized string" do
|
69
|
+
let(:decorator) { "[]".blue }
|
70
|
+
|
71
|
+
it "ignores the colors to calculate the total width" do
|
72
|
+
expect(output.uncolorize).to eq(
|
73
|
+
"[][][][][][][][][][][][][][][][][]\n" +
|
74
|
+
"[] A cock in a frock on a rock []\n" +
|
75
|
+
"[][][][][][][][][][][][][][][][][]"
|
76
|
+
)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "when options are passed" do
|
81
|
+
it "prefers them over the default configuration" do
|
82
|
+
expect(subject.decorate(message, decorator: "€")).to eq(
|
83
|
+
"€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€\n" +
|
84
|
+
"€ A cock in a frock on a rock €\n" +
|
85
|
+
"€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€"
|
86
|
+
)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "does not override the default configuration" do
|
90
|
+
old_config = config
|
91
|
+
subject.decorate(message, decorator: "¬_¬")
|
92
|
+
expect(old_config.decorator).not_to eq(subject.config.decorator)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Priscilla do
|
4
|
+
describe "::pr" do
|
5
|
+
it "adds a method to the Kernel" do
|
6
|
+
expect(capture_stdout { pr("hello") }).to match(/hello/)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "forwards additional options" do
|
10
|
+
expect(capture_stdout { pr("hello", decorator: '<3') }).to match(/hello/)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'priscilla'
|
2
|
+
|
3
|
+
module CaptureHelpers
|
4
|
+
def capture_stdout(&block)
|
5
|
+
original_stdout = $stdout
|
6
|
+
$stdout = fake = StringIO.new
|
7
|
+
begin
|
8
|
+
yield
|
9
|
+
ensure
|
10
|
+
$stdout = original_stdout
|
11
|
+
end
|
12
|
+
fake.string
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
RSpec.configure do |config|
|
17
|
+
config.include CaptureHelpers
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: priscilla
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ju Liu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.14'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.14'
|
69
|
+
description: Make your messages stand out from the crowd
|
70
|
+
email:
|
71
|
+
- ju.liu@welaika.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- lib/priscilla.rb
|
83
|
+
- lib/priscilla/configuration.rb
|
84
|
+
- lib/priscilla/makeup.rb
|
85
|
+
- lib/priscilla/version.rb
|
86
|
+
- priscilla.gemspec
|
87
|
+
- spec/priscilla/configuration_spec.rb
|
88
|
+
- spec/priscilla/makeup_spec.rb
|
89
|
+
- spec/priscilla_spec.rb
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
homepage: http://github.com/Arkham/priscilla
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.2.2
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Frock up your messages
|
115
|
+
test_files:
|
116
|
+
- spec/priscilla/configuration_spec.rb
|
117
|
+
- spec/priscilla/makeup_spec.rb
|
118
|
+
- spec/priscilla_spec.rb
|
119
|
+
- spec/spec_helper.rb
|