templar 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -7,14 +7,14 @@ Usage
7
7
  -----
8
8
 
9
9
  Once **Templar** is installed and configured, it will automatically keep your local copies of configurations up-to-date. It
10
- does this by running prior to initialization of the Rails environment.
10
+ does this by running prior to initialization of the Rails (and Capistrano) environment.
11
11
 
12
12
  The *Example* section below, will give you the best idea of the usage of **Templar**.
13
13
 
14
14
  Example
15
15
  -------
16
16
 
17
- Most of this example is now handled by `rake templar:file[filename]`.
17
+ Most of this example is now handled by `rake templar:file[filename]`, this task is currently only supported by Rails.
18
18
 
19
19
  This will take you, step by step, through the process of configuring and using **Templar** to manage the database.yml file
20
20
  in a Rails application.
@@ -129,9 +129,9 @@ It will also have added some lines to the `.gitignore` file.
129
129
  Confguration
130
130
  ------------
131
131
 
132
- There are two configuration files for **Templar**.
132
+ There are two types of configuration files for **Templar**.
133
133
 
134
- ### config/templar.yml
134
+ ### Templar Configuration (config/templar.yml)
135
135
 
136
136
  The `templar.yml` file is the primary configuration for **Templar**. Most often, you will only need to change the
137
137
  `templates` section of this file.
@@ -157,12 +157,7 @@ always_update: false
157
157
  data_file: data.yml
