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_erb, #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.
451 452 453 454 |
# File 'lib/ymdp/compiler/template.rb', line 451 def destination_path filename = convert_filename(@file.split("/").last) "#{directory}/#{filename}" end |
#directory ⇒ Object
Base directory for translations for this domain.
443 444 445 446 447 |
# File 'lib/ymdp/compiler/template.rb', line 443 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.
488 489 490 |
# File 'lib/ymdp/compiler/template.rb', line 488 def processed_template yrb.to_json end |
#to_hash ⇒ Object
Turn it back into a hash.
464 465 466 |
# File 'lib/ymdp/compiler/template.rb', line 464 def to_hash yrb end |
#to_json ⇒ Object
JSON values of the compiled translations.
458 459 460 |
# File 'lib/ymdp/compiler/template.rb', line 458 def to_json processed_template end |
#to_yaml ⇒ Object
Convert the hash to Yaml if you should want to do that.
476 477 478 479 480 481 482 483 |
# File 'lib/ymdp/compiler/template.rb', line 476 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.
494 495 496 |
# File 'lib/ymdp/compiler/template.rb', line 494 def validate Epic::Validator::JSON.new.validate(destination_path) end |
#yrb ⇒ Object
Parse YRB file
470 471 472 |
# File 'lib/ymdp/compiler/template.rb', line 470 def yrb ::YRB.load_file(@file) end |