Class: Haml::I18n::Extractor::YamlTool
- Inherits:
-
Object
- Object
- Haml::I18n::Extractor::YamlTool
- Defined in:
- lib/haml-i18n-extractor/yaml_tool.rb
Instance Attribute Summary collapse
-
#locale_hash ⇒ Object
Returns the value of attribute locale_hash.
-
#locales_dir ⇒ Object
Returns the value of attribute locales_dir.
-
#yaml_file ⇒ Object
Returns the value of attribute yaml_file.
Instance Method Summary collapse
-
#initialize(locales_dir = nil) ⇒ YamlTool
constructor
A new instance of YamlTool.
- #locale_file ⇒ Object
- #write_file(filename = nil) ⇒ Object
-
#yaml_hash ⇒ Object
{:en => {:view_name => {:key_name => :string_name } } }.
Constructor Details
#initialize(locales_dir = nil) ⇒ YamlTool
Returns a new instance of YamlTool.
13 14 15 16 17 18 |
# File 'lib/haml-i18n-extractor/yaml_tool.rb', line 13 def initialize(locales_dir = nil) @locales_dir = locales_dir ? locales_dir : "./config/locales/" if ! File.exists?(@locales_dir) FileUtils.mkdir_p(@locales_dir) end end |
Instance Attribute Details
#locale_hash ⇒ Object
Returns the value of attribute locale_hash.
11 12 13 |
# File 'lib/haml-i18n-extractor/yaml_tool.rb', line 11 def locale_hash @locale_hash end |
#locales_dir ⇒ Object
Returns the value of attribute locales_dir.
11 12 13 |
# File 'lib/haml-i18n-extractor/yaml_tool.rb', line 11 def locales_dir @locales_dir end |
#yaml_file ⇒ Object
Returns the value of attribute yaml_file.
11 12 13 |
# File 'lib/haml-i18n-extractor/yaml_tool.rb', line 11 def yaml_file @yaml_file end |
Instance Method Details
#locale_file ⇒ Object
33 34 35 |
# File 'lib/haml-i18n-extractor/yaml_tool.rb', line 33 def locale_file File.join(@locales_dir, "#{@yaml_file}.yml") end |
#write_file(filename = nil) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/haml-i18n-extractor/yaml_tool.rb', line 37 def write_file(filename = nil) pth = filename.nil? ? locale_file : filename if File.exist?(pth) str = File.read(pth) if str.empty? existing_yaml_hash = {} else existing_yaml_hash = YAML.load(str) end else existing_yaml_hash = {} end final_yaml_hash = existing_yaml_hash.deep_merge!(yaml_hash) f = File.open(pth, "w+") f.puts final_yaml_hash.to_yaml f.flush end |
#yaml_hash ⇒ Object
{:en => {:view_name => {:key_name => :string_name } } }
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/haml-i18n-extractor/yaml_tool.rb', line 21 def yaml_hash yml = Hash.new @locale_hash.map do |line_no, info| unless info[:keyname].nil? keyspace = [@yaml_file,standardized_viewnames(info[:path]), standarized_keyname(info[:keyname]), info[:replaced_text]].flatten yml.deep_merge!(nested_hash({},keyspace)) end end yml = hashify(yml) end |