class Edge::Generators::InstallGenerator

Public Instance Methods

append_assets() click to toggle source
# File lib/edge/install_generator.rb, line 44
def append_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 "app/assets/stylesheets/application#{detect_css_format[0]}", "#{ detect_css_format[1] } require framework\n", before: "#{ detect_css_format[1] } require_tree"
end
create_assets() click to toggle source

Copy the template to Rails’ assets directory

# File lib/edge/install_generator.rb, line 10
def create_assets
  files_list = {
    sass: ["_setting.scss", "framework.scss", "app.scss"],
    img: ["favicon.png", "favicon-big.png"],
    js: ["app.js"]
  }
  
  template_path = File.join(File.dirname(__FILE__), "..", "..", "template", "base", "assets")

  # loop each file type
  files_list.each do |type, files|
    case type
    when :sass
      src_dir = "sass"
      dest_dir = "stylesheets"
    when :img
      src_dir = "img"
      dest_dir = "images"
    when :js
      src_dir = "js"
      dest_dir = "javascripts"
    end

    # loop each file
    files.each do |f|
      f_path = File.join(template_path, src_dir, f)
      create_file(
        File.join("app", "assets", dest_dir, f),
        File.binread(f_path)
      )
    end
  end
end
create_layout() click to toggle source
# File lib/edge/install_generator.rb, line 65
def create_layout
  if options.haml?||(defined?(Haml) && options.haml?)
    template "application.html.haml", "app/views/layouts/#{file_name}.html.haml"
  elsif options.slim?||(defined?(Slim) && options.slim?)
    template "application.html.slim", "app/views/layouts/#{file_name}.html.slim"
  else
    template "application.html.erb", "app/views/layouts/#{file_name}.html.erb"
  end
end
detect_css_format() click to toggle source
# File lib/edge/install_generator.rb, line 57
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 [".sass", " //="] if File.exist?("app/assets/stylesheets/application.sass")
  return [".css.scss", " //="] if File.exist?("app/assets/stylesheets/application.css.scss")
  return [".scss", " //="] if File.exist?("app/assets/stylesheets/application.scss")
end
detect_js_format() click to toggle source
# File lib/edge/install_generator.rb, line 51
def detect_js_format
  return [".coffee", "#="] if File.exist?("app/assets/javascripts/application.coffee")
  return [".js.coffee", "#="] if File.exist?("app/assets/javascripts/application.js.coffee")
  return [".js", "//="] if File.exist?("app/assets/javascripts/application.js")
end

Private Instance Methods

file_name() click to toggle source
# File lib/edge/install_generator.rb, line 77
def file_name
  layout_name.underscore.downcase
end