Class: Twine::Formatters::JQuery
Instance Attribute Summary
Attributes inherited from Abstract
#options, #strings
Instance Method Summary
collapse
Methods inherited from Abstract
#escape_quotes, #format_comment, #format_header, #format_key_value, #format_row, #initialize, #output_path_for_language, #set_comment_for_key, #set_translation_for_key, #should_include_row
Instance Method Details
#can_handle_directory?(path) ⇒ Boolean
12
13
14
|
# File 'lib/twine/formatters/jquery.rb', line 12
def can_handle_directory?(path)
Dir.entries(path).any? { |item| /^.+\.json$/.match(item) }
end
|
#default_file_name ⇒ Object
16
17
18
|
# File 'lib/twine/formatters/jquery.rb', line 16
def default_file_name
return 'localize.json'
end
|
#determine_language_given_path(path) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/twine/formatters/jquery.rb', line 20
def determine_language_given_path(path)
path_arr = path.split(File::SEPARATOR)
path_arr.each do |segment|
match = /^((.+)-)?([^-]+)\.json$/.match(segment)
if match
return match[3]
end
end
return
end
|
#extension ⇒ Object
8
9
10
|
# File 'lib/twine/formatters/jquery.rb', line 8
def extension
'.json'
end
|
45
46
47
48
49
|
# File 'lib/twine/formatters/jquery.rb', line 45
def format_file(lang)
result = super
return result unless result
"{\n#{super}\n}\n"
end
|
71
72
73
|
# File 'lib/twine/formatters/jquery.rb', line 71
def format_key(key)
escape_quotes(key)
end
|
4
5
6
|
# File 'lib/twine/formatters/jquery.rb', line 4
def format_name
'jquery'
end
|
59
60
61
62
63
64
65
|
# File 'lib/twine/formatters/jquery.rb', line 59
def format_section(section, lang)
rows = section.rows.dup
rows.map! { |row| format_row(row, lang) }
rows.compact!
rows.join(",\n")
end
|
56
57
|
# File 'lib/twine/formatters/jquery.rb', line 56
def (section)
end
|
51
52
53
54
|
# File 'lib/twine/formatters/jquery.rb', line 51
def format_sections(strings, lang)
sections = strings.sections.map { |section| format_section(section, lang) }
sections.join(",\n\n")
end
|
75
76
77
|
# File 'lib/twine/formatters/jquery.rb', line 75
def format_value(value)
escape_quotes(value)
end
|
#key_value_pattern ⇒ Object
67
68
69
|
# File 'lib/twine/formatters/jquery.rb', line 67
def key_value_pattern
"\"%{key}\":\"%{value}\""
end
|
#read(io, lang) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/twine/formatters/jquery.rb', line 32
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
|