#!/usr/bin/env ruby # -*- coding: utf-8 -*- if ARGV.size != 2 puts "Usage: #{$0} SOURCE_DIR DEST_DIR" exit(false) end require 'pathname' def fix_link(text, extension, language) send("fix_#{extension}_link", text, language) end def fix_link_path(text) text.gsub(/\b_(sources|static|images)\b/, '\1') end def fix_language_link(url, language) url.gsub(/\A((?:\.\.\/){2,})([a-z]{2})\/html\//) do relative_base_path = $1 link_language = $2 close_quote = $3 if language == "en" relative_base_path = relative_base_path.gsub(/\A\.\.\//, '') end if link_language != "en" relative_base_path += "#{link_language}/" end "#{relative_base_path}docs/" end end def fix_html_link(html, language) html = html.gsub(/(href|src)="(.+?)"/) do attribute = $1 link = $2 link = fix_link_path(link) link = fix_language_link(link, language) "#{attribute}=\"#{link}\"" end html.gsub(/(id="top-link" href=)"(.+?)"/) do prefix = $1 top_path = $2.gsub(/\/index\.html\z/, '/') top_path = "./" if ["index.html", "#"].include?(top_path) "#{prefix}\"#{top_path}../\"" end end def add_language_annotation_to_source_label(html, language) return html unless language == "ja" html.gsub(/>(ソースコードを表示)#{label}(英語)<" end end def fix_js_link(js, language) fix_link_path(js) end LANGUAGE_TO_LOCALE = { "ja" => "ja_JP", "en" => "en_US", } def insert_facebook_html_header(html) html.gsub(/<\/head>/) do <<-HTML HTML end end def insert_facebook_html_fb_root(html) html.gsub(//) do <<-HTML
HTML end end def insert_facebook_html_buttons(html) html.gsub(/(