class SC::Builder::Strings

This builder is used to generate a file containing all of the loc strings for a particular manifest. The strings file is used when generating HTML try to map localized strings

Public Instance Methods

build(dst_path) click to toggle source
# File lib/sproutcore/builders/strings.rb, line 19
def build(dst_path)
  data = parse_strings_js(entry[:source_path])
  writelines dst_path, [data.to_json]
end
parse_strings_js(source_path) click to toggle source
# File lib/sproutcore/builders/strings.rb, line 24
def parse_strings_js(source_path)
  return {} if !File.exists?(source_path)

  # read the file in and strip out comments...
  str = File.read(source_path)
  str = str.gsub(/\/\/.*$/,'').gsub(/\/\*.*\*\//m,'')

  # Now build the hash
  ret = {}
  str.scan(/['"](.+)['"]\s*:\s*['"](.+)['"],?\s*$/) do |x,y|
    # x & y are JS strings that must be evaled as such..
    #x = eval(%("#{x}"))
    begin
      y = eval(%[<<__EOF__\n#{y}\n__EOF__]).chop
    rescue SyntaxError
      puts "Invalid string in #{source_path}:"
      puts $&
      exit
    end
    ret[x] = y
  end
  return ret
end