summaryrefslogtreecommitdiff
path: root/doc/Rookbook.yaml
blob: c031a35d678a68af7caea91c068dd77cc90341a6 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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


properties:
  - tagfile    : html-css


parameters:
  - u          : users-guide
  - all        : [ $(u).html ]


recipes:

  - product:	:default
    ingreds:	[ :all ]

  - product:	:doc
    ingreds:	[ users-guide.html ]

  - product:    :clear
    method*: |
	rm_rf 'guide.d', '*.html'

  - product:	:clean
    method*: |
	rm_rf 'guide.d', '*.toc.html'

  - product:	:all
    ingreds:	[ $(all) ]

  - product:	$(u).html
    ingreds:	[ $(u).txt ]
    byprods:	[ $(u).toc.html ]
    method*: |
	dir = "../test/data/$(u)"
	mkdir_p dir
	rm_rf "#{dir}/*"
	sys "retrieve -d #{dir} #{@ingred}"
	for filename in Dir.glob("#{dir}/*.*_filter")
	  content = File.read(filename)
	  name = (filename =~ /\.(\w+)_filter$/) && $1
	  case name
	  when 'comment'
	    content.gsub!(/\s*\#.*$/, '')
	    fname = filename.sub(/\.comment_filter$/, '')
	    File.open(fname, 'w') {|f| f.write(content) }
	  when 'split'
	    contents = content.split(/^\$ /).select{|s| !s.empty?}.collect{|s| '$ '+s}
	    i = 0
	    for cont in contents
	      i += 1
	      fname = filename.sub(/\.(\w+).(\w+)_filter$/, "#{i}.\\1")
	      File.open(fname, 'w') { |f| f.write(cont) }
	    end
	  end
	  File.unlink(filename)
	end
	sys "kwaser -t $(tagfile) -T #{@ingred} > #{@byprod}"
	sys "kwaser -t $(tagfile)    #{@ingred} > #{@product}"
	rm "#{@byprod}"

  - product:	:test
    ingreds:	[ $(u).html ]
    method*: |
        currdir = Dir.pwd
	chdir '../test' do
	  sys 'ruby test-users-guide.rb'
	end

  - product:	notext.txt
    ingreds:	[ ../test/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) }