Class: Locomotive::Wagon::Generators::Snippet

Inherits:
Thor::Group
  • Object
show all
Includes:
CLI::ForceColor, Thor::Actions
Defined in:
lib/locomotive/wagon/generators/snippet.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CLI::ForceColor

#force_color_if_asked

Class Method Details

.source_rootObject



41
42
43
# File 'lib/locomotive/wagon/generators/snippet.rb', line 41

def self.source_root
  File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'generators', 'snippet')
end

Instance Method Details

#apply_locales?Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
# File 'lib/locomotive/wagon/generators/snippet.rb', line 17

def apply_locales?
  self.locales.shift # remove the default locale

  unless self.locales.empty?
    unless yes?('Do you want to generate files for each locale?')
      self.locales = []
    end
  end
end

#create_snippetObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/locomotive/wagon/generators/snippet.rb', line 27

def create_snippet
  _slug = slug.clone.downcase.gsub(/[-]/, '_')

  options   = { slug: _slug, translated: false }
  file_path = File.join(snippets_path, _slug)

  template "template.liquid.tt", "#{file_path}.liquid", options

  self.locales.each do |locale|
    options[:translated] = true
    template "template.liquid.tt", "#{file_path}.#{locale}.liquid", options
  end
end