Module: YAMLWriter
- Included in:
- RailsTranslationManager::Importer
- Defined in:
- lib/rails_translation_manager/yaml_writer.rb
Instance Method Summary collapse
-
#write_yaml(filepath, data) ⇒ Object
‘to_yaml` outputs an initial ’—n‘, which is supposed to be a document separator.
Instance Method Details
#write_yaml(filepath, data) ⇒ Object
‘to_yaml` outputs an initial ’—n‘, which is supposed to be a document separator. We don’t want this in the written locale files, so we serialize to a string, remove the header and any trailing whitehspace, and write to the file.
9 10 11 12 13 14 15 16 |
# File 'lib/rails_translation_manager/yaml_writer.rb', line 9 def write_yaml(filepath, data) File.open(filepath, "w") do |f| yaml = data.to_yaml(separator: "") yaml_without_header = yaml.split("\n").map { |l| l.gsub(/\s+$/, '') }[1..-1].join("\n") f.write(yaml_without_header) f.puts end end |