Class: SC::Builder::Strings
- Defined in:
- lib/sproutcore/builders/strings.rb
Overview
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
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
build, #initialize, #joinlines, #readlines, #replace_static_url, #static_url, #writelines
Constructor Details
This class inherits a constructor from SC::Builder::Base
Instance Method Details
#build(dst_path) ⇒ Object
18 19 20 21 |
# File 'lib/sproutcore/builders/strings.rb', line 18 def build(dst_path) data = parse_strings_js(entry.source_path) writelines dst_path, [data.to_yaml] end |
#parse_strings_js(source_path) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sproutcore/builders/strings.rb', line 23 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}")) y = eval(%[<<__EOF__\n#{y}\n__EOF__]).chop ret[x] = y end return ret end |