Class: YMDP::Compiler::Template::YRB

Inherits:
Base
  • Object
show all
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

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_pathObject

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

#directoryObject

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_templateObject

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_hashObject

Turn it back into a hash.



464
465
466
# File 'lib/ymdp/compiler/template.rb', line 464

def to_hash
  yrb
end

#to_jsonObject

JSON values of the compiled translations.



458
459
460
# File 'lib/ymdp/compiler/template.rb', line 458

def to_json
  processed_template
end

#to_yamlObject

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

#validateObject

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

#yrbObject

Parse YRB file



470
471
472
# File 'lib/ymdp/compiler/template.rb', line 470

def yrb
  ::YRB.load_file(@file)
end