platem 0.0.1 → 0.0.2

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.
@@ -1,5 +1,20 @@
1
1
  require "platem/version"
2
+ require "platem/templates"
2
3
 
3
4
  module Platem
4
- # Your code goes here...
5
+ class << self
6
+ attr_accessor :template_root
7
+ end
8
+
9
+ module ClassMethods
10
+ def template_root(root)
11
+ Platem.template_root = root
12
+ end
13
+ end
14
+
15
+ def self.included(klass)
16
+ klass.extend ClassMethods
17
+ klass.send(:include, Platem::Templates)
18
+ end
19
+
5
20
  end
@@ -2,19 +2,15 @@ require 'ostruct'
2
2
  require 'tempfile'
3
3
 
4
4
  module Platem
5
- module Template
5
+ module Templates
6
6
  class ErbBinding < OpenStruct
7
7
  def get_binding
8
8
  binding
9
9
  end
10
10
  end
11
11
 
12
- def template(template)
13
- File.expand_path("../../../templates/#{template}", __FILE__)
14
- end
15
-
16
12
  def compile_template(template, vars)
17
- contents = File.read(template(template))
13
+ contents = File.read(template_file(template))
18
14
  struct = ErbBinding.new(vars)
19
15
  ERB.new(contents).result(struct.send(:get_binding))
20
16
  end
@@ -29,8 +25,8 @@ module Platem
29
25
  end
30
26
  end
31
27
 
32
- def template(template)
33
- File.expand_path("../../../templates/#{template}", __FILE__)
28
+ def template_file(template)
29
+ File.join(Platem.template_root, template)
34
30
  end
35
31
 
36
32
  def display_template(template)
@@ -38,7 +34,7 @@ module Platem
38
34
  end
39
35
 
40
36
  def read_template(template)
41
- File.read template(template)
37
+ File.read template_file(template)
42
38
  end
43
39
  end
44
40
  end
@@ -1,3 +1,3 @@
1
1
  module Platem
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,22 +1,45 @@
1
- require 'platem/template'
1
+ require_relative '../../lib/platem'
2
2
 
3
3
  class Subject
4
- include Platem::Template
4
+ include Platem
5
5
  end
6
6
 
7
- describe Platem::Template do
7
+ describe Platem do
8
8
  subject { Subject.new }
9
9
 
10
- describe '#template' do
10
+ describe '.template_root=' do
11
+ it "sets the template_root" do
12
+ Platem.template_root = '/etc/templates'
13
+ Platem.template_root.should == '/etc/templates'
14
+ end
15
+ end
16
+
17
+ describe '#template_root' do
18
+ it "sets the template root" do
19
+ class Subject
20
+ template_root '/etc/xyz'
21
+ end
22
+ Platem.template_root.should == '/etc/xyz'
23
+ end
24
+ end
25
+ end
26
+
27
+ describe Platem::Templates do
28
+ subject { Subject.new }
29
+
30
+ before(:each) do
31
+ Platem.template_root = '/etc/templates'
32
+ end
33
+
34
+ describe '#template_file' do
11
35
  it "returns the path to a template" do
12
- File.should_receive(:expand_path).with('../../../templates/path/template', anything).and_return('something')
13
- subject.template('path/template').should == "something"
36
+ subject.template_file('path/template').should == "/etc/templates/path/template"
14
37
  end
15
38
  end
16
39
 
17
40
  describe '#compile_template' do
18
41
  it "returns the string for the template" do
19
- template = subject.template('vhosts/nginx/rails3.erb')
42
+ template = subject.template_file('vhosts/nginx/rails3.erb')
20
43
  File.should_receive(:read).with(template).and_return('abcdef <%= app.name %> <%= app.path %>')
21
44
 
22
45
  app = stub(
@@ -72,7 +95,7 @@ describe Platem::Template do
72
95
 
73
96
  describe '#read_template' do
74
97
  it "reads the contents of a template to a string" do
75
- file = File.expand_path("../../../templates/template", __FILE__)
98
+ file = subject.template_file('template')
76
99
  File.should_receive(:read).with(file)
77
100
  subject.read_template 'template'
78
101
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: platem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-31 00:00:00.000000000 Z
12
+ date: 2012-04-10 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ERB templates
15
15
  email:
@@ -24,7 +24,7 @@ files:
24
24
  - README.md
25
25
  - Rakefile
26
26
  - lib/platem.rb
27
- - lib/platem/template.rb
27
+ - lib/platem/templates.rb
28
28
  - lib/platem/version.rb
29
29
  - platem.gemspec
30
30
  - spec/platem/template_spec.rb