Class: Lokale::Writer
- Inherits:
-
Object
- Object
- Lokale::Writer
- Defined in:
- lib/lokale/agent.rb
Instance Method Summary collapse
Instance Method Details
#append_new_strings(lstrings, file) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/lokale/agent.rb', line 165 def append_new_strings(lstrings, file) content = file.content puts "Appending #{lstrings.size} new strings to file #{file.lang}/#{file.full_name}:" lstrings.each { |ls| puts ls.pretty } puts append_at = find_append_point(content) data_to_append = "\n\n" + lstrings.map { |ls| ls.write_format }.join("\n").chomp("\n") content.insert(append_at, data_to_append) file.write(content) end |
#find_append_point(content) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/lokale/agent.rb', line 148 def find_append_point(content) ignore_after = (content =~ /^\s*?\/\/\s*?\n\s*?\/\/\s*?MARK/) || Float::INFINITY string_regexp = /^".*?"\s*=\s*".*"\s*;/ append_at = content.match(string_regexp).end(0) return if append_at.nil? next_try = append_at while next_try < ignore_after append_at = next_try next_match = content.match(string_regexp, next_try) break if next_match.nil? next_try = next_match.end(0) end append_at end |