Module: Mixin::Generators::TemplateLoader

Extended by:
TemplateLoader
Included in:
TemplateLoader
Defined in:
lib/fox/interface/thor/mixin/generators/template_loader.rb

Constant Summary collapse

TEMPLATE_DIR =

default template directory

'template'

Instance Method Summary collapse

Instance Method Details

#load(language) ⇒ String

Returns Result template source.

Parameters:

  • Target (String)

    language

Returns:

  • (String)

    Result template source

Raises:



25
26
27
28
29
30
31
# File 'lib/fox/interface/thor/mixin/generators/template_loader.rb', line 25

def load language
  file = templates.find { |file| File.basename(file).start_with?(language) }

  raise Fox::LoadTemplateError.new("Template for #{language} not found") if file.nil?

  File.read(file)
end

#templatesArray<String>

Returns List of all templates.

Returns:

  • (Array<String>)

    List of all templates



39
40
41
42
# File 'lib/fox/interface/thor/mixin/generators/template_loader.rb', line 39

def templates
  path = File.expand_path( File.dirname( __FILE__ ) + '../../../../../')
  Dir["#{path}/#{TEMPLATE_DIR}/*_template.erb"]
end