Sha256: abe7b32ab733d23810fa59b9fc0d77a563947f35f376bd41e54fa68f3a72d610

Contents?: true

Size: 1.41 KB

Versions: 19

Compression:

Stored size: 1.41 KB

Contents

# ===========================================================================
# Project:   Abbot - SproutCore Build Tools
# Copyright: ©2009 Apple Inc.
#            portions copyright @2006-2011 Strobe Inc.
#            and contributors
# ===========================================================================

require "sproutcore/builders/base"
require 'fileutils'
require 'json'

module SC

  # 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
  class Builder::Strings < Builder::Base

    def build(dst_path)
      data = parse_strings_js(entry[:source_path])
      writelines dst_path, [data.to_json]
    end

    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


  end

end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
sproutcore-1.11.0 lib/sproutcore/builders/strings.rb
sproutcore-1.11.0.rc3 lib/sproutcore/builders/strings.rb
sproutcore-1.11.0.rc2 lib/sproutcore/builders/strings.rb
sproutcore-1.11.0.rc1 lib/sproutcore/builders/strings.rb
sproutcore-1.10.3.1 lib/sproutcore/builders/strings.rb
sproutcore-1.10.2 lib/sproutcore/builders/strings.rb
sproutcore-1.10.1 lib/sproutcore/builders/strings.rb
sproutcore-1.10.0 lib/sproutcore/builders/strings.rb
sproutcore-1.10.0.rc.3 lib/sproutcore/builders/strings.rb
sproutcore-1.10.0.rc.2 lib/sproutcore/builders/strings.rb
sproutcore-1.10.0.rc.1 lib/sproutcore/builders/strings.rb
sproutcore-1.9.2 lib/sproutcore/builders/strings.rb
sproutcore-1.9.1 lib/sproutcore/builders/strings.rb
sproutcore-1.9.0 lib/sproutcore/builders/strings.rb
sproutcore-1.8.2.1 lib/sproutcore/builders/strings.rb
sproutcore-1.8.1 lib/sproutcore/builders/strings.rb
sproutcore-1.8.0 lib/sproutcore/builders/strings.rb
sproutcore-1.7.1.beta-java lib/sproutcore/builders/strings.rb
sproutcore-1.7.1.beta lib/sproutcore/builders/strings.rb