blob: 91d46fe95a257ac62dad162c27c35f3e63bca119 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
preparation*: |
def untabify(str, width=8)
list = str.split(/\t/)
last = list.pop
sb = ''
list.each do |s|
column = (n = s.rindex(?\n)) ? s.length - n - 1 : s.length
n = width - (column % width)
sb << s << (' ' * n)
end
sb << last
return sb
end
recipes:
- product: notext.txt
ingreds: [ test-notext.yaml, Rookbook.yaml ]
desc: create 'notext.txt' from 'test-notext.yaml'
method*: |
require 'yaml'
s = untabify(File.read(@ingred))
list = []
YAML.load_documents(s) { |ydoc| list << ydoc }
list.flatten!
entry = list.first
ydoc = {}
list.each do |hash|
%w[input output].each do |key|
hash[key].gsub!(/^\./, '') if hash.key?(key)
end
ydoc[hash['name']] = hash
end
text = entry['document']
require 'erubis'
eruby = Erubis::Eruby.new(text, :pattern=>'\[% %\]')
#p ydoc.keys
#puts eruby.src
result = eruby.result(binding())
File.open(@product, 'w') { |f| f.write(result) }
|