mattock 0.2.11 → 0.2.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -91,6 +91,20 @@ module Mattock
91
91
  end
92
92
  end
93
93
 
94
+ def to_hash(obj)
95
+ hash = if Configurable > superclass
96
+ superclass.to_hash(obj)
97
+ else
98
+ {}
99
+ end
100
+ hash.merge( Hash[default_values.keys.zip(default_values.keys.map{|key|
101
+ begin
102
+ obj.__send__(key)
103
+ rescue NoMethodError
104
+ end
105
+ }).to_a])
106
+ end
107
+
94
108
  #Creates an anonymous Configurable - useful in complex setups for nested
95
109
  #settings
96
110
  #@example SSH options
@@ -151,6 +165,10 @@ module Mattock
151
165
  self
152
166
  end
153
167
 
168
+ def to_hash
169
+ self.class.to_hash(self)
170
+ end
171
+
154
172
  #Call during initialize to set default values on settings - if you're using
155
173
  #Configurable outside of Mattock, be sure this gets called.
156
174
  def setup_defaults
@@ -42,17 +42,38 @@ module Mattock
42
42
  attr_accessor :valise
43
43
 
44
44
  def find_template(path)
45
- valise.find(["templates"] + valise.unpath(path)).contents
45
+ valise.find(["templates"] + valise.unpath(path))
46
46
  end
47
47
 
48
- def render(path, locals=nil)
48
+ def template_contents(path)
49
+ find_template(path).contents
50
+ end
51
+
52
+ def template_path(path)
53
+ find_template(path).full_path
54
+ end
55
+
56
+ def render(path, template_options = nil)
49
57
  template = TemplateHost::template_cache.fetch(path) do
50
- Tilt.new(path) do |tmpl|
51
- find_template(tmpl.file)
58
+ Tilt.new(path, template_options || {}) do |tmpl|
59
+ template_contents(tmpl.file)
52
60
  end
53
61
  end
54
62
 
55
- template.render(self, locals)
63
+ template.render(self)
64
+ end
65
+ end
66
+
67
+ module TemplateTaskLib
68
+ include TemplateHost
69
+
70
+ def template_task(template_source, destination_path, template_options = nil)
71
+ file template_path(template_source)
72
+ file destination_path => template_path(template_source) do
73
+ File::open(destination_path, "w") do |file|
74
+ file.write(render(template_source, template_options))
75
+ end
76
+ end
56
77
  end
57
78
  end
58
79
  end
@@ -13,7 +13,7 @@ module Mattock
13
13
  return true if [:CascadingDefinition, :Configurable, :Tasklib, :TaskLib].include? co.name and method == "define"
14
14
  return true if [:TaskMixin, :Task, :FileTask, :MultiTask].include? co.name and method == "action"
15
15
  end
16
- check_list = check_list.find_all{|co| co.respond_to?(:mixins)}.map{|co| co.mixins}.flatten
16
+ check_list = (check_list.find_all{|co| co.respond_to?(:mixins)}||[]).map{|co| co.mixins}.flatten
17
17
  end
18
18
  end
19
19
 
@@ -90,7 +90,7 @@ module Mattock
90
90
 
91
91
  value = statement.parameters(false)[1]
92
92
  if !value.nil? and value.type == :fcall and value.jump(:ident)[0] == "nested"
93
- remapped = value.parameters(false).first.map do |assoc|
93
+ remapped = (value.parameters.first||[]).map do |assoc|
94
94
  new_name =
95
95
  append_name(statement.parameters[0], extract_name(assoc[0]))
96
96
  synthetic_setting(new_name, assoc[1])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mattock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.11
4
+ version: 0.2.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-15 00:00:00.000000000 Z
12
+ date: 2012-05-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: corundum
16
- requirement: &83456260 !ruby/object:Gem::Requirement
16
+ requirement: &71422620 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.0.1
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *83456260
24
+ version_requirements: *71422620
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: valise
27
- requirement: &83455180 !ruby/object:Gem::Requirement
27
+ requirement: &71421560 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0.6'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *83455180
35
+ version_requirements: *71421560
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: tilt
38
- requirement: &83454630 !ruby/object:Gem::Requirement
38
+ requirement: &71545240 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>'
@@ -45,7 +45,7 @@ dependencies:
45
45
  - 0
46
46
  type: :runtime
47
47
  prerelease: false
48
- version_requirements: *83454630
48
+ version_requirements: *71545240
49
49
  description: ! " If Rake won't do it by itself, you oughtta Mattock.\n\n If you
50
50
  survived the pun, you might enjoy this gem.\n\n Features:\n\n * Extensions to
51
51
  Tasklibs to support powerful deerpaths.\n * A commandline library that supports
@@ -98,7 +98,7 @@ rdoc_options:
98
98
  - --main
99
99
  - doc/README
100
100
  - --title
101
- - mattock-0.2.11 RDoc
101
+ - mattock-0.2.12 RDoc
102
102
  require_paths:
103
103
  - lib/
104
104
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -109,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
109
  version: '0'
110
110
  segments:
111
111
  - 0
112
- hash: -318874223
112
+ hash: -458443345
113
113
  required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  none: false
115
115
  requirements: