Class: ExtractI18n::Slimkeyfy::SlimTransformer

Inherits:
Object
  • Object
show all
Defined in:
lib/extract_i18n/slimkeyfy/slim_transformer.rb

Direct Known Subclasses

VueTransformer

Constant Summary collapse

TRANSLATED =
/t\s*\(?\s*(".*?"|'.*?')\s*\)?/.freeze
STRING =
/(\".*\"|\'.*\')/.freeze
STRING_WITHOUT_QUOTES =
/("(?<double_quot>.*)"|'(?<single_quot>.*)')/.freeze
HTML_TAGS =
/^(?<html_tag>'|\||([a-z\.]+[0-9\-]*)+)/.freeze
EQUALS =
/#?([a-z0-9\.\-\s]+)?\=.*/.freeze
BEFORE =
/(?<before>.*)/.freeze
TRANSLATION =
/(?<translation>(".*?"|'.*?'))/.freeze
AFTER =
/(?<after>,?.*)?/.freeze
HTML_ARGUMENTS =
{
  hint: /(?<html_tag>hint:\s*)/,
  link_to: /(?<html_tag>link_to\s*\(?)/,
  inconified: /(?<html_tag>(iconified\s*\(?))/,
  placeholder: /(?<html_tag>placeholder:\s*)/,
  title: /(?<html_tag>title:\s*)/,
  prepend: /(?<html_tag>prepend:\s*)/,
  append: /(?<html_tag>append:\s*)/,
  label: /(?<html_tag>[a-z]*_?label:\s*)/,
  optionals: /(?<html_tag>(default|include_blank|alt):\s*)/,
  input: /(?<html_tag>[a-z]*\.?input:\s*)/,
  button: /(?<html_tag>[a-z]*\.?button:\s*(\:[a-z]+\s*,\s*)?)/,
  tag: /(?<html_tag>(submit|content)_tag[\:\(]?\s*)/,
  data_naive: /(?<html_tag>data:\s*\{\s*(confirm|content):\s*)/
}.freeze
/#{HTML_ARGUMENTS[:link_to]}#{TRANSLATION}/.freeze

Instance Method Summary collapse

Constructor Details

#initialize(word, file_key) ⇒ SlimTransformer

Returns a new instance of SlimTransformer.



47
48
49
50
# File 'lib/extract_i18n/slimkeyfy/slim_transformer.rb', line 47

def initialize(word, file_key)
  @word = word
  @file_key = file_key
end

Instance Method Details

#transform(&block) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/extract_i18n/slimkeyfy/slim_transformer.rb', line 34

def transform(&block)
  return yield(nil) if should_not_be_processed?(@word.as_list)
  unindented_line = @word.unindented_line

  if unindented_line.match(EQUALS)
    parse_html_arguments(unindented_line, &block)
  elsif @word.head.match(HTML_TAGS)
    parse_html(&block)
  else
    yield(nil)
  end
end