Reset build tasks

main
Kitaiti Makoto 3 years ago
parent 09c7cb8eb2
commit e5dee1e72e

@ -1,20 +1,32 @@
require "pathname" require "pathname"
BUILD_DIR = "build" BUILD_DIR = Pathname("build")
TRANS_DIR = "trans" LOCALE_DIR = Pathname("trans")
LOCALE_DIR = "locale" TRANS_DIR = Pathname("translate")
PSEUDO_LANG = "ach"
task :default => [:build_trans, "crowdin:upload", :build_site] CROWDIN_SNIPPET = <<EOS
<script type="text/javascript">
var _jipt = [];
_jipt.push(['project', 'plume-docs']);
_jipt.push(['escape', function() {
window.location.href = 'https://joinplu.me';
}]);
</script>
<script type="text/javascript" src="//cdn.crowdin.com/jipt/jipt.js"></script>
EOS
class Pathname
alias to_str to_s
end
desc "Build site" desc "Build site"
multitask :build_site => [:build_base, "crowdin:download"] do task :build_site => [:build_base, "crowdin:download"] do
Pathname.glob("#{LOCALE_DIR}/**/*.html").select(&:file?).each do |path| LOCALE_DIR.glob("**/*.html").each do |html|
content = path.read dest = Pathname(html.to_path.sub(LOCALE_DIR, BUILD_DIR))
content.sub! /<script type="text\/javascript" src="\/\/cdn.crowdin.com\/jipt\/jipt.js"><\/script>/, ""
dest = Pathname(path.to_path.sub(LOCALE_DIR, BUILD_DIR).sub(TRANS_DIR, ""))
$stderr.puts "copy #{path} -> #{dest}"
dest.parent.mkpath dest.parent.mkpath
dest.write content copy html, dest
end end
end end
@ -22,15 +34,26 @@ task :build_base do
sh "middleman", "build" sh "middleman", "build"
end end
desc "Build translation sources" desc "Build site for translate.docs.joinplu.me"
task :build_trans do task :build_trans do
env = {"CROWDIN" => "on"} sh "middleman", "build", "--build-dir", TRANS_DIR
sh env, "middleman", "build", "--build-dir", TRANS_DIR
(LOCALE_DIR/PSEUDO_LANG/"trans").glob("**/*.html").each do |html|
doc = html.read
doc.sub! "<head>", "<head>" + CROWDIN_SNIPPET
dest = Pathname(html.to_path.sub(LOCALE_DIR/PSEUDO_LANG/"trans", TRANS_DIR))
$stderr.puts "#{html} -> #{dest}"
dest.write doc
end
end
task :build_trans_src do
sh "middleman", "build", "--build-dir", LOCALE_DIR
end end
namespace :crowdin do namespace :crowdin do
desc "Download translations" desc "Download translations"
task :download do task :download => :build_trans_src do
sh "crowdin", "download" sh "crowdin", "download"
end end
@ -38,4 +61,8 @@ namespace :crowdin do
task :upload do task :upload do
sh "crowdin", "upload", "sources" sh "crowdin", "upload", "sources"
end end
task :download_pseudo do
sh "crowdin", "download", "--pseudo"
end
end end

@ -27,7 +27,7 @@ files: [
# Where translations will be placed # Where translations will be placed
# e.g. "/resources/%two_letters_code%/%original_file_name%" # e.g. "/resources/%two_letters_code%/%original_file_name%"
# #
"translation" : "/locale/%two_letters_code%/%original_path%/%original_file_name%", "translation" : "/trans/%two_letters_code%/%original_path%/%original_file_name%",
# #
# Files or directories for ignore # Files or directories for ignore

Loading…
Cancel
Save