Class: YMDP::Compiler::Template::Yaml

Inherits:
Base
  • Object
show all
Defined in:
lib/ymdp/compiler/template.rb

Overview

Process YAML format translation files.

Convert them to a hash and write the hash to a JSON file.

Each language can have as many YAML translation files as necessary. The files are 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.



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

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

#directoryObject

Base directory for translations for this domain.



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

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.



400
401
402
# File 'lib/ymdp/compiler/template.rb', line 400

def processed_template
  yaml.to_json
end

#to_hashObject

Turn it back into a hash.



381
382
383
# File 'lib/ymdp/compiler/template.rb', line 381

def to_hash
  yaml
end

#to_jsonObject

JSON values of the compiled translations.



375
376
377
# File 'lib/ymdp/compiler/template.rb', line 375

def to_json
  processed_template
end

#to_yamlObject

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



393
394
395
# File 'lib/ymdp/compiler/template.rb', line 393

def to_yaml
  to_hash.to_yaml
end

#validateObject

Validate the JSON file.



406
407
408
# File 'lib/ymdp/compiler/template.rb', line 406

def validate
  Epic::Validator::JSON.new.validate(destination_path)
end

#yamlObject

Parse Yaml file



387
388
389
# File 'lib/ymdp/compiler/template.rb', line 387

def yaml
  @yaml ||= ::YAML.load_file(@file)
end