class ExtractI18n::Adapters::SlimAdapter
Public Class Methods
join_multiline(strings_array)
click to toggle source
# File lib/extract_i18n/adapters/slim_adapter.rb, line 36 def self.join_multiline(strings_array) result = [] joining_str = '' indent_length = 0 long_str_start = /^[ ]+\| */ long_str_indent = /^[ ]+/ long_str_indent_with_vertical_bar = /^[ ]+\| */ strings_array.each do |str| if joining_str.empty? if str[long_str_start] joining_str = str indent_length = str[long_str_start].length else result << str end # multiline string continues with spaces elsif str[long_str_indent] && str[long_str_indent].length.to_i >= indent_length joining_str << str.gsub(long_str_indent, ' ') # muliline string continues with spaces and vertical bar with same indentation elsif str[long_str_indent_with_vertical_bar] && str[long_str_indent_with_vertical_bar].length.to_i == indent_length joining_str << str.gsub(long_str_indent_with_vertical_bar, ' ') # multiline string ends else result << joining_str joining_str = '' indent_length = 0 result << str end end result << joining_str unless joining_str.empty? result end
supports_relative_keys?()
click to toggle source
# File lib/extract_i18n/adapters/slim_adapter.rb, line 5 def self.supports_relative_keys? true end
Public Instance Methods
process_line(old_line)
click to toggle source
# File lib/extract_i18n/adapters/slim_adapter.rb, line 21 def process_line(old_line) word = ExtractI18n::Slimkeyfy::Word.for('.slim').new(old_line) ExtractI18n::Slimkeyfy::SlimTransformer.new(word, @file_key).transform do |change| if change.nil? # nothing to do return old_line end if @on_ask.call(change) change.i18n_t(relative: @options[:relative]) else old_line end end end
run(original_content)
click to toggle source
# File lib/extract_i18n/adapters/slim_adapter.rb, line 9 def run(original_content) @content = self.class.join_multiline(original_content.split("\n")) @content << "" # new line at the end @transformer = ExtractI18n::Slimkeyfy::SlimTransformer @new_content = @content.map do |old_line| process_line(old_line) end @new_content.join("\n") end