158
158
  ```
159
159
 
160
- ### config/templar/data.sample.yml
161
-
162
- This file should contain the default local development environment configuration data. This is used to create the
163
- `config/templar/data.yml` file for users when they first setup their local development environment for the app.
164
-
165
- ### config/templar/data.yml
160
+ ### Configuration Data (config/templar/data.yml)
166
161
 
167
162
  This file is ignored by git automatically (as part of the installation process). This should contain the configuration
168
163
  for the local development environment.
@@ -182,8 +177,27 @@ database:
182
177
  This file contains any of the data that will be inserted into the template configuration files. Such that if you have a
183
178
  `database.yml.erb` file managed by **Templar**, you can populate the data from the database block in the `data.yml` file.
184
179
 
180
+ ### Configuration Data (config/templar/data.sample.yml)
181
+
182
+ This file should contain the default local development environment configuration data. This is used to create the
183
+ `config/templar/data.yml` file for users when they first setup their local development environment for the app.
184
+
185
+
185
186
  See *Example* for more info.
186
187
 
188
+ Capistrano
189
+ ----------
190
+
191
+ The Capistrano integration is used for one specific purpose. It is rare and few will need it.
192
+
193
+ You can use Templar in conjunction with Capistrano to manage templated configuration files which you will be pushing
194
+ directly to the server using Capistrano's push method.
195
+
196
+ This allows you to have all the same functionality of templar, when running in something other than Ruby and Rails.
197
+
198
+ I use this to manage properties files for a J2EE application in SVN, and use Capistrano to push the properties
199
+ files to the servers
200
+
187
201
  TODO
188
202
  ----
189
203
 
@@ -1,6 +1,12 @@
1
1
  require 'templar'
2
2
  require 'awesome_print'
3
3
 
4
+ ##
5
+ # Capistrano integration
6
+ # Generally you will not need to use this, unless you specifically want to use
7
+ # capistrano to deploy templar templates directly to a server (rather than
8
+ # using deploy via remote cache)
9
+
4
10
  configuration = Capistrano::Configuration.respond_to?(:instance) ?
5
11
  Capistrano::Configuration.instance(:must_exist) :
6
12
  Capistrano.configuration(:must_exist)
@@ -1,19 +1,16 @@
1
- # stolen from mjijackson
2
- # http://mjijackson.com/2010/02/flexible-ruby-config-objects
3
-
1
+ ##
2
+ # Templar is a configuration template manager.
4
3
  module Templar
4
+ ##
5
+ # Basic, easy-to-use configuration object.
6
+ # @note would like to use Ribbon, but it only supports 1.9.x from what I've seen.
7
+ # @see http://mjijackson.com/2010/02/flexible-ruby-config-objects
5
8
  class Config
6
9
  def initialize(data={ })
7
10
  @data = { }
8
11
  update!(data)
9
12
  end
10
13
 
11
- def update!(data)
12
- data.each do |key, value|
13
- self[key] = value
14
- end
15
- end
16
-
17
14
  def [](key)
18
15
  @data[key.to_sym]
19
16
  end
@@ -38,5 +35,11 @@ module Templar
38
35
  self[sym]
39
36
  end
40
37
  end
38
+
39
+ def update!(data)
40
+ data.each do |key, value|
41
+ self[key] = value
42
+ end
43
+ end
41
44
  end
42
45
  end
@@ -1,4 +1,8 @@
1
+ ##
2
+ # Templar is a configuration template manager.
1
3
  module Templar
4
+ ##
5
+ # Rails 3.x integrations
2
6
  class Engine < Rails::Engine
3
7
  engine_name "templar"
4
8
  end
@@ -1,11 +1,20 @@
1
1
  require 'erubis'
2
2
  require 'templar/config'
3
3
 
4
+ ##
5
+ # Templar is a configuration template manager.
4
6
  module Templar
7
+ ##
8
+ # This is the implementation of template processing.
5
9
  class Processor
10
+ # @return [Templar::Config] contains the templar configuration data, usually config/templar.yml
6
11
  attr_accessor :config
12
+ # @return [Templar::Config] contains the data loaded from the YAML data file, usually config/templar/data.yml
7
13
  attr_accessor :data
8
14
 
15
+ ##
16
+ # Get a new processor
17
+ # @param [Hash] config_overrides these values will be merged on top of the defaults.
9
18
  def initialize(config_overrides = {})
10
19
  {:print_format => " templar: (update: %s) %s => %s"}.merge(config_overrides)
11
20
  yaml_hash = YAML.load_file('config/templar.yml') || {}
@@ -18,6 +27,9 @@ module Templar
18
27
  @data = Templar::Config.new(data_hash)
19
28
  end
20
29
 
30
+ ##
31
+ # Process configuration templates
32
+ # @raise [TemplarException] Raises exception when it cannot find files
21
33
  def process
22
34
  @use_environments = @config.use_environments
23
35
  @environment = @config.environment
@@ -26,14 +38,26 @@ module Templar
26
38
  process_templates
27
39
  end
28
40
 
41
+
42
+ ##
43
+ # Determine the data file to use.
44
+ # If #{directory}/data.yml exists, use that, otherwise use #{directory}/data.sample.yml
45
+ # data.sample.yml should contain non-development template data.
29
46
  def data_file
30
47
  @data_file ||= File.exists?("#{@directory}/data.yml") ? "#{@directory}/data.yml" : "#{@directory}/data.sample.yml"
31
48
  end
32
49
 
50
+ ##
51
+ # Load the template configuration data, usually config/templar/data.yml
52
+ # @return [Templar::Config] load the template configuration data.
33
53
  def load_data
34
54
  @data ||= Templar::Config.new(YAML::load(File.open(data_file)))
35
55
  end
36
56
 
57
+ ##
58
+ # Process all defined template files
59
+ #
60
+ # @raise [TemplarException] Raises exception when it cannot find files
37
61
  def process_templates
38
62
  if File.exists?(data_file) && @templates.count
39
63
 
@@ -45,6 +69,11 @@ module Templar
45
69
  end
46
70
  end
47
71
 
72
+ ##
73
+ # Process template file
74
+ # @param [String] source The source (template) file.
75
+ # @param [String] dest The destination for the processed file.
76
+ # @raise [TemplarException] Raises exception when it cannot find files
48
77
  def process_template(source, dest)
49
78
  update = update_file?(source, dest)
50
79
  puts @config.print_format % [update, source, dest]
@@ -58,13 +87,25 @@ module Templar
58
87
  end
59
88
  end
60
89
 
90
+ ##
91
+ # Check to see if we should update a file
92
+ #
93
+ # always_update will force the file to always be updated
94
+ # checking if data_file is newer verifies that files get regenerated when every the data file changes
95
+ # otherwise, check to see if the template file has been modified more recently than the destination
96
+ #
97
+ # @param [String] source The source (template) file.
98
+ # @param [String] dest The destination for the processed file.
99
+ # @return [Boolean] true if we should update the file
61
100
  def update_file?(source, dest)
62
- # always_update will force the file to always be updated
63
- # checking if data_file is newer verifies that files get regenerated when every the data file changes
64
- # otherwise, check to see if the template file has been modified more recently than the destination
65
101
  @config.always_update == true || template_newer?(@data_file, dest) == true || template_newer?(source, dest) == true
66
102
  end
67
103
 
104
+ ##
105
+ # Check to see if source is newer than the destination.
106
+ # @param [String] source The source (template) file.
107
+ # @param [String] dest The destination for the processed file.
108
+ # @return [Boolean] true if source is newer or destination does not exist.
68
109
  def template_newer?(source, dest)
69
110
  return true unless File.exists?(dest)
70
111
  File.mtime(source) > File.mtime(dest)
@@ -3,7 +3,7 @@ if !defined?(Templar::VERSION)
3
3
  module Version #:nodoc:
4
4
  MAJOR = 0
5
5
  MINOR = 7
6
- TINY = 1
6
+ TINY = 2
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
9
9
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: templar
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 1
10
- version: 0.7.1
9
+ - 2
10
+ version: 0.7.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Shawn Catanzarite
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-04-23 00:00:00 Z
18
+ date: 2012-04-27 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rake
@@ -46,7 +46,7 @@ dependencies:
46
46
  prerelease: false
47
47
  requirement: *id002
48
48
  - !ruby/object:Gem::Dependency
49
- name: sqlite3
49
+ name: yard
50
50
  version_requirements: &id003 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
@@ -59,6 +59,20 @@ dependencies:
59
59
  type: :development
60
60
  prerelease: false
61
61
  requirement: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: sqlite3
64
+ version_requirements: &id004 !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ type: :development
74
+ prerelease: false
75
+ requirement: *id004
62
76
  description: "[config] templar allows you to manage development environment configuration files as templates."
63
77
  email:
64
78
  - scatanzarite@gmail.com
@@ -176,3 +190,4 @@ test_files:
176
190
  - test/dummy/script/rails
177
191
  - test/templar_test.rb
178
192
  - test/test_helper.rb
193
+ has_rdoc: