Class: CamaleonCms::Generators::ThemeGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/camaleon_cms/theme_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(_dir) ⇒ Object



43
44
45
# File 'lib/generators/camaleon_cms/theme_generator.rb', line 43

def self.next_migration_number(_dir)
  Time.now.utc.strftime('%Y%m%d%H%M%S')
end

Instance Method Details

#create_initializer_fileObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/generators/camaleon_cms/theme_generator.rb', line 11

def create_initializer_file
  theme_folder = Rails.root.join('app', 'apps', 'themes', get_theme_name)
  if behavior == :revoke
    if Dir.exist?(theme_folder)
      FileUtils.rm_rf(theme_folder)
      say 'Theme destroyed successfully'
    else
      say "This theme doesn't exist"
    end
  elsif Dir.exist?(theme_folder)
    say 'This theme already exist'
  else
    # tmp copy
    FileUtils.mkdir_p(theme_folder)
    FileUtils.copy_entry(File.join($camaleon_engine_dir, 'lib', 'generators', 'camaleon_cms', 'theme_template'),
                         theme_folder)

    # configuration
    t = fix_text(File.read(File.join(theme_folder, 'config', 'config.json')))
    File.open(File.join(theme_folder, 'config', 'config.json'), 'w') { |f| f << t }

    # helper
    t = fix_text(File.read(File.join(theme_folder, 'main_helper.rb')))
    File.open(File.join(theme_folder, 'main_helper.rb'), 'w') { |f| f << t }
    say "Theme successfully created in: #{theme_folder}"
  end
end

#fix_text(text = '') ⇒ Object



39
40
41
# File 'lib/generators/camaleon_cms/theme_generator.rb', line 39

def fix_text(text = '')
  text.gsub('themeTitle', get_theme_title).gsub('ThemeClass', get_theme_class).gsub('themeKey', get_theme_name)
end