Class: Twine::Formatters::Flash

Inherits:
Abstract
  • Object
show all
Includes:
Placeholders
Defined in:
lib/twine/formatters/flash.rb

Constant Summary

Constants included from Placeholders

Placeholders::PLACEHOLDER_FLAGS_WIDTH_PRECISION_LENGTH, Placeholders::PLACEHOLDER_PARAMETER_FLAGS_WIDTH_PRECISION_LENGTH, Placeholders::PLACEHOLDER_REGEX, Placeholders::PLACEHOLDER_TYPES

Constants inherited from Abstract

Abstract::LANGUAGE_CODE_WITH_OPTIONAL_REGION_CODE

Instance Attribute Summary

Attributes inherited from Abstract

#options, #twine_file

Instance Method Summary collapse

Methods included from Placeholders

#contains_python_specific_placeholder, #convert_placeholders_from_android_to_twine, #convert_placeholders_from_flash_to_twine, #convert_placeholders_from_twine_to_android, #convert_placeholders_from_twine_to_flash, #convert_twine_string_placeholder, #number_of_twine_placeholders

Methods inherited from Abstract

#can_handle_directory?, #determine_language_given_path, #escape_quotes, #format_definition, #format_file, #format_key, #format_key_value, #format_section, #initialize, #output_path_for_language, #set_comment_for_key, #should_include_definition

Constructor Details

This class inherits a constructor from Twine::Formatters::Abstract

Instance Method Details

#default_file_nameObject



14
15
16
# File 'lib/twine/formatters/flash.rb', line 14

def default_file_name
  'resources.properties'
end

#extensionObject



10
11
12
# File 'lib/twine/formatters/flash.rb', line 10

def extension
  '.properties'
end

#format_comment(definition, lang) ⇒ Object



52
53
54
# File 'lib/twine/formatters/flash.rb', line 52

def format_comment(definition, lang)
  "# #{definition.comment}\n" if definition.comment
end

#format_header(lang) ⇒ Object



44
45
46
# File 'lib/twine/formatters/flash.rb', line 44

def format_header(lang)
  "## Flash Strings File\n## Generated by Twine #{Twine::VERSION}\n## Language: #{lang}"
end

#format_nameObject



6
7
8
# File 'lib/twine/formatters/flash.rb', line 6

def format_name
  'flash'
end

#format_section_header(section) ⇒ Object



48
49
50
# File 'lib/twine/formatters/flash.rb', line 48

def format_section_header(section)
  "## #{section.name} ##\n"
end

#format_sections(twine_file, lang) ⇒ Object



40
41
42
# File 'lib/twine/formatters/flash.rb', line 40

def format_sections(twine_file, lang)
  super + "\n"
end

#format_value(value) ⇒ Object



60
61
62
# File 'lib/twine/formatters/flash.rb', line 60

def format_value(value)
  convert_placeholders_from_twine_to_flash(value)
end

#key_value_patternObject



56
57
58
# File 'lib/twine/formatters/flash.rb', line 56

def key_value_pattern
  "%{key}=%{value}"
end

#read(io, lang) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/twine/formatters/flash.rb', line 23

def read(io, lang)
  last_comment = nil
  while line = io.gets
    match = /((?:[^"\\]|\\.)+)\s*=\s*((?:[^"\\]|\\.)*)/.match(line)
    if match
      key = match[1]
      value = match[2].strip

      set_translation_for_key(key, lang, value)
      set_comment_for_key(key, last_comment) if last_comment
    end
    
    match = /# *(.*)/.match(line)
    last_comment = match ? match[1] : nil
  end
end

#set_translation_for_key(key, lang, value) ⇒ Object



18
19
20
21
# File 'lib/twine/formatters/flash.rb', line 18

def set_translation_for_key(key, lang, value)
  value = convert_placeholders_from_flash_to_twine(value)
  super(key, lang, value)
end