Sha256: bb33fb5e2f7de14e5b0e1021c4155a73ea0b2e0c873396cea3b382603ba03cdb
Contents?: true
Size: 1.95 KB
Versions: 6
Compression:
Stored size: 1.95 KB
Contents
class CthemeGenerator < Rails::Generators::Base source_root File.expand_path("../ctheme_template", __FILE__) argument :theme_name, :type => :string, :default => "my_theme" desc "This generator create basic theme structure" 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 = Rails.root.join("lib", "generators", "ctheme_template", "app_#{get_theme_name}") plugin_folder = File.join(plugin_app, "apps", "themes", get_theme_name) # tmp copy FileUtils.cp_r(Rails.root.join("lib", "generators", "ctheme_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 def fix_text(text = "") text.gsub("themeTitle", get_theme_title).gsub("ThemeClass", get_theme_class).gsub("themeKey", get_theme_name) end def self.next_migration_number(dir) Time.now.utc.strftime("%Y%m%d%H%M%S") end private def get_theme_name theme_name.underscore.singularize end def get_theme_title theme_name.titleize end def get_theme_class get_theme_name.classify end end
Version data entries
6 entries across 6 versions & 1 rubygems