Class: CompassThemeGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/compass-themes/railties/generators/compass_theme/compass_theme_generator.rb

Constant Summary collapse

APP_LAYOUT =
'application.html.haml'
RAKE_NOTICE =
"Please run rake compass:themes to view all available themes"

Instance Method Summary collapse

Instance Method Details

#add_importObject



45
46
47
48
# File 'lib/compass-themes/railties/generators/compass_theme/compass_theme_generator.rb', line 45

def add_import
  gsub_file compass_file, /^@import\s\"compass\/reset\";$/, "//@import \"compass/reset\";"
  append_file compass_file, "@import \"#{args[:layout]}/#{args[:theme]}\"; //compass-theme"
end

#copy_layoutObject



36
37
38
39
# File 'lib/compass-themes/railties/generators/compass_theme/compass_theme_generator.rb', line 36

def copy_layout
  layout_file = layout_filename
  copy_file layout_file, Rails.root.join('app', 'views', 'layouts', 'application.html.haml') 
end

#remove_layoutObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/compass-themes/railties/generators/compass_theme/compass_theme_generator.rb', line 20

def remove_layout
  layout_path = Rails.root.join('app', 'views', 'layouts')
  layouts = Dir["#{layout_path}/application.*.haml"]
  layouts.each do |f|
    if APP_LAYOUT == File.basename(f.to_s) && !options[:force]
      say "Conflict found trying to install layout file", Thor::Shell::Color::YELLOW
      if ask("Would you like to back up your old layout? [Y/n]").downcase == 'y'
        backup = "#{APP_LAYOUT}.old"
        FileUtils.cp(f.to_s, File.join(layout_path, backup))
        say("Backing up old layout file to #{backup}", Thor::Shell::Color::GREEN)
      end
    end
    remove_file f.to_s
  end
end

#remove_old_theme_includeObject



41
42
43
# File 'lib/compass-themes/railties/generators/compass_theme/compass_theme_generator.rb', line 41

def remove_old_theme_include
  gsub_file compass_file, /^@import\s\".+\";\s\/\/compass\-theme$/, ''
end

#verify_that_arg_is_a_theme_comboObject



11
12
13
14
15
16
17
18
# File 'lib/compass-themes/railties/generators/compass_theme/compass_theme_generator.rb', line 11

def verify_that_arg_is_a_theme_combo
  themes = CompassThemes::GeneratorHelper.available_themes
  unless themes[args[:layout].to_sym] && themes[args[:layout].to_sym].include?(args[:theme].gsub(/(.+)\.theme/){ $1 })
    say "Theme combination not found!", Thor::Shell::Color::RED
    say RAKE_NOTICE, Thor::Shell::Color::YELLOW
    exit
  end
end