platem 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in platem.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Felipe Coury
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Platem
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'platem'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install platem
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/lib/platem.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "platem/version"
2
+
3
+ module Platem
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,44 @@
1
+ require 'ostruct'
2
+ require 'tempfile'
3
+
4
+ module Platem
5
+ module Template
6
+ class ErbBinding < OpenStruct
7
+ def get_binding
8
+ binding
9
+ end
10
+ end
11
+
12
+ def template(template)
13
+ File.expand_path("../../../templates/#{template}", __FILE__)
14
+ end
15
+
16
+ def compile_template(template, vars)
17
+ contents = File.read(template(template))
18
+ struct = ErbBinding.new(vars)
19
+ ERB.new(contents).result(struct.send(:get_binding))
20
+ end
21
+
22
+ def create_from_template(file, template, vars = {})
23
+ File.open(file, 'w') { |f| f.write compile_template(template, vars) }
24
+ end
25
+
26
+ def temp_from_template(template)
27
+ Tempfile.new(File.basename(template)).tap do |file|
28
+ create_from_template file.path, template
29
+ end
30
+ end
31
+
32
+ def template(template)
33
+ File.expand_path("../../../templates/#{template}", __FILE__)
34
+ end
35
+
36
+ def display_template(template)
37
+ puts read_template(template)
38
+ end
39
+
40
+ def read_template(template)
41
+ File.read template(template)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module Platem
2
+ VERSION = "0.0.1"
3
+ end
data/platem.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/platem/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Felipe Coury"]
6
+ gem.email = ["felipe.coury@gmail.com"]
7
+ gem.description = %q{ERB templates}
8
+ gem.summary = %q{Manages creation of files from ERB templates}
9
+ gem.homepage = "http://webbynode.com"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "platem"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Platem::VERSION
17
+ end
@@ -0,0 +1,80 @@
1
+ require 'platem/template'
2
+
3
+ class Subject
4
+ include Platem::Template
5
+ end
6
+
7
+ describe Platem::Template do
8
+ subject { Subject.new }
9
+
10
+ describe '#template' do
11
+ 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"
14
+ end
15
+ end
16
+
17
+ describe '#compile_template' do
18
+ it "returns the string for the template" do
19
+ template = subject.template('vhosts/nginx/rails3.erb')
20
+ File.should_receive(:read).with(template).and_return('abcdef <%= app.name %> <%= app.path %>')
21
+
22
+ app = stub(
23
+ :name => 'app1',
24
+ :path => '/var/app/app1',
25
+ :domain => 'webby.com',
26
+ :alaises => 'app2.webby.com app3.webby.com'
27
+ )
28
+
29
+ result = subject.compile_template('vhosts/nginx/rails3.erb', { :app => app })
30
+ result.should == "abcdef app1 /var/app/app1"
31
+ end
32
+ end
33
+
34
+ describe '#temp_from_template' do
35
+ let(:file) { stub(:tempfile) }
36
+ it "creates a tempfile with the template contents" do
37
+ Tempfile.should_receive(:new).with('app1.conf').and_return(file)
38
+ file.stub(:path => "/tmp/app1.conf.24722.0")
39
+ subject.should_receive(:create_from_template).with("/tmp/app1.conf.24722.0", "path/app1.conf")
40
+ subject.temp_from_template("path/app1.conf").should == file
41
+ end
42
+ end
43
+
44
+ describe '#create_from_template' do
45
+ let(:app) { stub }
46
+ let(:write_file) { stub }
47
+
48
+ it "creates a file with the template" do
49
+ subject.should_receive(:compile_template).with('vhosts/nginx/rails3.erb', { :app => app }).and_return('contents')
50
+ write_file.should_receive(:write).with('contents')
51
+ File.should_receive(:open).with('/tmp/app1.conf', 'w').and_yield(write_file)
52
+
53
+ subject.create_from_template('/tmp/app1.conf', 'vhosts/nginx/rails3.erb', { :app => app })
54
+ end
55
+
56
+ it "accepts empty params" do
57
+ subject.should_receive(:compile_template).with('vhosts/nginx/rails3.erb', {}).and_return('contents')
58
+ write_file.should_receive(:write).with('contents')
59
+ File.should_receive(:open).with('/tmp/app1.conf', 'w').and_yield(write_file)
60
+
61
+ subject.create_from_template('/tmp/app1.conf', 'vhosts/nginx/rails3.erb')
62
+ end
63
+ end
64
+
65
+ describe '#display_template' do
66
+ it 'prints out the contents of a template' do
67
+ subject.should_receive(:read_template).with('template').and_return('contents')
68
+ subject.should_receive(:puts).with('contents')
69
+ subject.display_template 'template'
70
+ end
71
+ end
72
+
73
+ describe '#read_template' do
74
+ it "reads the contents of a template to a string" do
75
+ file = File.expand_path("../../../templates/template", __FILE__)
76
+ File.should_receive(:read).with(file)
77
+ subject.read_template 'template'
78
+ end
79
+ end
80
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: platem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Felipe Coury
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-31 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ERB templates
15
+ email:
16
+ - felipe.coury@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.md
25
+ - Rakefile
26
+ - lib/platem.rb
27
+ - lib/platem/template.rb
28
+ - lib/platem/version.rb
29
+ - platem.gemspec
30
+ - spec/platem/template_spec.rb
31
+ homepage: http://webbynode.com
32
+ licenses: []
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 1.8.21
52
+ signing_key:
53
+ specification_version: 3
54
+ summary: Manages creation of files from ERB templates
55
+ test_files:
56
+ - spec/platem/template_spec.rb