-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
214 lines (177 loc) · 6.8 KB
/
Rakefile
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require_relative 'config/application'
Rails.application.load_tasks
require 'spider'
namespace :spec do
namespace 'regression' do
desc 'Generate & normalize regression test artefacts'
task 'artefacts' => ['artefacts:generate', 'artefacts:normalize']
namespace 'artefacts' do
desc 'Clear regression test artefacts'
task 'clear' => 'environment' do
spider = Spider.new
spider.clear_artefacts
end
desc 'Generate regression test artefacts'
task 'generate' => 'clear' do
spider = Spider.new
spider.run
end
desc 'Normalize regression test artefacts'
task 'normalize' => 'environment' do
spider = Spider.new
spider.normalize_artefacts
end
end
end
end
require "erb"
namespace :week do
desc <<-DESC
Displays the GFR week number from the date of incorporation.
It defaults to today's date but you can override that by supplying
a parseable date in the DATE environment variable.
Example: `DATE=2014-03-24 rake week:number`
=> Week beginning 24 Mar 2014 is week 271
DESC
task number: :environment do
date = Date.parse(ENV['DATE']) rescue Date.today
week_number = Company::GoFreeRange.week_number_for(date)
week_beginning = date.monday.strftime("%d %b %Y")
puts "Week beginning #{week_beginning} is week #{week_number}"
end
desc <<-DESC
Displays a list of GFR week numbers and dates from the date of incorporation.
DESC
task numbers_and_dates: :environment do
Company::GoFreeRange.week_numbers_and_dates.each do |(week_number, date)|
puts "Week #{week_number} begins #{date.strftime('%a %d %b %Y')}"
end
end
namespace :notes do
desc <<-DESC
Creates a new weeknotes snip for the current GFR week.
By default it calculates the GFR week number based on today's
date, but you can override that either by supplying a parseable
date in the DATE environment variable or by setting the WEEK
environment variable to the GFR week number.
DESC
task create: :environment do
template = Template.find('week-nnn')
date = Date.parse(ENV['DATE']) rescue Date.today
week_number = (ENV['WEEK'] || Company::GoFreeRange.week_number_for(date))
Weeknotes.create(template.attributes.merge({
name: "week-#{week_number}",
extension: "markdown",
author: Person.current_name,
created_at: Time.now,
updated_at: Time.now,
page_title: "Week #{week_number}",
content: template.content.gsub(/Week NNN/, "Week #{week_number}")
}))
end
desc <<-DESC
Prepares the current weeknotes snip for publication.
By default it calculates the GFR week number based on today's
date, but you can override that either by supplying a parseable
date in the DATE environment variable or by setting the WEEK
environment variable to the GFR week number.
If a weeknotes snip for the relevant GFR week does not exist,
it will exit with an error message.
DESC
task publish: :environment do
date = Date.parse(ENV['DATE']) rescue Date.today
week_number = (ENV['WEEK'] || Company::GoFreeRange.week_number_for(date))
snip_name = "week-#{week_number}"
snip = Weeknotes.find(snip_name)
snip.attributes.delete(:draft)
snip.created_at = Time.now
snip.updated_at = Time.now
snip.save
end
end
namespace :links do
desc <<-DESC
Creates a new weeklinks snip for the current GFR week.
By default it calculates the GFR week number based on today's
date, but you can override that either by supplying a parseable
date in the DATE environment variable or by setting the WEEK
environment variable to the GFR week number.
DESC
task create: :environment do
template = Template.find('week-nnn-links')
date = Date.parse(ENV['DATE']) rescue Date.today
week_number = (ENV['WEEK'] || Company::GoFreeRange.week_number_for(date))
Weeklinks.create(template.attributes.merge({
name: "week-#{week_number}-links",
extension: "markdown",
author: Person.current_name,
created_at: Time.now,
updated_at: Time.now,
page_title: "Week #{week_number} - Interesting links",
content: template.content.gsub(/Week NNN/, "Week #{week_number}")
}))
end
desc <<-DESC
Prepares the current weeklinks snip for publication.
By default it calculates the GFR week number based on today's
date, but you can override that either by supplying a parseable
date in the DATE environment variable or by setting the WEEK
environment variable to the GFR week number.
If a weeklinks snip for the relevant GFR week does not exist,
it will exit with an error message.
DESC
task publish: :environment do
date = Date.parse(ENV['DATE']) rescue Date.today
week_number = (ENV['WEEK'] || Company::GoFreeRange.week_number_for(date))
snip_name = "week-#{week_number}-links"
snip = Weeklinks.find(snip_name)
snip.attributes.delete(:draft)
snip.created_at = Time.now
snip.updated_at = Time.now
snip.save
end
end
end
namespace 'show-and-tell' do
desc <<-DESC
Creates a new show-and-tell snip.
By default it calculates the new event number based on existing
show-and-tell snips, but you can override that by supplying an
event number in the NUMBER environment variable.
DESC
task create: :environment do
template = Template.find('show-and-tell-nn')
event_number = (ENV['NUMBER'] || ShowAndTell.latest_event_number + 1).to_i
ShowAndTell.create(template.attributes.merge({
name: "show-and-tell-#{event_number}",
extension: "markdown",
author: Person.current_name,
created_at: Time.now,
updated_at: Time.now,
page_title: "Show and Tell #{event_number}",
content: template.content.gsub(/Show and Tell NN/, "Show and Tell #{event_number}")
}))
end
desc <<-DESC
Prepares the latest show-and-tell snip for publication.
By default it calculates the latest event number based on existing
show-and-tell snips, but you can override that by supplying an
event number in the NUMBER environment variable.
If a show-and-tell snip for the relevant number does not exist,
it will exit with an error message.
DESC
task publish: :environment do
event_number = (ENV['NUMBER'] || ShowAndTell.latest_event_number + 1).to_i
snip_name = "show-and-tell-#{event_number}"
snip = ShowAndTell.find(snip_name)
unless snip
abort "No show-and-tell snip found for event number #{event_number}"
end
snip.attributes.delete(:draft)
snip.created_at = Time.now
snip.updated_at = Time.now
snip.save
end
end