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_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_pathObject

The destination of the compiled JSON file.



324
325
326
327
# File 'lib/ymdp/compiler/template.rb', line 324

def destination_path
  filename = convert_filename(@file.split("/").last)
  "#{directory}/#{filename}"
end

#directoryObject

Base directory for translations for this domain.



316
317
318
319
320
# File 'lib/ymdp/compiler/template.rb', line 316

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.



361
362
363
# File 'lib/ymdp/compiler/template.rb', line 361

def processed_template
  yrb.to_json
end

#to_hashObject

Turn it back into a hash.



337
338
339
# File 'lib/ymdp/compiler/template.rb', line 337

def to_hash
  yrb
end

#to_jsonObject

JSON values of the compiled translations.



331
332
333
# File 'lib/ymdp/compiler/template.rb', line 331

def to_json
  processed_template
end

#to_yamlObject

Convert the hash to Yaml if you should want to do that.



349
350
351
352
353
354
355
356
# File 'lib/ymdp/compiler/template.rb', line 349

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.



367
368
369
# File 'lib/ymdp/compiler/template.rb', line 367

def validate
  YMDP::Validator::JSON.validate(destination_path)
end

#yrbObject

Parse YRB file



343
344
345
# File 'lib/ymdp/compiler/template.rb', line 343

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