Class: Groundworkcss::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_assetsObject



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
# File 'lib/groundworkcss/generators/install_generator.rb', line 15

def add_assets
  if detect_js_format
    js_file = "app/assets/javascripts/application#{detect_js_format[0]}"
    insert_into_file js_file, "#{detect_js_format[1]} require groundworkcss/libs/modernizr-2.6.2.min\n", :after => "jquery_ujs\n"
    insert_into_file js_file, "#{detect_js_format[1]} require groundworkcss/all\n", :after => "groundworkcss/libs/modernizr-2.6.2.min\n"
  else
    puts 'Cannot locate "application.js" or "application(.js).coffee" manifest file for writing...'.colorize( :red )
    puts 'You will need to add the following to your javascript manifest file manually:'.colorize( :blue )
    puts '//= require groundworkcss/libs/modernizr-2.6.2.min'
    puts '//= require groundworkcss/all'
  end

  if detect_css_format
    css_file = "app/assets/stylesheets/application#{detect_css_format[0]}"
    insert_into_file css_file, "@import 'groundwork_settings';\n", :after => "*/\n"
    insert_into_file css_file, "@import 'groundworkcss/groundwork';\n", :after => "@import 'groundwork_settings';\n"
    if detect_css_format[0] == '.css'
      puts "Renaming #{css_file} to #{css_file}.scss (to enable Sass partial includes)..."
      File.rename(css_file, css_file + '.scss')
    end
  else
    puts 'Cannot locate "application.css", "application(.css).scss" or "application(.css).sass" manifest file for writing...'.colorize( :red )
    puts 'You will need to add the following to your stylesheet manifest file manually:'.colorize( :blue )
    puts '@import \'groundwork_settings\';'
    puts '@import \'groundworkcss/groundwork\';'
  end
end

#create_settings_fileObject



9
10
11
12
13
# File 'lib/groundworkcss/generators/install_generator.rb', line 9

def create_settings_file
  dir = Pathname.new(Gem.loaded_specs['groundworkcss'].full_gem_path)
  file = File.join(dir, "app/assets/stylesheets/groundworkcss/_settings-rails#{Rails::VERSION::MAJOR}.scss")
  create_file "app/assets/stylesheets/_groundwork_settings.scss", File.read(file)
end

#detect_css_formatObject



50
51
52
53
54
55
56
57
# File 'lib/groundworkcss/generators/install_generator.rb', line 50

def detect_css_format
  return ['.css'] if File.exist?('app/assets/stylesheets/application.css')
  return ['.css.sass'] if File.exist?('app/assets/stylesheets/application.css.sass')
  return ['.css.scss'] if File.exist?('app/assets/stylesheets/application.css.scss')
  return ['.sass'] if File.exist?('app/assets/stylesheets/application.sass')
  return ['.scss'] if File.exist?('app/assets/stylesheets/application.scss')
  return false
end

#detect_js_formatObject



43
44
45
46
47
48
# File 'lib/groundworkcss/generators/install_generator.rb', line 43

def detect_js_format
  return ['.js', '//='] if File.exist?('app/assets/javascripts/application.js')
  return ['.js.coffee', '#='] if File.exist?('app/assets/javascripts/application.js.coffee')
  return ['.coffee', '#='] if File.exist?('app/assets/javascripts/application.coffee')
  return false
end