mutter 0.3.3 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -13,36 +13,11 @@ begin
13
13
  gem.authors = ["cloudhead"]
14
14
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
15
  end
16
-
16
+ Jeweler::RubyforgeTasks.new
17
17
  rescue LoadError
18
18
  puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
19
19
  end
20
20
 
21
- # rubyforge
22
- begin
23
- require 'rake/contrib/sshpublisher'
24
- namespace :rubyforge do
25
- desc "Release gem and RDoc documentation to RubyForge"
26
- task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
27
-
28
- namespace :release do
29
- desc "Publish RDoc to RubyForge."
30
- task :docs => [:rdoc] do
31
- config = YAML.load(
32
- File.read(File.expand_path('~/.rubyforge/user-config.yml'))
33
- )
34
- host = "#{config['username']}@rubyforge.org"
35
- remote_dir = "/var/www/gforge-projects/the-perfect-gem/"
36
- local_dir = 'rdoc'
37
-
38
- Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
39
- end
40
- end
41
- end
42
- rescue LoadError
43
- puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
44
- end
45
-
46
21
  require 'rake/testtask'
47
22
  Rake::TestTask.new(:test) do |test|
48
23
  test.libs << 'lib' << 'test'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.3
1
+ 0.3.6
@@ -1,7 +1,5 @@
1
1
  module Mutter
2
2
  class Mutterer
3
- attr_accessor :styles
4
-
5
3
  @stream = STDOUT
6
4
 
7
5
  # Initialize the styles, and load the defaults from +styles.yml+
@@ -11,28 +9,27 @@ module Mutter
11
9
  #
12
10
  def initialize obj = {}
13
11
  self.reset
14
- load File.dirname(__FILE__) + "/styles"
12
+ @defaults = load File.dirname(__FILE__) + "/styles"
15
13
 
16
14
  case obj
17
15
  when Hash # A style definition: expand quick-styles and merge with @styles
18
- obj = obj.inject({}) do |h, (k, v)|
16
+ @styles = obj.inject({}) do |h, (k, v)|
19
17
  h.merge k =>
20
18
  (v.is_a?(Hash) ? v : { :match => v, :style => [k].flatten })
21
19
  end
22
- @styles.merge! obj
23
20
  when Array # An array of styles to be activated
24
21
  @active = obj
25
22
  when Symbol # A single style to be activated
26
- self.<< obj
23
+ self << obj
27
24
  when String # The path of a yaml style-sheet
28
- load obj
25
+ @styles = load obj
29
26
  else raise ArgumentError
30
27
  end
31
28
 
32
29
  #
33
30
  # Create an instance method for each style
34
31
  #
35
- @styles.keys.each do |style|
32
+ self.styles.keys.each do |style|
36
33
  (class << self; self end).class_eval do
37
34
  define_method style do |msg|
38
35
  say msg, style
@@ -41,8 +38,19 @@ module Mutter
41
38
  end
42
39
  end
43
40
 
44
- def clear
45
- @active, @styles = [], {}
41
+ def styles
42
+ @defaults.merge @styles
43
+ end
44
+
45
+ def clear opt = :all
46
+ case opt
47
+ when :user then @styles = {}
48
+ when :default then @defaults = {}
49
+ when :styles then @styles, @defaults = {}, {}
50
+ when :active then @active = []
51
+ when :all then @active, @styles, @defaults = [], {}, {}
52
+ else raise ArgumentError, "[:user, :default, :active, :all] only"
53
+ end
46
54
  self
47
55
  end
48
56
  alias :reset clear
@@ -53,11 +61,10 @@ module Mutter
53
61
  #
54
62
  def load styles
55
63
  styles += '.yml' unless styles =~ /\.ya?ml/
56
- @defaults = YAML.load_file(styles).inject({}) do |h, (key, value)|
64
+ YAML.load_file(styles).inject({}) do |h, (key, value)|
57
65
  value = { :match => value['match'], :style => value['style'] }
58
66
  h.merge key.to_sym => value
59
67
  end
60
- @styles.merge! @defaults
61
68
  end
62
69
 
63
70
  #
@@ -128,13 +135,13 @@ module Mutter
128
135
  # the matches are sent to +stylize+
129
136
  #
130
137
  def parse string
131
- @styles.inject(string) do |str, (name, options)|
132
- glyph, styles = options[:match], options[:style]
138
+ self.styles.inject(string) do |str, (name, options)|
139
+ glyph, style = options[:match], options[:style]
133
140
  if glyph.is_a? Array
