lib/generators/half_pipe/install_generator.rb in half-pipe-0.2.4 vs lib/generators/half_pipe/install_generator.rb in half-pipe-0.3.0.alpha.1

- old
+ new

@@ -6,63 +6,129 @@ def self.source_root @_half_pipe_source_root ||= File.expand_path("../templates", __FILE__) end - def create_initializer_file + def welcome + say "*" * 120 + say + say "Welcome to Half Pipe!" + say "I'm going to take some preliminary setup steps to get you going." + say + say "*" * 120 + end + + def create_config_files + say + say "First I need to generate config files for NPM & Bower. This is where you'll put your asset building and browser dependencies in the future." + say + sleep 3 template "package.json", "package.json" template "_bowerrc", ".bowerrc" template "bower.json", "bower.json" template "_jshintrc", ".jshintrc" template "Gruntfile.js", "Gruntfile.js" + template "config/half-pipe.json" + end + def remove_sprockets + say + say "Half Pipe uses app/scripts and app/styles for your JavaScript and Stylesheet templates. I need to update your application layout to point to those, plus remove any traces of sprockets." + say + sleep 3 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".*%>$}, '' + end + + def insert_includes_into_layout 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>" + end - gsub_file "config/environments/development.rb", "config.assets.debug = true", "config.middleware.use Rack::HalfPipe" + def generate_scripts + say + say "Now I can generate some starter templates for your requirejs configuration and Sass imports" + say + sleep 3 + empty_directory "app/scripts" - append_to_file ".gitignore", %w(node_modules bower_components public/scripts public/styles public/images).join("\n"), force: true + template "app/scripts/main.js" + template "app/scripts/application.js" + end - directory "app" + def generate_stylesheets + template "app/styles/main.scss" + end - empty_directory "app/scripts" + def insert_ignores + append_to_file ".gitignore", %w(node_modules bower_components public/assets).join("\n"), force: true + end - inside "app/scripts" do - template "main.js", force: true - template "application.js", force: true - end + def generate_task_config_files + say + say "All of your Grunt tasks will be configured by files in #{Rails.root.join("tasks/options")}. After I'm done, have a look there to see if you need to customize anything." + say + sleep 3 + empty_directory "tasks/options" - initializer "sass.rb" do - %Q{ - require 'sass/importers/bower_importer' - require 'sass/half_pipe_functions' - Sass.load_paths << Sass::Importers::BowerImporter.new("bower_components") - } + inside "tasks/options" do + task_options_files.each do |f| + template File.basename(f), force: true + end end + end + def patch_sass_imports + # TODO: Remove this once https://github.com/chriseppstein/sass-css-importer/pull/6 is accepted and released + gem "sass-css-importer", github: "joefiorini/sass-css-importer", branch: "load-paths" + end + + def install_dependencies + say_status :run, "bundle install" + + bundle_path = Gem.bin_path("bundler", "bundle") + Bundler.with_clean_env do + `"#{Gem.ruby}" "#{bundle_path}" install` + end run "npm install" + end + def build_project ENV["PATH"] = "./node_modules/.bin:#{ENV["PATH"]}" run "bower install" - run "grunt build" + run "grunt build:public" + end + + def finalize + + say + say "Congratulations!".upcase + say + 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." + say + say "To start developing, fire up a development server with 'grunt server:debug'. You can continue to use 'http://localhost:3000' in your browser to access your app. I will take care of rebuilding your assets and restarting your Rails server as you work. Enjoy!" end + protected + def main_module_name app_name.underscore.dasherize end def app_name - Rails.application.class.parent_name + Rails.application.class.parent_name || "myapp" + end + + def task_options_files + Dir[File.join(%W(#{File.dirname(__FILE__)} templates tasks options *.js))] end end end