forked from minad/olelo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
176 lines (150 loc) · 5.61 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
task default: :test
def shrink_js(t)
#sh "cat #{t.prerequisites.sort.join(' ')} > #{t.name}"
sh 'java -jar tools/google-compiler*.jar --dev_mode EVERY_PASS --compilation_level SIMPLE_OPTIMIZATIONS ' +
t.prerequisites.sort.map {|x| "--js #{x}" }.join(' ') + " > #{t.name}"
end
def sass(file)
`sass -C -I #{File.dirname(file)} -I static/themes -t compressed #{file}`
end
def spew(file, content)
File.open(file, 'w') {|f| f.write(content) }
end
file('static/themes/atlantis/style.css' => Dir.glob('static/themes/atlantis/*.scss') + Dir.glob('static/themes/lib/*.scss')) do |t|
puts "Creating #{t.name}..."
content = "@media screen{#{sass(t.name.gsub('style.css', 'screen.scss'))}}@media print{#{sass(t.name.gsub('style.css', 'print.scss'))}}"
spew(t.name, content)
end
rule '.css' => ['.scss'] do |t|
puts "Creating #{t.name}..."
spew(t.name, sass(t.source))
end
file('static/script.js' => Dir.glob('static/script/*.js')) { |t| shrink_js(t) }
file('plugins/treeview/script.js' => Dir.glob('plugins/treeview/script/*.js')) {|t| shrink_js(t) }
file('plugins/misc/fancybox/script.js' => Dir.glob('plugins/misc/fancybox/script/*.js')) {|t| shrink_js(t) }
file('plugins/editor/markup/script.js' => Dir.glob('plugins/editor/markup/script/*.js')) {|t| shrink_js(t) }
file('plugins/history/script.js' => Dir.glob('plugins/history/script/*.js')) {|t| shrink_js(t) }
namespace :gen do
desc('Shrink JS files')
task js: %w(static/script.js plugins/treeview/script.js plugins/misc/fancybox/script.js plugins/editor/markup/script.js plugins/history/script.js)
desc('Compile CSS files')
task css: %w(static/themes/atlantis/style.css
plugins/treeview/treeview.css
plugins/aspects/gallery/gallery.css
plugins/misc/fancybox/jquery.fancybox.css
plugins/blog/blog.css)
end
desc 'Run tests with bacon'
task test: FileList['test/*_test.rb'] do |t|
sh "bacon -q -Ilib:test test/run.rb"
end
desc 'Cleanup'
task :clean do |t|
FileUtils.rm_rf 'doc/api'
FileUtils.rm_rf 'coverage'
FileUtils.rm_rf '.wiki/cache'
FileUtils.rm_rf '.wiki/log'
end
namespace :doc do
desc 'Generate documentation'
task :gen do; sh "yard doc -o doc/api 'lib/**/*.rb' 'plugins/**/*.rb'"; end
desc 'Start YARD documentation server'
task :server do; sh 'yard server --reload'; end
desc 'Check YARD documentation'
task :check do; sh "yardcheck 'lib/**/*.rb' 'plugins/**/*.rb'"; end
end
namespace :locale do
desc 'Sort locale yaml files'
task :sort do
require File.join(File.dirname(__FILE__), 'lib/olelo/virtualfs')
require 'i18n_yaml_sorter'
Dir['**/*.rb'].each do |file|
begin
locale = Olelo::VirtualFS::Embedded.new(file).read('locale.yml')
rescue
next
end
puts "Sorting #{file}"
result = I18nYamlSorter::Sorter.new(StringIO.new(locale)).sort
if result != locale
puts "Sorted #{file}:\n#{result}\n"
end
end
Dir['**/locale.yml'].each do |file|
puts "Sorting #{file}"
system("sort_yaml < #{file} > #{file}.sorted && mv #{file}.sorted #{file}")
end
end
desc 'Check locales for missing keys'
task :check do
require File.join(File.dirname(__FILE__), 'lib/olelo/virtualfs')
require 'yaml'
require 'set'
locales = {}
Dir['**/*.rb'].each do |file|
begin
locales[file] = YAML.load(Olelo::VirtualFS::Embedded.new(file).read('locale.yml'))
rescue
end
end
Dir['**/locale.yml'].each do |file|
locales[file] = YAML.load_file(file)
end
locales.each do |file, translations|
puts "Checking #{file}"
en = translations['en']
raise 'en locale missing' unless en
en_keys = en.keys
translations.each do |locale,hash|
delta = hash.keys - en_keys
puts "\t#{locale} has additional keys #{delta.join(' ')}" unless delta.empty?
delta = en_keys - hash.keys
puts "\t#{locale} is missing the keys #{delta.join(' ')}" unless delta.empty?
(en_keys & hash.keys).each do |key|
if hash[key].count('%{') != en[key].count('%{')
puts "\t#{locale}:#{key} has invalid number of arguments"
end
end
end
end
locale_defined = {}
locales.each do |file,translations|
translations.each do |locale, hash|
hash.keys.each do |key|
(locale_defined[key] ||= Set.new) << file
end
end
end
locale_used = {}
Dir['**/*.rb', '**/*.slim'].each do |file|
File.read(file).scan(/:(\w+)\.t[^\w]/) do
(locale_used[$1] ||= Set.new) << file
end
end
locale_defined.each do |key,files|
unless locale_used[key]
puts "#{key} defined in #{files.to_a.join(', ')} is unused"
end
end
locale_used.each do |key, files|
unless locale_defined[key]
puts "#{key} used in #{files.to_a.join(', ')} is undefined"
end
end
(locale_defined.keys & locale_used.keys).sort.each do |key|
if locale_defined[key] != locale_used[key] &&
!(locale_defined[key].all? {|file| file =~ %r{^lib} } && locale_used[key].any? {|file| file =~ %r{^lib} })
puts "#{key} - defined in #{locale_defined[key].to_a.join(', ')} - used in #{locale_used[key].to_a.join(', ')}"
end
end
end
end
namespace :notes do
task :todo do; system('ack T''ODO'); end
task :fixme do; system('ack F''IXME'); end
task :hack do; system('ack H''ACK'); end
task :warn do; system('ack W''ARN'); end
task :important do; system('ack I''MPORTANT'); end
end
desc 'Show annotations'
task notes: %w(notes:todo notes:fixme notes:hack notes:warn notes:important)