class ExtractI18n::Slimkeyfy::Word

Attributes

indentation[R]
line[R]
tokens[R]

Public Class Methods

for(extension) click to toggle source
# File lib/extract_i18n/slimkeyfy/word.rb, line 7
def self.for(extension)
  if extension == 'vue'
    JsWord
  else
    Word
  end
end
new(line) click to toggle source
# File lib/extract_i18n/slimkeyfy/word.rb, line 15
def initialize(line)
  @line = line
  @indentation = " " * (@line.size - unindented_line.size)
end

Public Instance Methods

as_list() click to toggle source
# File lib/extract_i18n/slimkeyfy/word.rb, line 20
def as_list
  # check for div.foo-bar(foo=bar)
  has_html_form = !!@line[/^ *[\.#]?[a-z\.#-]+\(/]
  delimiter_items =
    @line.
    sub(/^(\s*\|)(\w)/, "\\1 \\2"). # add a whitespace to support "|string"
    split(has_html_form ? /(?<=[\(])| +/ : ' '). # split by whitespace or ( but keep (
    drop_while { |i| i == "" } # .. but that leaves leading ""
  items = []
  # div: div
  delimiter_items.reverse_each do |item|
    if item[/^([a-z]|\.[a-z]|#[a-z]).*:/] and items.length > 0
      items[-1] = "#{item} #{items[-1]}"
    else
      items << item
    end
  end
  items.reverse
end
extract_arguments(translation) click to toggle source
# File lib/extract_i18n/slimkeyfy/word.rb, line 52
def extract_arguments(translation)
  args = {}
  translation.scan(/\#{[^}]*}/).each_with_index do |arg, index|
    stripped_arg = arg[2..-2]
    key = arg[/\w+/]
    key += index.to_s if index > 0
    translation = translation.gsub(arg, "%{#{key}}")
    args[key] = stripped_arg
  end
  [args, translation]
end
extract_updated_key(translation_key_with_base) click to toggle source
# File lib/extract_i18n/slimkeyfy/word.rb, line 64
def extract_updated_key(translation_key_with_base)
  return "" if translation_key_with_base.blank?
  translation_key_with_base.split(".").last
end
head() click to toggle source
# File lib/extract_i18n/slimkeyfy/word.rb, line 44
def head
  as_list.first
end
tail() click to toggle source
# File lib/extract_i18n/slimkeyfy/word.rb, line 48
def tail
  as_list.drop(1)
end
unindented_line() click to toggle source
# File lib/extract_i18n/slimkeyfy/word.rb, line 40
def unindented_line
  @line.sub(/^\s*/, "")
end