# >---------------------------------------------------------------------------< # # _____ _ _ # | __ \ (_) | /\ # | |__) |__ _ _| |___ / \ _ __ _ __ ___ # | _ // _` | | / __| / /\ \ | '_ \| '_ \/ __| # | | \ \ (_| | | \__ \/ ____ \| |_) | |_) \__ \ # |_| \_\__,_|_|_|___/_/ \_\ .__/| .__/|___/ # | | | | # |_| |_| # # Application template generated by the rails_apps_composer gem. # Restrain your impulse to make changes to this file; instead, # make changes to the recipes in the rails_apps_composer gem. # # For more information, see: # https://github.com/RailsApps/rails_apps_composer/ # # Thank you to Michael Bleigh for leading the way with the RailsWizard gem. # # Primarily generated by file: # https://github.com/RailsApps/rails_apps_composer/templates/layout.erb # # >---------------------------------------------------------------------------< # >----------------------------[ Initial Setup ]------------------------------< initializer 'generators.rb', <<-RUBY Rails.application.config.generators do |g| end RUBY module Gemfile class GemInfo def initialize(name) @name=name; @group=[]; @opts={}; end attr_accessor :name, :version attr_reader :group, :opts def opts=(new_opts={}) new_group = new_opts.delete(:group) if (new_group && self.group != new_group) @group = ([self.group].flatten + [new_group].flatten).compact.uniq.sort end @opts = (self.opts || {}).merge(new_opts) end def group_key() @group end def gem_args_string args = ["'#{@name}'"] args << "'#{@version}'" if @version @opts.each do |name,value| args << ":#{name}=>#{value.inspect}" end args.join(', ') end end @geminfo = {} class << self # add(name, version, opts={}) def add(name, *args) name = name.to_s version = args.first && !args.first.is_a?(Hash) ? args.shift : nil opts = args.first && args.first.is_a?(Hash) ? args.shift : {} @geminfo[name] = (@geminfo[name] || GemInfo.new(name)).tap do |info| info.version = version if version info.opts = opts end end def write File.open('Gemfile', 'a') do |file| file.puts grouped_gem_names.sort.each do |group, gem_names| indent = "" unless group.empty? file.puts "group :#{group.join(', :')} do" unless group.empty? indent=" " end gem_names.sort.each do |gem_name| file.puts "#{indent}gem #{@geminfo[gem_name].gem_args_string}" end file.puts "end" unless group.empty? file.puts end end end private #returns {group=>[...gem names...]}, ie {[:development, :test]=>['rspec-rails', 'mocha'], :assets=>[], ...} def grouped_gem_names {}.tap do |_groups| @geminfo.each do |gem_name, geminfo| (_groups[geminfo.group_key] ||= []).push(gem_name) end end end end end def add_gem(*all) Gemfile.add(*all); end @recipes = <%= resolve_recipes.map(&:key).inspect %> @prefs = <%= resolve_preferences %> @gems = <%= resolve_gems %> @diagnostics_recipes = <%= resolve_diagnostics_recipes %> @diagnostics_prefs = <%= resolve_diagnostics_prefs %> diagnostics = {} # ><%= ' templates/helpers.erb '.center(75,'-').chomp %>start< <%= render('helpers').chomp %> # ><%= ' templates/helpers.erb '.center(75,'-').chomp %>end< if diagnostics_recipes.sort.include? recipes.sort diagnostics[:recipes] = 'success' say_wizard("WOOT! The recipes you've selected are known to work together.") else diagnostics[:recipes] = 'fail' say_wizard("\033[1m\033[36m" + "WARNING! The recipes you've selected might not work together." + "\033[0m") say_wizard("Help us out by reporting whether this combination works or fails.") say_wizard("Please open an issue for rails_apps_composer on GitHub.") say_wizard("Your new application will contain diagnostics in its README file.") say_wizard("Continuing...") end # this application template only supports Rails version 3.1 and newer case Rails::VERSION::MAJOR.to_s when "3" case Rails::VERSION::MINOR.to_s when "0" say_wizard "You are using Rails version #{Rails::VERSION::STRING} which is not supported. Try 3.1 or newer." raise StandardError.new "Rails #{Rails::VERSION::STRING} is not supported. Try 3.1 or newer." end when "4" say_wizard "\033[1m\033[36m" + "WARNING! See GitHub for issues with Rails #{Rails::VERSION::STRING}." + "\033[0m" else say_wizard "You are using Rails version #{Rails::VERSION::STRING} which is not supported. Try 3.1 or newer." raise StandardError.new "Rails #{Rails::VERSION::STRING} is not supported. Try 3.1 or newer." end say_wizard "Using rails_apps_composer recipes to generate an application." # >---------------------------[ Autoload Modules/Classes ]-----------------------------< inject_into_file 'config/application.rb', :after => 'config.autoload_paths += %W(#{config.root}/extras)' do <<-'RUBY' config.autoload_paths += %W(#{config.root}/lib) RUBY end # >---------------------------------[ Recipes ]----------------------------------< <% resolve_recipes.each do |recipe| %> <%= render('recipe', recipe.get_binding).chomp %> <% end %> # >-----------------------------[ Final Gemfile Write ]------------------------------< Gemfile.write # >---------------------------------[ Diagnostics ]----------------------------------< # remove prefs which are diagnostically irrelevant redacted_prefs = prefs.clone redacted_prefs.delete(:ban_spiders) redacted_prefs.delete(:better_errors) redacted_prefs.delete(:dev_webserver) redacted_prefs.delete(:git) redacted_prefs.delete(:github) redacted_prefs.delete(:jsruntime) redacted_prefs.delete(:local_env_file) redacted_prefs.delete(:main_branch) redacted_prefs.delete(:prelaunch_branch) redacted_prefs.delete(:prod_webserver) redacted_prefs.delete(:quiet_assets) redacted_prefs.delete(:rvmrc) redacted_prefs.delete(:templates) if diagnostics_prefs.include? redacted_prefs diagnostics[:prefs] = 'success' else diagnostics[:prefs] = 'fail' end <% if custom_code? %># >-----------------------------[ Custom Code ]-------------------------------< <%= custom_code %><% end %>@current_recipe = nil # >-----------------------------[ Run 'Bundle Install' ]-------------------------------< say_wizard "Installing gems. This will take a while." if prefs.has_key? :bundle_path run "bundle install --without production --path #{prefs[:bundle_path]}" else run 'bundle install --without production' end # >-----------------------------[ Run 'After Bundler' Callbacks ]-------------------------------< say_wizard "Running 'after bundler' callbacks." require 'bundler/setup' if prefer :templates, 'haml' say_wizard "importing html2haml conversion tool" require 'html2haml' end if prefer :templates, 'slim' say_wizard "importing html2haml and haml2slim conversion tools" require 'html2haml' require 'haml2slim' end @after_blocks.each{|b| config = @configs[b[0]] || {}; @current_recipe = b[0]; b[1].call} # >-----------------------------[ Run 'After Everything' Callbacks ]-------------------------------< @current_recipe = nil say_wizard "Running 'after everything' callbacks." @after_everything_blocks.each{|b| config = @configs[b[0]] || {}; @current_recipe = b[0]; b[1].call} @current_recipe = nil if diagnostics[:recipes] == 'success' say_wizard("WOOT! The recipes you've selected are known to work together.") say_wizard("If they don't, open an issue for rails_apps_composer on GitHub.") else say_wizard("\033[1m\033[36m" + "WARNING! The recipes you've selected might not work together." + "\033[0m") say_wizard("Help us out by reporting whether this combination works or fails.") say_wizard("Please open an issue for rails_apps_composer on GitHub.") say_wizard("Your new application will contain diagnostics in its README file.") end if diagnostics[:prefs] == 'success' say_wizard("WOOT! The preferences you've selected are known to work together.") say_wizard("If they don't, open an issue for rails_apps_composer on GitHub.") else say_wizard("\033[1m\033[36m" + "WARNING! The preferences you've selected might not work together." + "\033[0m") say_wizard("Help us out by reporting whether this combination works or fails.") say_wizard("Please open an issue for rails_apps_composer on GitHub.") say_wizard("Your new application will contain diagnostics in its README file.") end say_wizard "Finished running the rails_apps_composer app template." say_wizard "Your new Rails app is ready. Time to run 'bundle install'."