Class: YMDP::Compiler::Template::YRB
- Defined in:
- lib/ymdp/compiler/template.rb
Overview
Process Yahoo! Resource Bundle format translation files.
Convert them to a hash and write the hash to a JSON file.
Each language can have as many YRB translation files (with an extension of “.pres”) as necessary. The files are concatenated together and converted into a single JSON file for each language.
Instance Attribute Summary
Attributes inherited from Base
#assets_directory, #domain, #file, #hash, #host, #message, #server
Instance Method Summary collapse
-
#destination_path ⇒ Object
The destination of the compiled JSON file.
-
#directory ⇒ Object
Base directory for translations for this domain.
-
#processed_template ⇒ Object
This function is the file which is written to the destination–in this case, the JSON file.
-
#to_hash ⇒ Object
Turn it back into a hash.
-
#to_json ⇒ Object
JSON values of the compiled translations.
-
#to_yaml ⇒ Object
Convert the hash to Yaml if you should want to do that.
-
#validate ⇒ Object
Validate the JSON file.
-
#yrb ⇒ Object
Parse YRB file.
Methods inherited from Base
#build, #initialize, #partial?, #process_template, #server_path, #servers_path, #set_content_variables, #verbose, #verbose?, #write_template_with_layout, #write_template_without_layout
Methods inherited from Base
#base_path, base_path, #configuration, configuration, configure, #content_variables, display_path, #display_path, #paths, #servers
Constructor Details
This class inherits a constructor from YMDP::Compiler::Template::Base
Instance Method Details
#destination_path ⇒ Object
The destination of the compiled JSON file.
338 339 340 341 |
# File 'lib/ymdp/compiler/template.rb', line 338 def destination_path filename = convert_filename(@file.split("/").last) "#{directory}/#{filename}" end |
#directory ⇒ Object
Base directory for translations for this domain.
330 331 332 333 334 |
# File 'lib/ymdp/compiler/template.rb', line 330 def directory directory = "#{paths[:base_path]}/servers/#{@domain}/assets/yrb" FileUtils.mkdir_p(directory) directory end |
#processed_template ⇒ Object
This function is the file which is written to the destination–in this case, the JSON file.
375 376 377 |
# File 'lib/ymdp/compiler/template.rb', line 375 def processed_template yrb.to_json end |
#to_hash ⇒ Object
Turn it back into a hash.
351 352 353 |
# File 'lib/ymdp/compiler/template.rb', line 351 def to_hash yrb end |
#to_json ⇒ Object
JSON values of the compiled translations.
345 346 347 |
# File 'lib/ymdp/compiler/template.rb', line 345 def to_json processed_template end |
#to_yaml ⇒ Object
Convert the hash to Yaml if you should want to do that.
363 364 365 366 367 368 369 370 |
# File 'lib/ymdp/compiler/template.rb', line 363 def to_yaml h = {} to_hash.each do |k,v| k = k.downcase h[k] = "#{v}" end h.to_yaml end |
#validate ⇒ Object
Validate the JSON file.
381 382 383 |
# File 'lib/ymdp/compiler/template.rb', line 381 def validate Epic::Validator::JSON.new.validate(destination_path) end |
#yrb ⇒ Object
Parse YRB file
357 358 359 |
# File 'lib/ymdp/compiler/template.rb', line 357 def yrb ::YRB.load_file(@file) end |