Class: Uniword::Resource::DocumentElementLoader
- Inherits:
-
Object
- Object
- Uniword::Resource::DocumentElementLoader
- Defined in:
- lib/uniword/resource/document_element_loader.rb
Overview
Loads document element templates from data/resources/document_elements/
Constant Summary collapse
- DATA_DIR =
File.join(__dir__, "../../../data/resources/document_elements")
Class Method Summary collapse
-
.available_categories(locale) ⇒ Array<String>
List available categories for a locale.
-
.available_locales ⇒ Array<String>
List all available locales.
-
.load(locale, category) ⇒ DocumentElementTemplate
Load templates for a specific locale and category.
Class Method Details
.available_categories(locale) ⇒ Array<String>
List available categories for a locale
33 34 35 36 37 38 39 40 |
# File 'lib/uniword/resource/document_element_loader.rb', line 33 def self.available_categories(locale) dir = File.join(DATA_DIR, locale) return [] unless Dir.exist?(dir) Dir.glob(File.join(dir, "*.yml")) .map { |p| File.basename(p, ".yml") } .sort end |
.available_locales ⇒ Array<String>
List all available locales
45 46 47 48 49 50 51 |
# File 'lib/uniword/resource/document_element_loader.rb', line 45 def self.available_locales return [] unless Dir.exist?(DATA_DIR) Dir.glob(File.join(DATA_DIR, "*/")) .map { |p| File.basename(p) } .sort end |
.load(locale, category) ⇒ DocumentElementTemplate
Load templates for a specific locale and category
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/uniword/resource/document_element_loader.rb', line 17 def self.load(locale, category) path = File.join(DATA_DIR, locale, "#{category}.yml") unless File.exist?(path) raise ArgumentError, "Document elements not found: #{locale}/#{category}. " \ "Available locales: #{available_locales.join(', ')}" end data = YAML.load_file(path) DocumentElementTemplate.from_hash(data) end |