thor 0.14.1 → 0.14.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -86,7 +86,7 @@ class Thor
86
86
  context = instance_eval('binding')
87
87
 
88
88
  create_file destination, nil, config do
89
- content = ERB.new(::File.binread(source), nil, '-').result(context)
89
+ content = ERB.new(::File.binread(source), nil, '-', '@output_buffer').result(context)
90
90
  content = block.call(content) if block
91
91
  content
92
92
  end
@@ -225,5 +225,22 @@ class Thor
225
225
  end
226
226
  alias :remove_dir :remove_file
227
227
 
228
+ private
229
+ attr_accessor :output_buffer
230
+ def concat(string)
231
+ @output_buffer.concat(string)
232
+ end
233
+
234
+ def capture(*args, &block)
235
+ with_output_buffer { block.call(*args) }
236
+ end
237
+
238
+ def with_output_buffer(buf = '') #:nodoc:
239
+ self.output_buffer, old_buffer = buf, output_buffer
240
+ yield
241
+ output_buffer
242
+ ensure
243
+ self.output_buffer = old_buffer
244
+ end
228
245
  end
229
246
  end
@@ -50,7 +50,7 @@ class Thor
50
50
  end
51
51
 
52
52
  def parse(args)
53
- @pile = args.dup
53
+ @pile = except_underscores(args.dup)
54
54
 
55
55
  while peek
56
56
  if current_is_switch?
@@ -169,6 +169,12 @@ class Thor
169
169
  @non_assigned_required.delete(option)
170
170
  send(:"parse_#{option.type}", switch)
171
171
  end
172
+
173
+ # Except underscores in commandline switches
174
+ def except_underscores(args)
175
+ args.map {|x| x =~ /^--/ ? x.gsub('_', '-') : x }
176
+ end
177
+
172
178
 
173
179
  end
174
180
  end
@@ -1,3 +1,3 @@
1
1
  class Thor
2
- VERSION = "0.14.1".freeze
2
+ VERSION = "0.14.2".freeze
3
3
  end
@@ -117,6 +117,13 @@ describe Thor::Actions do
117
117
  end
118
118
 
119
119
  describe "#template" do
120
+ it "allows using block helpers in the template" do
121
+ action :template, "doc/block_helper.rb"
122
+
123
+ file = File.join(destination_root, "doc/block_helper.rb")
124
+ File.read(file).must == "Hello world!"
125
+ end
126
+
120
127
  it "evaluates the template given as source" do
121
128
  runner.instance_variable_set("@klass", "Config")
122
129
  action :template, "doc/config.rb"
@@ -0,0 +1,3 @@
1
+ <% world do -%>
2
+ Hello
3
+ <% end -%>
@@ -37,6 +37,13 @@ FOO
37
37
  super
38
38
  base.source_paths.unshift(File.expand_path(File.join(File.dirname(__FILE__), "doc")))
39
39
  end
40
+
41
+ no_tasks do
42
+ def world(&block)
43
+ result = capture(&block)
44
+ concat(result.strip + " world!")
45
+ end
46
+ end
40
47
  end
41
48
 
42
49
  class ClearCounter < MyCounter
@@ -85,4 +92,4 @@ class TaskConflict < Thor::Group
85
92
  def group
86
93
  puts "group"
87
94
  end
88
- end
95
+ end
@@ -47,6 +47,11 @@ describe Thor::Options do
47
47
  it "accepts hashes" do
48
48
  Thor::Options.to_switches(:count => {:a => :b}).must == "--count a:b"
49
49
  end
50
+
51
+ it "accepts underscored options" do
52
+ Thor::Options.to_switches(:under_score_option => "foo bar").must == '--under_score_option "foo bar"'
53
+ end
54
+
50
55
  end
51
56
 
52
57
  describe "#parse" do
@@ -115,6 +120,19 @@ describe Thor::Options do
115
120
  parse("--asdf---asdf", "baz", "--foo", "--asdf---dsf--asdf").must == {"foo" => "--asdf---dsf--asdf"}
116
121
  check_unknown!
117
122
  end
123
+
124
+ it "excepts underscores in commandline args hash for boolean" do
125
+ create :foo_bar => :boolean
126
+ parse("--foo_bar")["foo_bar"].must == true
127
+ parse("--no_foo_bar")["foo_bar"].must == false
128
+ end
129
+
130
+ it "excepts underscores in commandline args hash for strings" do
131
+ create :foo_bar => :string, :baz_foo => :string
132
+ parse("--foo_bar", "baz")["foo_bar"].must == "baz"
133
+ parse("--baz_foo", "foo bar")["baz_foo"].must == "foo bar"
134
+ end
135
+
118
136
 
119
137
  describe "with no input" do
120
138
  it "and no switches returns an empty hash" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thor
3
3
  version: !ruby/object:Gem::Version
4
- hash: 37
4
+ hash: 35
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 14
9
- - 1
10
- version: 0.14.1
9
+ - 2
10
+ version: 0.14.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Yehuda Katz
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-09-17 00:00:00 +02:00
19
+ date: 2010-09-24 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies: []
22
22
 
@@ -78,6 +78,7 @@ files:
78
78
  - spec/core_ext/ordered_hash_spec.rb
79
79
  - spec/fixtures/application.rb
80
80
  - spec/fixtures/bundle/execute.rb
81
+ - spec/fixtures/doc/block_helper.rb
81
82
  - spec/fixtures/doc/config.rb
82
83
  - spec/group_spec.rb
83
84
  - spec/invocation_spec.rb
@@ -151,6 +152,7 @@ test_files:
151
152
  - spec/core_ext/ordered_hash_spec.rb
152
153
  - spec/fixtures/application.rb
153
154
  - spec/fixtures/bundle/execute.rb
155
+ - spec/fixtures/doc/block_helper.rb
154
156
  - spec/fixtures/doc/config.rb
155
157
  - spec/group_spec.rb
156
158
  - spec/invocation_spec.rb