Class: HalfPipe::Generators::InstallGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



7
8
9
# File 'lib/generators/half_pipe/install_generator.rb', line 7

def self.source_root
  @_half_pipe_source_root ||= File.expand_path("../templates", __FILE__)
end

Instance Method Details

#app_nameObject



63
64
65
# File 'lib/generators/half_pipe/install_generator.rb', line 63

def app_name
  Rails.application.class.parent_name
end

#create_initializer_fileObject



11
12
13
14
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/generators/half_pipe/install_generator.rb', line 11

def create_initializer_file
  template "package.json", "package.json"
  template "_bowerrc", ".bowerrc"
  template "bower.json", "bower.json"
  template "_jshintrc", ".jshintrc"
  template "Gruntfile.js", "Gruntfile.js"

  comment_lines "config/application.rb", %r{sprockets/railtie}

  railties_requires = File.read(File.join(self.class.source_root, "railties.rb"))
  gsub_file "config/application.rb", %r{require 'rails/all'}, railties_requires

  gsub_file "app/views/layouts/application.html.erb", %r{\s*<%= stylesheet_link_tag\s+"application".*%>$}, ''
  gsub_file "app/views/layouts/application.html.erb", %r{\s*<%= javascript_include_tag\s+"application".*%>$}, ''
  insert_into_file "app/views/layouts/application.html.erb", %Q{  <%= requirejs_include_tag "/scripts/application.js" %>\n  }, before: "</body>"
  insert_into_file "app/views/layouts/application.html.erb", %Q{  <%= stylesheet_link_tag "/styles/main.css" %>\n  }, before: "</head>"

  gsub_file "config/environments/development.rb", "config.assets.debug = true", "config.middleware.use Rack::HalfPipe"

  append_to_file ".gitignore", %w(node_modules bower_components public/scripts public/styles public/images).join("\n"), force: true

  directory "app"

  empty_directory "app/scripts"

  inside "app/scripts" do
    template "main.js", force: true
    template "application.js", force: true
  end

  initializer "sass.rb" do
    %Q{
    require 'sass/importers/bower_importer'
    require 'sass/half_pipe_functions'
    Sass.load_paths << Sass::Importers::BowerImporter.new("bower_components")
    }
  end

  run "npm install"

  ENV["PATH"] = "./node_modules/.bin:#{ENV["PATH"]}"

  run "bower install"
  run "grunt build"

  say "You may now safely migrate your assets to app/scripts and/or app/styles. Feel free to delete app/assets/javascripts and app/assets/stylesheets when you're done."
end

#main_module_nameObject



59
60
61
# File 'lib/generators/half_pipe/install_generator.rb', line 59

def main_module_name
  app_name.underscore.dasherize
end