class Twine::Formatters::JQuery
Public Instance Methods
default_file_name()
click to toggle source
# File lib/twine/formatters/jquery.rb, line 12 def default_file_name 'localize.json' end
determine_language_given_path(path)
click to toggle source
Calls superclass method
Twine::Formatters::Abstract#determine_language_given_path
# File lib/twine/formatters/jquery.rb, line 16 def determine_language_given_path(path) match = /^.+-([^-]{2})\.json$/.match File.basename(path) return match[1] if match return super end
extension()
click to toggle source
# File lib/twine/formatters/jquery.rb, line 8 def extension '.json' end
format_file(lang)
click to toggle source
Calls superclass method
Twine::Formatters::Abstract#format_file
# File lib/twine/formatters/jquery.rb, line 36 def format_file(lang) result = super return result unless result "{\n#{super}\n}\n" end
format_key(key)
click to toggle source
# File lib/twine/formatters/jquery.rb, line 63 def format_key(key) escape_quotes(key) end
format_name()
click to toggle source
# File lib/twine/formatters/jquery.rb, line 4 def format_name 'jquery' end
format_section(section, lang)
click to toggle source
# File lib/twine/formatters/jquery.rb, line 51 def format_section(section, lang) definitions = section.definitions.dup definitions.map! { |definition| format_definition(definition, lang) } definitions.compact! # remove nil definitions definitions.join(",\n") end
format_section_header(section)
click to toggle source
# File lib/twine/formatters/jquery.rb, line 48 def format_section_header(section) end
format_sections(twine_file, lang)
click to toggle source
# File lib/twine/formatters/jquery.rb, line 42 def format_sections(twine_file, lang) sections = twine_file.sections.map { |section| format_section(section, lang) } sections.delete_if(&:empty?) sections.join(",\n\n") end
format_value(value)
click to toggle source
# File lib/twine/formatters/jquery.rb, line 67 def format_value(value) escape_quotes(value) end
key_value_pattern()
click to toggle source
# File lib/twine/formatters/jquery.rb, line 59 def key_value_pattern "\"%{key}\":\"%{value}\"" end
read(io, lang)
click to toggle source
# File lib/twine/formatters/jquery.rb, line 23 def read(io, lang) begin require "json" rescue LoadError raise Twine::Error.new "You must run `gem install json` in order to read or write jquery-localize files." end json = JSON.load(io) json.each do |key, value| set_translation_for_key(key, lang, value) end end