Module: Themeable::GeneratorConcern

Defined in:
lib/themeable/generator_concern.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



3
4
5
6
7
8
# File 'lib/themeable/generator_concern.rb', line 3

def self.included(klass)
  klass.instance_eval do
    class_option :theme, type: :string, desc: "Choose theme to generate files", default: nil
    class_option :theme_scaffold, type: :string, desc: "Choose a templete to scaffold", default: nil
  end
end

Instance Method Details

#find_in_source_paths(file) ⇒ Object

Support theme and template



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/themeable/generator_concern.rb', line 11

def find_in_source_paths(file)
  theme_scaffold = options[:theme_scaffold]
  theme_scaffold ||= 'default' if options[:theme].present?
  themed_file = [options[:theme], theme_scaffold, file].compact.join('/')
  super(themed_file)
rescue Thor::Error => e
  if e.message =~ /^Could not find /
    say "Can't find themed file #{themed_file}, use default template", :yellow unless @behavior == :revoke
    return super(file)
  else
    raise
  end
end