class Toronto::InstallGenerator

Public Instance Methods

copy_form_builder() click to toggle source
# File lib/generators/toronto/install/install_generator.rb, line 26
def copy_form_builder
  copy_file "form_builders/form_builder/_form.html.#{options[:template_engine]}", "lib/templates/#{options[:template_engine]}/scaffold/_form.html.#{options[:template_engine]}"
end
copy_langs() click to toggle source
# File lib/generators/toronto/install/install_generator.rb, line 22
def copy_langs
  directory 'lib/templates/lang', 'lib/rails/generators/lang'
end
copy_lib() click to toggle source
# File lib/generators/toronto/install/install_generator.rb, line 18
def copy_lib
  directory "lib/templates/#{options[:template_engine]}"
end
copy_locales_controller() click to toggle source
# File lib/generators/toronto/install/install_generator.rb, line 49
def copy_locales_controller
  copy_file 'controllers/locales_controller.rb', 'app/controllers/locales_controller.rb'
end
copy_scaffold_generator() click to toggle source
# File lib/generators/toronto/install/install_generator.rb, line 14
def copy_scaffold_generator
  directory 'lib/rails'
end
create_layout() click to toggle source
# File lib/generators/toronto/install/install_generator.rb, line 30
def create_layout
  # Remove the default layout.
  remove_file 'app/views/layouts/application.html.erb'
  # Create the new one.
  template "layouts/starter.html.#{options[:template_engine]}", "app/views/layouts/application.html.#{options[:template_engine]}"
end
create_stylesheets() click to toggle source
# File lib/generators/toronto/install/install_generator.rb, line 37
def create_stylesheets
  stylesheet_extension = options[:stylesheet_engine] || 'css'

  copy_file "assets/stylesheets/starter.#{stylesheet_extension}", "app/assets/stylesheets/bootstrap-generators.#{stylesheet_extension}"
  copy_file 'assets/stylesheets/flags.css', 'app/assets/stylesheets/flags.css'
  copy_file 'assets/images/flags.png', 'app/assets/images/flags.png'

  if [:less, :scss].include?(options[:stylesheet_engine].to_sym)
    copy_file "assets/stylesheets/bootstrap-variables.#{stylesheet_extension}", "app/assets/stylesheets/bootstrap-variables.#{stylesheet_extension}"
  end
end
inject_backbone() click to toggle source
# File lib/generators/toronto/install/install_generator.rb, line 107
def inject_backbone
  application_js_path = 'app/assets/javascripts/application.js'

  if ::File.exists?(::File.join(destination_root, application_js_path))
    inject_into_file application_js_path, before: '//= require_tree' do
      "//= require bootstrap\n"
    end
  end
end
inject_locales_route() click to toggle source
# File lib/generators/toronto/install/install_generator.rb, line 66
def inject_locales_route
  p options
  langs = !options['languages'] || options['languages'].empty? ? 'en' : options['languages']
  langs_array = langs.split(',' )
  langs.gsub!( ',', '|' )

  # Create the routes for language management
  # This way lead to a lot of problem. We use ?locale=
  # route 'end'
  # route '  # Put all your routes inside the scope'
  # route "scope '(:locale)', locale: /#{langs}/ do"

  # Create the local file
  data = "I18n.config.load_path += Dir['#{Rails.root.to_s}/config/locales/**/*.{rb,yml}']\n\n"
  data << "I18n.config.available_locales = [ #{langs_array.map{ |e| ':'+e }.join( ', ' )} ]\n"
  data << "I18n.default_locale = :#{langs_array.first}"

  create_file 'config/initializers/locales.rb', data

  route "put 'set_locale/:locale', constraints: { locale: /#{langs}/ }, to: 'locales#set'"
end
inject_menu_helper() click to toggle source

def disable_regular_routes_generation

create_file 'config/initializers/generators.rb', 'Rails.application.config.generators.skip_routes = true'

end

# File lib/generators/toronto/install/install_generator.rb, line 92
    def inject_menu_helper
      # TODO : use a template file
      data = %{
def nav_link(link_text, link_path)
  class_name = current_page?(link_path) ? 'active' : ''

  content_tag(:li, :class => class_name) do
    link_to link_text, link_path
  end
end

}
      insert_into_file 'app/helpers/application_helper.rb', data, :before => /^end/
    end
patch_locale_files() click to toggle source
# File lib/generators/toronto/install/install_generator.rb, line 53
    def patch_locale_files
      # TODO : use a template file
      data = %{
  def set_locale
    I18n.locale = params[:locale] || I18n.default_locale
  end
}
      inject_into_file 'app/controllers/application_controller.rb', data, :before => /^end/

      data = "\n  before_action :set_locale"
      inject_into_file 'app/controllers/application_controller.rb', data, :after => /^class ApplicationController < ActionController::Base/
    end