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


54
55
56
# File 'lib/generators/camaleon_cms/theme_generator.rb', line 54

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

Instance Method Details

#create_initializer_fileObject


10
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
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/generators/camaleon_cms/theme_generator.rb', line 10

def create_initializer_file
  if behavior == :revoke
    if PluginRoutes.theme_info(get_theme_name).present?
      PluginRoutes.destroy_theme(get_theme_name)
      puts "Theme destroyed successfully"
    else
      puts "This theme doesn't exist"
    end

  else

    if PluginRoutes.all_themes.include?(PluginRoutes.theme_info(get_theme_name))
      puts "This theme already exist"
    else

      # helpers + controllers
      plugin_app = File.join($camaleon_engine_dir, "lib", "generators", "camaleon_cms", "theme_template", "app_#{get_theme_name}")
      plugin_folder = File.join(plugin_app, "apps", "themes", get_theme_name)

      FileUtils.rm_r(plugin_app) if Dir.exist?(plugin_app)

      # tmp copy
      FileUtils.cp_r(File.join($camaleon_engine_dir, "lib", "generators", "camaleon_cms", "theme_template", "app"), plugin_app)
      FileUtils.mv(File.join(plugin_app, "apps", "themes", "my_theme"), plugin_folder) rescue nil

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

      # helper
      t = fix_text(File.read(File.join(plugin_folder, "main_helper.rb")))
      File.open(File.join(plugin_folder, "main_helper.rb"), "w"){|f|  f << t }


      directory("app_#{get_theme_name}", Rails.root.join("app"))
      FileUtils.rm_r(plugin_app)
    end
  end
end

#fix_text(text = "") ⇒ Object


50
51
52
# File 'lib/generators/camaleon_cms/theme_generator.rb', line 50

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