class Bootstrap::Generators::InstallGenerator
Public Instance Methods
copy_scaffold_views()
click to toggle source
# File lib/generators/bootstrap/install_generator.rb, line 38 def copy_scaffold_views %w[edit index show new].each do |file| template "scaffolds/#{options[:template_engine]}/#{file}.html.#{options[:template_engine]}", "lib/templates/#{options[:template_engine]}/scaffold/#{file}.html.#{options[:template_engine]}", force: true end copy_file "scaffolds/#{options[:template_engine]}/_form.html.#{options[:template_engine]}", "lib/templates/#{options[:template_engine]}/scaffold/_form.html.#{options[:template_engine]}", force: true end
copy_simpleforms()
click to toggle source
# File lib/generators/bootstrap/install_generator.rb, line 53 def copy_simpleforms copy_file("simple_form/_form.html.#{options[:template_engine]}", "lib/templates/#{options[:template_engine]}/scaffold/_form.html.#{options[:template_engine]}", force: true) if options[:simpleform] end
create_layout()
click to toggle source
# File lib/generators/bootstrap/install_generator.rb, line 45 def create_layout template("layouts/application.html.#{options[:template_engine]}.tt", "app/views/layouts/application.html.#{options[:template_engine]}", force: true) if options[:layout] end
inject_application_helpers()
click to toggle source
Inject Bootstrap
helpers into the application_helper file
# File lib/generators/bootstrap/install_generator.rb, line 58 def inject_application_helpers pagy_helper = (options[:pagination] ? 'include Pagy::Frontend' : '') helper_str = <<~HELPER #{pagy_helper} # https://gist.github.com/fjahr/b3828b9f4e333e74ba1894687d65e055 def bootstrap_class_for(flash_type) { success: 'alert-success', error: 'alert-danger', alert: 'alert-warning', notice: 'alert-info' }.stringify_keys[flash_type.to_s] || flash_type.to_s end def flash_messages(_opts = []) return '' unless flash.any? flash.each do |msg_type, message| next unless !message.nil? && message.to_s.length.positive? concat(content_tag(:div, message, class: "alert \#{bootstrap_class_for(msg_type)}", role: 'alert') do concat content_tag(:button, 'x', class: 'close', data: { dismiss: 'alert' }) concat message end) end nil end # for outputting an objects error messages def errors_for(object) return '' unless object.errors.any? content_tag(:div, class: 'card border-danger') do concat(content_tag(:div, class: 'card-header bg-danger text-white') do concat "\#{pluralize(object.errors.count, 'error')} prohibited this \#{object.class.name.downcase} from being saved:" end) concat(content_tag(:ul, class: 'mb-0 list-group list-group-flush') do object.errors.full_messages.each do |msg| concat content_tag(:li, msg, class: 'list-group-item') end end) end end HELPER inject_into_file 'app/helpers/application_helper.rb', optimize_indentation(helper_str, 2), after: "module ApplicationHelper\n" end
invoke_devise_generator()
click to toggle source
# File lib/generators/bootstrap/install_generator.rb, line 101 def invoke_devise_generator # Generate bootstrap based devise views if devise is being used invoke('bootstrap:devise') if options[:devise] end