/
Rakefile
69 lines (61 loc) · 1.95 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
# -*- ruby -*-
#
# This is a sample Rakefile to which you can add tasks to manage your website. For example, users
# may use this file for specifying an upload task for their website (copying the output to a server
# via rsync, ftp, scp, ...).
#
# It also provides some tasks out of the box, for example, rendering the website, clobbering the
# generated files, an auto render task,...
#
require 'webgen/webgentask'
require 'webgen/website'
task :default => :webgen
webgen_config = lambda do |config|
# you can set configuration options here
end
Webgen::WebgenTask.new do |website|
website.clobber_outdir = true
website.config_block = webgen_config
end
desc "Show outdated translations"
task :outdated do
puts "Listing outdated translations"
puts
puts "(Note: Information is taken from the last webgen run. To get the"
puts " useful information, run webgen once before this task!)"
puts
website = Webgen::Website.new(Dir.pwd, Webgen::Logger.new($stdout), &webgen_config)
website.execute_in_env do
website.init
website.tree.node_access[:acn].each do |acn, versions|
main = versions.find {|v| v.lang == website.config['website.lang']}
next unless main
outdated = versions.select do |v|
main != v && main['modified_at'] > v['modified_at']
end.map {|v| v.lang}.join(', ')
puts "ACN #{acn}: #{outdated}" if outdated.length > 0
end
end
end
desc "Render the website automatically on changes"
task :auto_webgen do
puts 'Starting auto-render mode'
time = Time.now
abort = false
old_paths = []
Signal.trap('INT') {abort = true}
while !abort
# you may need to adjust the glob so that all your sources are included
paths = Dir['src/**/*'].sort
if old_paths != paths || paths.any? {|p| File.mtime(p) > time}
begin
Rake::Task['webgen'].execute({})
rescue Webgen::Error => e
puts e.message
end
end
time = Time.now
old_paths = paths
sleep 2
end
end