paramsfile 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENCE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2013 Gareth Rees
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ Paramsfile
2
+ ==========
3
+
4
+ Dynamically generate configuration files with YAML and Mustache
5
+
6
+ Usage
7
+ -----
8
+
9
+ Create a template
10
+
11
+ ```mustache
12
+ # ./nginx.conf.mustache
13
+
14
+ server {
15
+ server_name {{ app_domain }};
16
+ }
17
+ ```
18
+
19
+ Create a parameters file
20
+
21
+ ```yaml
22
+ # ./parameters.yml
23
+
24
+ sprocketcorp:
25
+ app_domain: www.sprocketcorp.com
26
+ ```
27
+
28
+ Generate the config file
29
+
30
+ ```sh
31
+ $ ./bin/paramsfile nginx.conf.mustache
32
+ ```
data/bin/paramsfile ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ require 'yaml'
3
+ require 'pathname'
4
+
5
+ bin_file = Pathname.new(__FILE__).realpath
6
+ $:.unshift File.expand_path('../../lib', bin_file)
7
+ require 'paramsfile'
8
+
9
+ DEFAULT_PARAMS_FILE = './parameters.yml'
10
+
11
+ opts = { :template => ARGV[0],
12
+ :params => File.expand_path(ARGV[1] || DEFAULT_PARAMS_FILE) }
13
+
14
+ file = Paramsfile::Paramsfile.new(opts[:template], YAML.load(File.open(opts[:params])))
15
+
16
+ puts "==> Writing..."
17
+ file.write
18
+ puts "==> Done!"
data/lib/paramsfile.rb ADDED
@@ -0,0 +1,3 @@
1
+ Dir[File.dirname(__FILE__) + '/paramsfile/*.rb'].each do |file|
2
+ require file
3
+ end
@@ -0,0 +1,33 @@
1
+ require 'mustache'
2
+
3
+ module Paramsfile
4
+ class Paramsfile < Mustache
5
+
6
+ attr_accessor :data
7
+
8
+ # path - String path to template
9
+ # data - Hash of data to fill template with
10
+ def initialize(path, data)
11
+ self.template_path = path
12
+ self.data = data
13
+ end
14
+
15
+ def write
16
+ File.open(config_file_name, 'w') do |file|
17
+ file.write(render_data)
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def render_data
24
+ render(File.read(template_path), data[data.keys.first])
25
+ end
26
+
27
+ def config_file_name
28
+ basename = File.basename(template_path)
29
+ basename.gsub(File.extname(basename), '')
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module Paramsfile
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'paramsfile/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'paramsfile'
8
+ gem.version = Paramsfile::VERSION
9
+ gem.authors = ['Gareth Rees']
10
+ gem.email = ['gareth@garethrees.co.uk']
11
+ gem.description = %q{Dynamically generate configuration files with YAML and Mustache}
12
+ gem.summary = %q{YAML -> Mustache -> Configuration File}
13
+ gem.homepage = 'http://github.com/garethrees/paramsfile'
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ['lib']
19
+
20
+ gem.add_dependency 'mustache'
21
+
22
+ end
@@ -0,0 +1,19 @@
1
+ server {
2
+ listen {{ nginx.port }} default_server;
3
+ server_name {{ app_domain }};
4
+ root /opt/{{ app_name }}/public;
5
+
6
+ client_max_body_size 20M;
7
+ keepalive_timeout 10;
8
+
9
+ passenger_enabled on;
10
+ passenger_user passenger;
11
+ passenger_show_version_in_header off;
12
+ passenger_friendly_error_pages off;
13
+
14
+ rails_env {{ rails_env }};
15
+
16
+ error_page 500 502 503 504 /500.html;
17
+ error_page 404 /404.html;
18
+ error_page 422 /422.html;
19
+ }
@@ -0,0 +1,8 @@
1
+ sprocketcorp:
2
+ app_name: sprocketcorp
3
+ app_domain: www.sprocketcorp.net
4
+ rails_env: production
5
+ nginx:
6
+ port: 80
7
+
8
+
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paramsfile
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gareth Rees
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mustache
16
+ requirement: &70221538266520 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70221538266520
25
+ description: Dynamically generate configuration files with YAML and Mustache
26
+ email:
27
+ - gareth@garethrees.co.uk
28
+ executables:
29
+ - paramsfile
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - Gemfile
34
+ - LICENCE
35
+ - README.md
36
+ - bin/paramsfile
37
+ - lib/paramsfile.rb
38
+ - lib/paramsfile/paramsfile.rb
39
+ - lib/paramsfile/version.rb
40
+ - paramsfile.gemspec
41
+ - spec/fixtures/nginx.conf.mustache
42
+ - spec/fixtures/parameters.yml
43
+ homepage: http://github.com/garethrees/paramsfile
44
+ licenses: []
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 1.8.15
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: YAML -> Mustache -> Configuration File
67
+ test_files:
68
+ - spec/fixtures/nginx.conf.mustache
69
+ - spec/fixtures/parameters.yml
70
+ has_rdoc: