templater 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/templater.rb CHANGED
@@ -40,6 +40,6 @@ module Templater
40
40
  class MalformattedArgumentError < ArgumentError #:nodoc:
41
41
  end
42
42
 
43
- VERSION = '0.1.4'
43
+ VERSION = '0.1.5'
44
44
 
45
45
  end
@@ -4,10 +4,9 @@ module Templater
4
4
 
5
5
  class Generator
6
6
 
7
- def initialize(generator_name, destination_root, manifold, name, version)
8
- @destination_root, @manifold, @name, @version = destination_root, manifold, name, version
9
- @generator_name = generator_name
10
- @generator_class = @manifold.generator(@generator_name)
7
+ def initialize(generator_name, generator_class, destination_root, name, version)
8
+ @destination_root, @generator_name, @generator_class = destination_root, generator_name, generator_class
9
+ @name, @version = name, version
11
10
  end
12
11
 
13
12
  def version
@@ -17,8 +17,8 @@ module Templater
17
17
 
18
18
  if arguments.first and not arguments.first =~ /^-/ and not arguments.first == "help"
19
19
  generator_name = arguments.shift
20
- if manifold.generator(generator_name)
21
- Generator.new(generator_name, destination_root, manifold, name, version).run(arguments)
20
+ if generator_class = manifold.generator(generator_name)
21
+ Generator.new(generator_name, generator_class, destination_root, name, version).run(arguments)
22
22
  else
23
23
  Manifold.new(destination_root, manifold, name, version).run(arguments)
24
24
  end
@@ -332,7 +332,7 @@ module Templater
332
332
  unless ::File.directory?(action)
333
333
  action = action.sub("#{source_root}/", '')
334
334
 
335
- if template_extensions.include?(::File.extname(action)[1..-1]) or template_extensions.include?(::File.basename(action))
335
+ if template_extensions.include?(::File.extname(action.sub(/\.%.+%$/,''))[1..-1]) or template_extensions.include?(::File.basename(action))
336
336
  template(action.downcase.gsub(/[^a-z0-9]+/, '_').to_sym, action, action)
337
337
  else
338
338
  file(action.downcase.gsub(/[^a-z0-9]+/, '_').to_sym, action, action)
@@ -499,7 +499,15 @@ module Templater
499
499
 
500
500
  # Invokes the templates for this generator
501
501
  def invoke!
502
- templates.each { |t| t.invoke! }
502
+ actions.each { |t| t.invoke! }
503
+ end
504
+
505
+ # Renders all actions in this generator. Use this to verify that rendering templates raises no errors.
506
+ #
507
+ # === Returns
508
+ # [String]:: The results of the rendered actions
509
+ def render!
510
+ actions.map { |t| t.render }
503
511
  end
504
512
 
505
513
  # Returns this generator's source root
@@ -69,13 +69,26 @@ describe Templater::Generator, '.glob!' do
69
69
 
70
70
  @instance.templates.map { |t| t.name }.should == [
71
71
  :arg_js,
72
+ :hellothar_html_feh_,
72
73
  :readme,
73
74
  :subfolder_monkey_rb,
74
- :test_rb
75
+ :test_rb,
75
76
  ]
76
77
  @instance.files.map { |f| f.name }.should == [
78
+ :hellothar_feh_,
77
79
  :subfolder_jessica_alba_jpg
78
80
  ]
79
81
  end
80
82
 
83
+ it "should ignore ending '.%..%' and look at the extension preceding it" do
84
+ @generator_class.glob!
85
+
86
+ @instance = @generator_class.new('/tmp/destination')
87
+
88
+ @instance.template(:hellothar_html_feh_).source.should == template_path("glob/hellothar.html.%feh%")
89
+ @instance.template(:hellothar_html_feh_).destination.should == "/tmp/destination/hellothar.html.%feh%"
90
+
91
+ @instance.file(:hellothar_feh_).source.should == template_path("glob/hellothar.%feh%")
92
+ @instance.file(:hellothar_feh_).destination.should == "/tmp/destination/hellothar.%feh%"
93
+ end
81
94
  end
@@ -94,13 +94,13 @@ describe Templater::Generator, '#invoke!' do
94
94
  @generator_class = Class.new(Templater::Generator)
95
95
  end
96
96
 
97
- it "should invoke all templates" do
97
+ it "should invoke all actions" do
98
98
  template1 = mock('a template')
99
99
  template2 = mock('another template')
100
100
 
101
101
  instance = @generator_class.new('/tmp')
102
102
 
103
- instance.should_receive(:templates).and_return([template1, template2])
103
+ instance.should_receive(:actions).and_return([template1, template2])
104
104
  template1.should_receive(:invoke!)
105
105
  template2.should_receive(:invoke!)
106
106
 
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Templater::Generator, '#render!' do
4
+
5
+ before do
6
+ @generator_class = Class.new(Templater::Generator)
7
+ end
8
+
9
+ it "should render all actions and return an array of the results" do
10
+ template1 = mock('a template')
11
+ template2 = mock('another template')
12
+
13
+ instance = @generator_class.new('/tmp')
14
+
15
+ instance.should_receive(:actions).and_return([template1, template2])
16
+ template1.should_receive(:render).and_return("oh my")
17
+ template2.should_receive(:render).and_return("monkey")
18
+
19
+ instance.render!.should == ["oh my", "monkey"]
20
+ end
21
+ end
@@ -0,0 +1 @@
1
+ meh
@@ -0,0 +1 @@
1
+ <a href="hello.jpg">hello thar</a>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: templater
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Nicklas
@@ -9,7 +9,7 @@ autorequire: templater
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-02 00:00:00 +02:00
12
+ date: 2008-08-07 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -86,6 +86,7 @@ files:
86
86
  - spec/generator/invocations_spec.rb
87
87
  - spec/generator/invoke_spec.rb
88
88
  - spec/generator/option_spec.rb
89
+ - spec/generator/render_spec.rb
89
90
  - spec/generator/source_root_getter_spec.rb
90
91
  - spec/generator/source_root_spec.rb
91
92
  - spec/generator/template_getter_spec.rb
@@ -108,6 +109,8 @@ files:
108
109
  - spec/templates/erb.rbt
109
110
  - spec/templates/glob
110
111
  - spec/templates/glob/arg.js
112
+ - spec/templates/glob/hellothar.%feh%
113
+ - spec/templates/glob/hellothar.html.%feh%
111
114
  - spec/templates/glob/README
112
115
  - spec/templates/glob/subfolder
113
116
  - spec/templates/glob/subfolder/jessica_alba.jpg