Class: Bootstrap::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Bootstrap::Generators::InstallGenerator
- Includes:
- BootstrapViewsGenerator::Helpers
- Defined in:
- lib/generators/bootstrap/install_generator.rb
Instance Method Summary collapse
- #copy_scaffold_views ⇒ Object
- #copy_shared_pagination ⇒ Object
- #copy_simpleforms ⇒ Object
- #create_layout ⇒ Object
-
#inject_application_helpers ⇒ Object
Inject Bootstrap helpers into the application_helper file.
- #invoke_devise_generator ⇒ Object
Methods included from BootstrapViewsGenerator::Helpers
Instance Method Details
#copy_scaffold_views ⇒ Object
38 39 40 41 42 43 |
# File 'lib/generators/bootstrap/install_generator.rb', line 38 def copy_scaffold_views %w[edit index show new].each do |file| template "scaffolds/#{[:template_engine]}/#{file}.html.#{[:template_engine]}", "lib/templates/#{[:template_engine]}/scaffold/#{file}.html.#{[:template_engine]}", force: true end copy_file "scaffolds/#{[:template_engine]}/_form.html.#{[:template_engine]}", "lib/templates/#{[:template_engine]}/scaffold/_form.html.#{[:template_engine]}", force: true end |
#copy_shared_pagination ⇒ Object
49 50 51 |
# File 'lib/generators/bootstrap/install_generator.rb', line 49 def copy_shared_pagination copy_file("shared/_pagination.html.#{[:template_engine]}", "app/views/shared/_pagination.html.#{[:template_engine]}", force: true) if [:pagination] end |
#copy_simpleforms ⇒ Object
53 54 55 |
# File 'lib/generators/bootstrap/install_generator.rb', line 53 def copy_simpleforms copy_file("simple_form/_form.html.#{[:template_engine]}", "lib/templates/#{[:template_engine]}/scaffold/_form.html.#{[:template_engine]}", force: true) if [:simpleform] end |
#create_layout ⇒ Object
45 46 47 |
# File 'lib/generators/bootstrap/install_generator.rb', line 45 def create_layout template("layouts/application.html.#{[:template_engine]}.tt", "app/views/layouts/application.html.#{[:template_engine]}", force: true) if [:layout] end |
#inject_application_helpers ⇒ Object
Inject Bootstrap helpers into the application_helper file
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/generators/bootstrap/install_generator.rb', line 58 def inject_application_helpers pagy_helper = ([: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 ⇒ Object
101 102 103 104 |
# 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 [:devise] end |