-
Notifications
You must be signed in to change notification settings - Fork 1
/
beer.rb
125 lines (82 loc) · 3 KB
/
beer.rb
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# encoding: utf-8
package 'book-templates/beer'
beer adapter: 'sqlite3', database: './beer.db'
book do |b|
opts = {}
### generate what's news in 2015
years = [2015,2014,2013,2012,2011,2010]
years.each do |year|
b.page( "#{year}", title: "What's News in #{year}?",
id: "#{year}" ) do |page|
page.render_whats_news_in_year( year, opts )
end
end
### generate breweries index
b.page( 'breweries', title: 'Breweries Index',
id: 'breweries' ) do |page|
page.render_breweries_idx( opts )
end
### generate beers index
b.page( 'beers', title: 'Beers Index',
id: 'beers' ) do |page|
page.render_beers_idx( opts )
end
### generate brands index
b.page( 'brands', title: 'Brands Index',
id: 'brands' ) do |page|
page.render_brands_idx( opts )
end
### generate table of contents (toc)
b.page( 'index', title: 'Contents',
id: 'index' ) do |page|
page.render_toc( opts )
end
### generate pages for countries
country_count=0
# Country.where( "key in ('at','mx','hr', 'de', 'be', 'nl', 'cz')" ).each do |country|
Country.order(:id).each do |country|
beers_count = country.beers.count
breweries_count = country.breweries.count
next if beers_count == 0 && breweries_count == 0
country_count += 1
puts "build country page #{country.key}..."
path = country.to_path
puts "path=#{path}"
b.page( path, title: "#{country.title} (#{country.code})",
id: "#{country.key}" ) do |page|
page.render_country( country, opts )
end
## todo - add b.divider() - for inline version - why, why not ????
## break if country_count == 3 # note: for testing only build three country pages
end
end # book block
=begin
###
## todo: move to its own bookfile
## - how to pass in country parameter ???
def build_book_for_country( country_code, opts={} )
country = Country.find_by_key!( country_code )
b = BookBuilder.new( PAGES_DIR, opts )
### generate breweries index
b.page( "#{country.key}-breweries", title: 'Breweries Index',
id: "/#{country.key}-breweries" ) do |page|
page.write render_breweries_idx( opts )
end
### generate pages for countries
puts "build country page #{country.key}..."
path = country.to_path
puts "path=#{path}"
b.page( path, title: "#{country.title} (#{country.code})",
id: "#{country.key}" ) do |page|
page.write render_country( country, opts )
end
b.page( "#{country.key}-mini", title: "#{country.title} (#{country.code}) - Mini",
id: "#{country.key}-mini" ) do |page|
page.write render_country_mini( country, opts )
end
b.page( "#{country.key}-stats", title: "#{country.title} (#{country.code}) - Stats",
id: "#{country.key}-stats.html" ) do |page|
page.write render_country_stats( country, opts )
end
end
=end