jamescook-pow 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +19 -1
- data/jamescook-pow.gemspec +6 -3
- data/lib/pow.rb +35 -3
- data/lib/pow/profile.rb +40 -0
- data/pow.rb +5 -1
- data/rakefile.rb +4 -2
- data/test/pow_profile_test.rb +33 -0
- data/test/pow_test.rb +22 -0
- metadata +5 -2
data/README
CHANGED
@@ -25,11 +25,29 @@ Examples:
|
|
25
25
|
p! "Hello world, in bold"
|
26
26
|
p! "Mix and match", :color => :purple, :background => :black
|
27
27
|
|
28
|
+
========================================================
|
28
29
|
|
29
|
-
You can
|
30
|
+
You can set defaults in your ~/.irbrc or wherever.
|
30
31
|
require 'pow'
|
31
32
|
Pow.defaults = {:bold => true} # Now any puts will default to bold
|
32
33
|
|
33
34
|
|
35
|
+
Profiles:
|
36
|
+
=======================================================
|
37
|
+
|
38
|
+
Pow will try to load "~/.pow_defaults" into the Pow.defaults hash when loaded/required.
|
39
|
+
You can create custom profiles with the Pow::Profile class.
|
40
|
+
|
41
|
+
-- IRB Example
|
42
|
+
> profile = Pow::Profile.new # defaults to a file in $HOME
|
43
|
+
> profile.settings = {:bold => true, :color => :purple, :on => :black}
|
44
|
+
> profile.save
|
45
|
+
> Pow.load_profile # No argument needed if using default settings file
|
46
|
+
|
47
|
+
|
48
|
+
Misc:
|
49
|
+
|
50
|
+
Pow can be enabled/disabled with Pow.enable or Pow.disable
|
51
|
+
|
34
52
|
There's a script included that you can pipe text into and output customized text:
|
35
53
|
cat README | ruby bin/ruby-pow --bold --background=purple
|
data/jamescook-pow.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{jamescook-pow}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["James Cook"]
|
12
|
-
s.date = %q{2009-11-
|
12
|
+
s.date = %q{2009-11-27}
|
13
13
|
s.default_executable = %q{ruby-pow}
|
14
14
|
s.description = %q{Ruby 'puts' with shell colors.}
|
15
15
|
s.email = %q{jamecook@gmail.com}
|
@@ -23,8 +23,10 @@ Gem::Specification.new do |s|
|
|
23
23
|
"bin/ruby-pow",
|
24
24
|
"jamescook-pow.gemspec",
|
25
25
|
"lib/pow.rb",
|
26
|
+
"lib/pow/profile.rb",
|
26
27
|
"pow.rb",
|
27
28
|
"rakefile.rb",
|
29
|
+
"test/pow_profile_test.rb",
|
28
30
|
"test/pow_test.rb"
|
29
31
|
]
|
30
32
|
s.homepage = %q{http://github.com/jamescook/pow}
|
@@ -33,7 +35,8 @@ Gem::Specification.new do |s|
|
|
33
35
|
s.rubygems_version = %q{1.3.5}
|
34
36
|
s.summary = %q{puts with colors}
|
35
37
|
s.test_files = [
|
36
|
-
"test/
|
38
|
+
"test/pow_profile_test.rb",
|
39
|
+
"test/pow_test.rb"
|
37
40
|
]
|
38
41
|
|
39
42
|
if s.respond_to? :specification_version then
|
data/lib/pow.rb
CHANGED
@@ -3,6 +3,9 @@ module Pow
|
|
3
3
|
class << self
|
4
4
|
def included(base)
|
5
5
|
@@defaults = {}
|
6
|
+
@@enabled = true
|
7
|
+
@@profile = nil
|
8
|
+
Pow.load_profile
|
6
9
|
base.send(:define_method, :puts){ |*args| Puts.new(*args) }
|
7
10
|
base.send(:define_method, :puts!){ |*args| opts=(args.detect{|a| a.is_a?(Hash)} || {}).merge(:misc => {:bold => true}); args.reject!{|a| a.is_a?(Hash)}; args = [args.push(opts)].flatten; Puts.new(*args) } # Now that's just self-explanatory ..
|
8
11
|
base.send(:define_method, :puts_){ |*args| opts=(args.detect{|a| a.is_a?(Hash)} || {}).merge(:misc => {:underline => true}); args.reject!{|a| a.is_a?(Hash)}; args = [args.push(opts)].flatten; Puts.new(*args) } # Now that's just self-explanatory ..
|
@@ -12,12 +15,41 @@ module Pow
|
|
12
15
|
base.send(:alias_method, :p_, :puts_)
|
13
16
|
end
|
14
17
|
|
18
|
+
def enable
|
19
|
+
@@enabled = true
|
20
|
+
end
|
21
|
+
|
22
|
+
def disable
|
23
|
+
@@enabled = false
|
24
|
+
end
|
25
|
+
|
26
|
+
def enabled?
|
27
|
+
@@enabled == true
|
28
|
+
end
|
29
|
+
|
30
|
+
def disabled?
|
31
|
+
@@enabled == false
|
32
|
+
end
|
33
|
+
|
15
34
|
def defaults
|
16
35
|
@@defaults
|
17
36
|
end
|
18
37
|
|
19
38
|
def defaults=(val)
|
20
|
-
@@defaults
|
39
|
+
@@defaults = val || {}
|
40
|
+
end
|
41
|
+
|
42
|
+
def profile
|
43
|
+
@@profile
|
44
|
+
end
|
45
|
+
|
46
|
+
def load_profile( profile_path=:default )
|
47
|
+
@@profile = Pow::Profile.new( profile_path )
|
48
|
+
Pow.defaults = @@profile.read[:settings] rescue {}
|
49
|
+
end
|
50
|
+
|
51
|
+
def unload_profile
|
52
|
+
Pow.defaults = {}
|
21
53
|
end
|
22
54
|
end
|
23
55
|
|
@@ -90,7 +122,7 @@ module Pow
|
|
90
122
|
end
|
91
123
|
@@color = options[:color] || :white
|
92
124
|
@writer = options[:writer] || STDOUT
|
93
|
-
@formatted_text = format_string(options)
|
125
|
+
@formatted_text = Pow.enabled? ? format_string(options) : options[:text] + "\n"
|
94
126
|
out!(@formatted_text)
|
95
127
|
end
|
96
128
|
|
@@ -141,7 +173,7 @@ module Pow
|
|
141
173
|
|
142
174
|
def format_string(options={})
|
143
175
|
newline = options.fetch(:newline){ "\n" }
|
144
|
-
color = options.fetch(:color){ :white }
|
176
|
+
color = options.fetch(:color){ Pow.defaults[:color] || :white }
|
145
177
|
text = options.fetch(:text){ '' }
|
146
178
|
bold = options.fetch(:bold){ Pow.defaults[:bold] }
|
147
179
|
negative = options.fetch(:negative){ Pow.defaults[:negative] }
|
data/lib/pow/profile.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module Pow
|
5
|
+
|
6
|
+
class Profile
|
7
|
+
attr_accessor :profile_path, :settings, :name
|
8
|
+
attr_reader :yaml
|
9
|
+
|
10
|
+
def initialize(profile_path=:default)
|
11
|
+
@profile_path = (profile_path == :default) ? File.expand_path("~/.pow_defaults") : profile_path
|
12
|
+
@settings = read if File.exists?(@profile_path)
|
13
|
+
@name = "Default"
|
14
|
+
end
|
15
|
+
|
16
|
+
def write
|
17
|
+
FileUtils.mkdir_p( File.dirname(profile_path) )
|
18
|
+
File.open( profile_path, 'wb'){|f| YAML.dump( settings, f ) }
|
19
|
+
read
|
20
|
+
end
|
21
|
+
alias_method :save, :write
|
22
|
+
|
23
|
+
def read
|
24
|
+
@yaml = YAML.load_file( profile_path )
|
25
|
+
end
|
26
|
+
|
27
|
+
def settings=(val)
|
28
|
+
@settings = {:name => name, :settings => val}
|
29
|
+
end
|
30
|
+
|
31
|
+
def inspect
|
32
|
+
"<Pow::Profile '#{name}'>"
|
33
|
+
end
|
34
|
+
|
35
|
+
def preview
|
36
|
+
opts = {:text => "Hello world!"}.merge( settings )
|
37
|
+
Puts.new( opts ).out!
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/pow.rb
CHANGED
data/rakefile.rb
CHANGED
@@ -3,7 +3,7 @@ begin
|
|
3
3
|
require 'jeweler'
|
4
4
|
Jeweler::Tasks.new do |gemspec|
|
5
5
|
gemspec.name = "jamescook-pow"
|
6
|
-
gemspec.version = "0.1.
|
6
|
+
gemspec.version = "0.1.6"
|
7
7
|
gemspec.summary = "puts with colors"
|
8
8
|
gemspec.description = "Ruby 'puts' with shell colors."
|
9
9
|
gemspec.email = "jamecook@gmail.com"
|
@@ -18,7 +18,9 @@ task :default => [:test]
|
|
18
18
|
|
19
19
|
desc "Run tests"
|
20
20
|
task :test do |t|
|
21
|
-
|
21
|
+
Dir[ File.join(File.dirname(File.expand_path(__FILE__)), "test", "**") ].each do |test_file|
|
22
|
+
ruby test_file
|
23
|
+
end
|
22
24
|
end
|
23
25
|
|
24
26
|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require "stringio"
|
3
|
+
require File.join( File.dirname(__FILE__), "..", "pow")
|
4
|
+
|
5
|
+
class PowProfileTest < Test::Unit::TestCase
|
6
|
+
include Pow
|
7
|
+
def setup
|
8
|
+
@puts = Pow::Puts
|
9
|
+
@writer = StringIO.new
|
10
|
+
@temp_defaults_path = File.join(File.dirname(__FILE__), 'DEFAULTS')
|
11
|
+
@settings = {:bold => false, :color => :purple}
|
12
|
+
Pow.enable
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
File.unlink( @temp_defaults_path ) if File.exists?(@temp_defaults_path)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_pow_new_profile_exists_on_save
|
20
|
+
profile = Pow::Profile.new( @temp_defaults_path )
|
21
|
+
profile.settings = @settings
|
22
|
+
profile.save
|
23
|
+
assert_equal true, File.exists?( @temp_defaults_path )
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_pow_loads_profile
|
27
|
+
profile = Pow::Profile.new( @temp_defaults_path )
|
28
|
+
profile.settings = {:color => :red, :bold => false}
|
29
|
+
profile.save
|
30
|
+
Pow.load_profile( @temp_defaults_path )
|
31
|
+
assert_equal profile.settings[:settings], Pow.defaults
|
32
|
+
end
|
33
|
+
end
|
data/test/pow_test.rb
CHANGED
@@ -7,6 +7,28 @@ class PowTest < Test::Unit::TestCase
|
|
7
7
|
def setup
|
8
8
|
@puts = Pow::Puts
|
9
9
|
@writer = StringIO.new
|
10
|
+
Pow.enable
|
11
|
+
Pow.unload_profile # Prevents users profile from messing up test output
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_pow_enable
|
15
|
+
Pow.disable
|
16
|
+
Pow.enable
|
17
|
+
assert_equal false, Pow.enabled?
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_pow_enable
|
21
|
+
Pow.enable
|
22
|
+
Pow.disable
|
23
|
+
Pow.enable
|
24
|
+
assert_equal true, Pow.enabled?
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_puts_strips_formatting_when_pow_disabled
|
28
|
+
Pow.disable
|
29
|
+
@puts.new(:text => "TEST", :bold => true, :writer => @writer).out!
|
30
|
+
@writer.rewind
|
31
|
+
assert_equal "TEST\n", @writer.gets
|
10
32
|
end
|
11
33
|
|
12
34
|
def test_puts
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jamescook-pow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Cook
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-27 00:00:00 -06:00
|
13
13
|
default_executable: ruby-pow
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -27,8 +27,10 @@ files:
|
|
27
27
|
- bin/ruby-pow
|
28
28
|
- jamescook-pow.gemspec
|
29
29
|
- lib/pow.rb
|
30
|
+
- lib/pow/profile.rb
|
30
31
|
- pow.rb
|
31
32
|
- rakefile.rb
|
33
|
+
- test/pow_profile_test.rb
|
32
34
|
- test/pow_test.rb
|
33
35
|
has_rdoc: true
|
34
36
|
homepage: http://github.com/jamescook/pow
|
@@ -59,4 +61,5 @@ signing_key:
|
|
59
61
|
specification_version: 3
|
60
62
|
summary: puts with colors
|
61
63
|
test_files:
|
64
|
+
- test/pow_profile_test.rb
|
62
65
|
- test/pow_test.rb
|