class Octopress::Multilingual::Translate

Public Class Methods

generate_id(paths) click to toggle source
# File lib/octopress-multilingual/command.rb, line 22
def self.generate_id(paths)
  id = Digest::MD5.hexdigest(paths.join)
  translated = []
  paths.each do |path|
    if File.file? path
      contents = File.read(path)
      contents.sub!(/\A(---\s+.+?\s+)---/m) do
        fm = $1.sub(/translation_id:.+\n?/,'')
        fm << "translation_id: #{id}\n"
        fm << "---"
      end

      File.open(path, 'w+') {|f| f.write(contents) }

      translated << path
    end
  end

  puts "translation_id: #{id}"
  puts "Added to:"
  puts translated.map {|p| "  - #{p}" }.join("\n")
end
init_with_program(p) click to toggle source
# File lib/octopress-multilingual/command.rb, line 11
def self.init_with_program(p)
  p.command(:id) do |c|
    c.syntax 'id <path> [path path...]>'
    c.description "Generate a uniqe id to link translated posts or pages."

    c.action do |args|
      generate_id(args)
    end
  end
end