Class: Foundation::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_assetsObject



13
14
15
16
17
18
19
20
# File 'lib/generators/foundation/install_generator.rb', line 13

def add_assets
  # rails_ujs breaks, need to incorporate rails-behavior plugin for this to work seamlessly
  # gsub_file "app/assets/javascripts/application#{detect_js_format[0]}", /\/\/= require jquery\n/, ""
  insert_into_file File.join(javascripts_base_dir, "application#{detect_js_format[0]}"), "#{detect_js_format[1]} require foundation\n", :before => "require_tree .\n"
  append_to_file File.join(javascripts_base_dir, "application#{detect_js_format[0]}"), "#{detect_js_format[2]}"
  create_app_scss
  insert_into_file File.join(stylesheets_base_dir, "application#{detect_css_format[0]}"), "\n#{detect_css_format[1]} require foundation_and_overrides\n", :after => "require_self"
end

#create_app_scssObject



56
57
58
59
60
# File 'lib/generators/foundation/install_generator.rb', line 56

def create_app_scss
  template "foundation_and_overrides.scss", File.join(stylesheets_base_dir, "foundation_and_overrides.scss")
  template "_settings.scss", File.join(stylesheets_base_dir, "_settings.scss")
  template "browserslist", File.join(stylesheets_base_dir, "browserslist")
end

#create_layoutObject



46
47
48
49
50
51
52
53
54
# File 'lib/generators/foundation/install_generator.rb', line 46

def create_layout
  if options.haml? || (defined?(Haml) && options.haml?)
    template "application.html.haml", File.join(layouts_base_dir, "#{file_name}.html.haml")
  elsif options.slim? || (defined?(Slim) && options.slim?)
    template "application.html.slim", File.join(layouts_base_dir, "#{file_name}.html.slim")
  else
    template "application.html.erb", File.join(layouts_base_dir, "#{file_name}.html.erb")
  end
end

#detect_css_formatObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/generators/foundation/install_generator.rb', line 34

def detect_css_format
  %w(.css .css.sass .sass .css.scss .scss).each do |ext|
    if File.exist?(File.join(stylesheets_base_dir, "application#{ext}"))
      if ext.include?(".sass") || ext.include?(".scss")
        return [ext, "//="]
      else
        return [ext, " *="]
      end
    end
  end
end

#detect_js_formatObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/generators/foundation/install_generator.rb', line 22

def detect_js_format
  %w(.coffee .coffee.erb .js.coffee .js.coffee.erb .js .js.erb).each do |ext|
    if File.exist?(File.join(javascripts_base_dir, "application#{ext}"))
      if ext.include?(".coffee")
        return [ext, "#=", "\n() ->\n  $(document).foundation()\n"]
      else
        return [ext, "//=", "\n$(function(){ $(document).foundation(); });\n"]
      end
    end
  end
end