Class: Hobo::SetupWizardGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Hobo::SetupWizardGenerator
- Includes:
- Generators::HoboSupport::ThorShell, classy_module do class_option :activation_email, :type => :boolean, :desc => "Send an email to activate the account" end, classy_module do class_option :invite_only, :aliases => '-i', :type => :boolean, :desc => "Add features for an invite only website" private def invite_only? options[:invite_only] end end, classy_module do class_option :user_resource_name, :type => :string, :desc => "User Resource Name", :default => 'user' end, classy_module do protected def gem_with_comments(*args) options = argsclassy_module do protected def gem_with_comments(*args) options = args.extract_options! name = args[0] unless File.read("Gemfile") =~ /^gem ("|')#{name}/ if (comments = options.delete(:comments)) append_file "Gemfile", "#{comments}", :verbose => false end gem(args[0], args[1], options) true else false end end def install_plugin_helper(name, git_path, options) plugin = name.dup unless options[:skip_gem] gem_options = {} if git_path if git_path =~ /:/ gem_options[:git] = git_path else gem_options[:path] = git_path end end gem_options[:comments] = "# #{options[:comments]}" if options[:comments] need_update = gem_with_comments(plugin, options[:version], gem_options) end if options[:subsite].nil? || options[:subsite] == "all" subsites = ['front'] + ::Hobo.subsites else subsites = [options[:subsite]] end subsites.each do |subsite| inject_js_require(name, subsite, options[:comments]) unless options[:skip_js] inject_css_require(name, subsite, options[:comments]) unless options[:skip_css] inject_dryml_include(name, subsite, options[:comments]) unless options[:skip_dryml] end return need_update end def inject_js_require(name, subsite, comments) application_file = "app/assets/javascripts/#{subsite}.js" pattern = /\/\/=(?!.*\/\/=).*?$/m unless exists?(application_file) application_file = "#{application_file}.coffee" pattern = /#=(?!.*#=).*?$/m end raise Thor::Error, "Couldn't find either #{subsite}.js or #{subsite}.js.coffee files!" unless exists?(application_file) inject_into_file application_file, :before=>pattern do line = "//= require #{name}\n" line = "//\n// #{comments}\n#{line}" if comments line end end def inject_css_require(name, subsite, comments) application_file = "app/assets/stylesheets/#{subsite}.scss" application_file = "app/assets/stylesheets/#{subsite}.css" unless exists?(application_file) raise Thor::Error, "Couldn't find #{subsite}.css!" unless exists?(application_file) opts = {:before => /\*=(?!.*\*=).*?$/m} raise Thor::Error, "Couldn't find #{subsite}.css!" unless exists?(application_file) inject_into_file application_file, opts do line = "*= require #{name}\n " line = "*\n * #{comments}\n #{line}" if comments line end end def inject_dryml_include(name, subsite, comments) subsite = "#{subsite}_site" unless subsite=="application" application_file = "app/views/taglibs/#{subsite}.dryml" pattern = /\<include gem=.*?\>(?!.*\<include gem=.*?\>).*?\n/m raise Thor::Error, "Couldn't find #{subsite}.dryml!" unless exists?(application_file) inject_into_file application_file, :after=>pattern do line = "\n<include gem='#{name}'/>\n" line = "\n<%# #{comments} %>#{line}" if comments line end end def exists?(file) File.exist?(File.join(destination_root, file)) end end
- Defined in:
- lib/generators/hobo/setup_wizard/setup_wizard_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #active_reload_dryml ⇒ Object
- #admin_subsite ⇒ Object
- #dont_emit_deprecated_routes ⇒ Object
- #dryml_only_templates_option ⇒ Object
- #finalize ⇒ Object
- #front_controller ⇒ Object
- #generate_migration ⇒ Object
- #git_repo ⇒ Object
- #i18n ⇒ Object
- #install_default_plugins ⇒ Object
- #invoking_user_and_admin ⇒ Object
- #quiet_assets ⇒ Object
- #site_options ⇒ Object
- #startup ⇒ Object
- #user_options ⇒ Object
- #will_paginate ⇒ Object
Class Method Details
.banner ⇒ Object
14 15 16 |
# File 'lib/generators/hobo/setup_wizard/setup_wizard_generator.rb', line 14 def self. "rails generate hobo:setup_wizard [options]" end |
Instance Method Details
#active_reload_dryml ⇒ Object
216 217 218 219 220 |
# File 'lib/generators/hobo/setup_wizard/setup_wizard_generator.rb', line 216 def active_reload_dryml environment "#", :env => :development environment "config.watchable_dirs[File.join(config.root, 'app/views')] = ['dryml']", :env => :development environment "# Hobo: tell ActiveReload about dryml", :env => :development end |
#admin_subsite ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/generators/hobo/setup_wizard/setup_wizard_generator.rb', line 179 def admin_subsite if wizard? say_title 'Admin Subsite' if @invite_only || (@add_admin_subsite = yes_no?("Do you want an admin subsite?")) @admin_subsite_name = ask("Choose a name for the admin subsite: [<enter>=admin|<custom_name>]", 'admin') say "The currently available themes are clean, clean_admin, clean_sidemenu and bootstrap." @admin_theme = ask("Choose a theme for the #{@admin_subsite_name} site: [<enter>=clean_admin|<custom_name>]", 'clean_admin') say "The currently available jQuery-UI themes are listed here: https://github.com/fatdude/jquery-ui-themes-rails/blob/master/README.markdown" @admin_ui_theme = ask("Choose a jQuery-UI theme for the admin site: [<enter>=flick|<custom_name>]", 'flick') end else if @invite_only || (@add_admin_subsite = [:add_admin_subsite]) @admin_subsite_name = [:admin_subsite_name] @admin_theme = [:front_theme] @admin_ui_theme = [:front_ui_theme] end end end |
#dont_emit_deprecated_routes ⇒ Object
136 137 138 139 140 |
# File 'lib/generators/hobo/setup_wizard/setup_wizard_generator.rb', line 136 def dont_emit_deprecated_routes environment "#" environment "config.hobo.dont_emit_deprecated_routes = true" environment "# Hobo: Named routes have changed in Hobo 2.0. Set to false to emit both the 2.0 and 1.3 names." end |
#dryml_only_templates_option ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/generators/hobo/setup_wizard/setup_wizard_generator.rb', line 120 def dryml_only_templates_option if wizard? say_title 'Templates Option' dryml_only_templates = yes_no?("Will your application use only hobo/dryml web page templates?\n(Choose 'n' only if you also plan to use plain rails/erb web page templates)") else dryml_only_templates = [:dryml_only_templates] end if dryml_only_templates remove_file 'app/views/layouts/application.html.erb' remove_file 'app/helpers/application_helper.rb' environment "#" environment "config.hobo.dryml_only_templates = true" environment "# Hobo: remove support for ERB templates" end end |
#finalize ⇒ Object
297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/generators/hobo/setup_wizard/setup_wizard_generator.rb', line 297 def finalize return unless wizard? say_title 'Process completed!' say %(You can start your application with `rails server` (run with --help for options). Then point your browser to http://localhost:3000/ Follow the guidelines to start developing your application. You can find the following resources handy: * The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html * Ruby on Rails Tutorial Book: http://www.railstutorial.org/ ) end |
#front_controller ⇒ Object
152 153 154 155 156 157 158 159 160 161 |
# File 'lib/generators/hobo/setup_wizard/setup_wizard_generator.rb', line 152 def front_controller if wizard? say_title 'Front Controller' front_controller_name = ask("Choose a name for the front controller: [<enter>=front|<custom_name>]", 'front') say "Installing #{front_controller_name} controller..." else front_controller_name = [:front_controller_name] end invoke 'hobo:front_controller', [front_controller_name], :user_resource_name => @user_resource_name, :invite_only => @invite_only end |
#generate_migration ⇒ Object
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/generators/hobo/setup_wizard/setup_wizard_generator.rb', line 222 def generate_migration if wizard? say_title 'DB Migration' action = choose("Initial Migration: [s]kip, [g]enerate migration file only, generate and [m]igrate: [s|g|m]", /^(s|g|m)$/) opt = case action when 's' return say('Migration skipped!') when 'g' {:generate => true} when 'm' {:migrate => true} end say action == 'g' ? 'Generating Migration...' : 'Migrating...' else return if ![:migration_generate] && ![:migration_migrate] opt = [:migration_migrate] ? {:migrate => true} : {:generate => true} end rake 'db:setup' invoke 'hobo:migration', ['initial_migration'], opt end |
#git_repo ⇒ Object
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/generators/hobo/setup_wizard/setup_wizard_generator.rb', line 277 def git_repo if wizard? say_title 'Git Repository' return unless yes_no?("Do you want to initialize a git repository now?") gitignore_auto_generated = yes_no? "Do you want git to ignore the auto-generated files?\n(Choose 'n' only if you are planning to deploy on a read-only File System like Heroku)" say 'Initializing git repository...' else return unless [:git_repo] gitignore_auto_generated = [:gitignore_auto_generated_files] end if gitignore_auto_generated hobo_routes_rel_path = Hobo::Engine.config.hobo.routes_path.relative_path_from Rails.root append_file '.gitignore', "app/views/taglibs/auto/**/*\n#{hobo_routes_rel_path}\n" end git :init git :add => '.' git :commit => '-m "initial commit"' say("NOTICE: If you change the config.hobo.routes_path, you should update the .gitignore file accordingly.", Color::YELLOW) if gitignore_auto_generated end |
#i18n ⇒ Object
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/generators/hobo/setup_wizard/setup_wizard_generator.rb', line 243 def i18n if wizard? say_title 'I18n' i18n_templates = File.('../../i18n/templates', __FILE__) supported_locales = Dir.glob("#{i18n_templates}/hobo.*.yml").map do |l| l =~ /([^\/.]+)\.yml$/ $1 end say "The Hobo supported locales are #{supported_locales * ' '} (please, contribute to more translations)" locales = ask("Type the locales (space separated) you want to add to your application or <enter> for 'en':", 'en').split(/\s/) unless locales.size == 1 && locales.first == 'en' default_locale = ask "Do you want to set a default locale? Type the locale or <enter> to skip:" end else default_locale = [:default_locale] locales = [:locales] end unless default_locale.blank? default_locale.gsub!(/\:/, '') environment "#" environment "config.i18n.default_locale = #{default_locale.to_sym.inspect}" environment "#" end ls = (locales - %w[en]).map {|l| ":#{l}" } lstr = ls.to_sentence invoke 'hobo:i18n', locales say(<<STR , Color::YELLOW) unless ls.empty? NOTICE: You should manually install in 'config/locales' also the official Rails locale #{ls.size==1 ? 'file' : 'files'} for #{lstr} that your application will use. Official rails I18n URLs: - Readme: https://github.com/svenfuchs/rails-i18n/blob/master/README.md - locale dir: https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale/ STR end |
#install_default_plugins ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/generators/hobo/setup_wizard/setup_wizard_generator.rb', line 163 def install_default_plugins if wizard? say_title 'Front Theme' say "The currently available themes are clean, clean_admin, clean_sidemenu and bootstrap." @front_theme = ask("Choose a theme for the front site: [<enter>=bootstrap|<custom_name>]", 'bootstrap') say_title 'Front jQuery-UI Theme' say "The currently available jQuery-UI themes are listed here: https://github.com/fatdude/jquery-ui-themes-rails/blob/master/README.markdown" @front_ui_theme = ask("Choose a jQuery-UI theme for the front site: [<enter>=redmond|<custom_name>]", 'redmond') else @front_theme = [:front_theme] @front_ui_theme = [:front_ui_theme] end invoke 'hobo:install_default_plugins', [], {:subsite => 'front', :theme => "hobo_#{@front_theme}", :ui_theme => @front_ui_theme, :skip_gem => false} end |
#invoking_user_and_admin ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/generators/hobo/setup_wizard/setup_wizard_generator.rb', line 200 def invoking_user_and_admin say "Installing '#{@user_resource_name}' resources..." invoke 'hobo:user_resource', [@user_resource_name], :invite_only => @invite_only, :activation_email => @activation_email, :admin_subsite_name => @admin_subsite_name if @invite_only || @add_admin_subsite say "Installing admin subsite..." invoke 'hobo:admin_subsite', [@admin_subsite_name], :user_resource_name => @user_resource_name, :invite_only => @invite_only, :theme => @admin_theme, :ui_theme => @admin_ui_theme end end |
#quiet_assets ⇒ Object
142 143 144 145 |
# File 'lib/generators/hobo/setup_wizard/setup_wizard_generator.rb', line 142 def quiet_assets say "Adding quiet_assets gem" gem_with_comments('quiet_assets', :group => :development, :comments => "\n# Hobo has a lot of assets. Stop cluttering the log in development mode.") end |
#site_options ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/generators/hobo/setup_wizard/setup_wizard_generator.rb', line 92 def if wizard? say_title 'Invite Only Option' return unless (@invite_only = yes_no?("Do you want to add the features for an invite only website?")) private_site = yes_no?("Do you want to prevent all access to the site to non-members?\n(Choose 'y' only if ALL your site will be private, choose 'n' if at least one controller will be public)") say( %( If you wish to prevent all access to some controller to non-members, add 'before_filter :login_required' to the relevant controllers: include Hobo::Controller::AuthenticationSupport before_filter :login_required (note that the include statement is not required for hobo_controllers) NOTE: You might want to sign up as the administrator before adding this! ), Color::YELLOW) unless private_site else @invite_only = invite_only? private_site = [:private_site] end inject_into_file 'app/controllers/application_controller.rb', <<EOI, :after => "protect_from_forgery with: :exception\n" if private_site include Hobo::Controller::AuthenticationSupport before_filter :except => [:login, :forgot_password, :accept_invitation, :do_accept_invitation, :reset_password, :do_reset_password] do login_required unless #{@user_resource_name.camelize}.count == 0 end EOI end |
#startup ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/generators/hobo/setup_wizard/setup_wizard_generator.rb', line 73 def startup if wizard? say_title [:main_title] ? 'Hobo Setup Wizard' : 'Startup' say 'Installing Hobo assets...' end invoke 'hobo:assets' end |
#user_options ⇒ Object
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/generators/hobo/setup_wizard/setup_wizard_generator.rb', line 81 def if wizard? say_title 'User Resource' @user_resource_name = ask("Choose a name for the user resource: [<enter>=user|<custom_name>]", 'user') @activation_email = @invite_only ? false : yes_no?("Do you want to send an activation email to activate the user?") else @user_resource_name = [:user_resource_name] @activation_email = [:activation_email] end end |
#will_paginate ⇒ Object
147 148 149 150 |
# File 'lib/generators/hobo/setup_wizard/setup_wizard_generator.rb', line 147 def will_paginate say "Adding hobo_will_paginate gem" gem_with_comments('hobo_will_paginate', :comments => "\n# Hobo's version of will_paginate is required.") end |