134
- str.gsub(/#{Regexp.escape(glyph.first)}(.+?)
135
- #{Regexp.escape(glyph.last)}/x) { stylize $1, styles }
141
+ str.gsub(/#{Regexp.escape(glyph.first)}(.*?)
142
+ #{Regexp.escape(glyph.last)}/x) { stylize $1, style }
136
143
  else
137
- str.gsub(/(#{Regexp.escape(glyph)}+)(.+?)\1/) { stylize $2, styles }
144
+ str.gsub(/(#{Regexp.escape(glyph)}+)(.*?)\1/) { stylize $2, style }
138
145
  end
139
146
  end
140
147
  end
data/mutter.gemspec CHANGED
@@ -1,12 +1,15 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
1
4
  # -*- encoding: utf-8 -*-
2
5
 
3
6
  Gem::Specification.new do |s|
4
7
  s.name = %q{mutter}
5
- s.version = "0.3.3"
8
+ s.version = "0.3.6"
6
9
 
7
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
11
  s.authors = ["cloudhead"]
9
- s.date = %q{2009-09-02}
12
+ s.date = %q{2009-10-06}
10
13
  s.description = %q{the tiny CLI library}
11
14
  s.email = %q{self@cloudhead.net}
12
15
  s.extra_rdoc_files = [
data/spec/mutter_spec.rb CHANGED
@@ -43,17 +43,17 @@ describe Mutter do
43
43
  out.should == "\e[1mhello * world\e[22m\n"
44
44
  end
45
45
 
46
- it "should set defaults at the instance level" do
46
+ it "should set actives at the instance level" do
47
47
  Mutter.new([:bold, :underline]).say "hello mutter!"
48
48
  out.should == "\e[4m\e[1mhello mutter!\e[22m\e[24m\n"
49
49
  end
50
50
 
51
- it "should set defaults at the method level" do
51
+ it "should set actives at the method level" do
52
52
  Mutter.say "hello mutter!", :bold, :underline
53
53
  out.should == "\e[4m\e[1mhello mutter!\e[22m\e[24m\n"
54
54
  end
55
55
 
56
- it "should set defaults at both levels" do
56
+ it "should set actives at both levels" do
57
57
  Mutter.new(:bold).say "hello mutter!", :underline, :yellow
58
58
  out.should == "\e[33m\e[4m\e[1mhello mutter!\e[22m\e[24m\e[39m\n"
59
59
  end
@@ -69,17 +69,24 @@ describe Mutter do
69
69
  Mutter.new(style).say "alert!", :alert
70
70
  out.should == "\e[31m\e[1malert!\e[22m\e[39m\n"
71
71
  end
72
-
73
- it "should work with shorthand custom styles" do
74
- Mutter.new({:bold => '~'}).say "~hello mutter!~"
75
- out.should == "\e[1mhello mutter!\e[22m\n"
76
- end
77
-
78
- it "should color" do
79
- Mutter.new({:cyan => ['<', '>']}).say "<hello mutter!>"
80
- out.should == "\e[36mhello mutter!\e[39m\n"
72
+
73
+ describe "in shorthand form" do
74
+ it "should work with simple shorthand styles" do
75
+ Mutter.new({:bold => '~'}).say "~hello mutter!~"
76
+ out.should == "\e[1mhello mutter!\e[22m\n"
77
+ end
78
+
79
+ it "should work with complex shorthand styles" do
80
+ Mutter.new({:cyan => ['<', '>']}).say "<hello mutter!>"
81
+ out.should == "\e[36mhello mutter!\e[39m\n"
82
+ end
83
+
84
+ it "should work with multiple shorthand styles" do
85
+ Mutter.new({[:cyan, :underline] => '~'}).say "~hello mutter!~"
86
+ out.should == "\e[4m\e[36mhello mutter!\e[39m\e[24m\n"
87
+ end
81
88
  end
82
-
89
+
83
90
  it "should mix styles" do
84
91
  Mutter.new({:cyan => '~'}).say "_*hello* ~world~_"
85
92
  out.should == "\e[4m\e[1mhello\e[22m \e[36mworld\e[39m\e[24m\n"
@@ -89,11 +96,6 @@ describe Mutter do
89
96
  Mutter.new({:cyan => '~'}).say "~[hello mutter!]~"
90
97
  out.should == "\e[36m\e[7mhello mutter!\e[27m\e[39m\n"
91
98
  end
92
-
93
- it "should work with multiple shorthand styles" do
94
- Mutter.new({[:cyan, :underline] => '~'}).say "~hello mutter!~"
95
- out.should == "\e[4m\e[36mhello mutter!\e[39m\e[24m\n"
96
- end
97
99
 
98
100
  it "should load styles from a yaml" do
99
101
  Mutter.new("spec/style").say "{important message!}"
@@ -105,6 +107,17 @@ describe Mutter do
105
107
  out.should == "\e[33m\e[4m\e[1mimportant message!\e[22m\e[24m\e[39m\n"
106
108
  end
107
109
 
110
+ it "should clear all styles" do
111
+ Mutter.new.clear(:all).say "[hello] *world*"
112
+ out.should == "[hello] *world*\n"
113
+ end
114
+
115
+ it "should clear active styles" do
116
+ mut = Mutter.new(:bold)
117
+ mut.clear(:active).say "hello"
118
+ out.should == "hello\n"
119
+ end
120
+
108
121
  it "should add and remove active styles" do
109
122
  mut = Mutter.new
110
123
  mut << :bold << :underline << :inverse
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mutter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - cloudhead
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-02 00:00:00 -04:00
12
+ date: 2009-10-06 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15