Class: Kowl::ViewsAndHelpersGenerator
- Inherits:
-
Generators::Base
- Object
- Rails::Generators::Base
- Generators::Base
- Kowl::ViewsAndHelpersGenerator
- Defined in:
- lib/kowl/generators/views_and_helpers_generator.rb
Instance Method Summary collapse
-
#copy_footer ⇒ Object
Generate an application footer view based on framework/template_engine.
-
#copy_navigation ⇒ Object
Generate an application navigation view based on framework/template_engine.
-
#generate_templates ⇒ Object
Generate templates with framework and templae_engine with required application options.
-
#inject_footer_into_layout ⇒ Object
Inject view template partial into application layout.
-
#inject_header_into_layout ⇒ Object
Inject navigation header into application layout file based on template_engine/framework.
-
#remove_application_layout ⇒ Object
If template engine isn’t set for erb remove application.erb.
-
#update_application_helpers ⇒ Object
Skip a flash type if the key is a cookie/session timeone, since this can occure so regularly.
Methods inherited from Generators::Base
default_source_root, source_paths
Methods included from Docker
#alpine_docker_dependencies, #app_js_volumes, #app_volumes, #db_volumes, #debian_database_dependencies, #debian_docker_dependencies, #docker_app_command, #docker_compose_database_string, #docker_databases, #docker_depends_on, #docker_port_watcher, #docker_redis_service, #docker_sidekiq_service, #docker_variables, #docker_volumes, #docker_webpacker_service, #dockerfile_database_args, #dockerfile_migration_snip, #js_volumes, #mysql_volumes, #postgresql_volumes, #redis_volumes
Methods included from Actions
#add_extension_routes, #add_package, #append_to_file, #database_route, #dev_config, #dup_file, #file_exists?, #mailer_gems, #mailer_route, #mk_dir, #move_file, #pry_gems, #rails_cmd, #remove_dir, #remove_file, #remove_gem, #replace_string_in_file, #robocop_test_engine, #sidekiq_route, #template_linter_gems
Instance Method Details
#copy_footer ⇒ Object
Generate an application footer view based on framework/template_engine
55 56 57 |
# File 'lib/kowl/generators/views_and_helpers_generator.rb', line 55 def template("shared/footer/#{[:framework]}.html.#{[:template_engine]}.tt", "app/views/shared/_footer.html.#{[:template_engine]}") if %w[bootstrap semantic].include? [:framework] end |
#copy_navigation ⇒ Object
Generate an application navigation view based on framework/template_engine
50 51 52 |
# File 'lib/kowl/generators/views_and_helpers_generator.rb', line 50 def template("shared/navigation/#{[:framework]}.html.#{[:template_engine]}.tt", "app/views/shared/_navigation.html.#{[:template_engine]}") if %w[bootstrap semantic].include? [:framework] end |
#generate_templates ⇒ Object
Generate templates with framework and templae_engine with required application options
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/kowl/generators/views_and_helpers_generator.rb', line 19 def generate_templates # Generate views using bootstrap and semanic view generators = [] .push("--template-engine=#{[:template_engine]}") .push('--simpleform') if [:simpleform] .push('--pagination') unless [:skip_pagination] .push('--devise') unless [:noauth] .push('--skip_javascript') if [:skip_javascript] .push('--skip_turbolinks') if [:skip_turbolinks] .push('--metatags') .push('--layout') generate("#{[:framework]}:install #{.join(' ')}") if %w[bootstrap semantic].include? [:framework] end |
#inject_footer_into_layout ⇒ Object
Inject view template partial into application layout
60 61 62 63 64 65 66 67 |
# File 'lib/kowl/generators/views_and_helpers_generator.rb', line 60 def = "#{template_prefix}= render 'shared/footer'#{template_postfix}\n" if [:template_engine] == 'erb' insert_into_file 'app/views/layouts/application.html.erb', optimize_indentation(, 4), before: " </body>\n" else append_to_file "app/views/layouts/application.html.#{[:template_engine]}", optimize_indentation(, 4) end end |
#inject_header_into_layout ⇒ Object
Inject navigation header into application layout file based on template_engine/framework
39 40 41 42 43 44 45 46 47 |
# File 'lib/kowl/generators/views_and_helpers_generator.rb', line 39 def inject_header_into_layout # prefix, includes, postfix # Pre and Postfix is determined if the template engine is ERB, Slim, or HAML nav_str = "#{template_prefix}= render 'shared/navigation'#{template_postfix}\n" match = { 'erb' => /\s\<body\>\n/, 'haml' => /\s%body\n/, 'slim' => /\sbody\n/ } insert_into_file "app/views/layouts/application.html.#{[:template_engine]}", optimize_indentation(nav_str, 4), after: match[[:template_engine]] end |
#remove_application_layout ⇒ Object
If template engine isn’t set for erb remove application.erb
34 35 36 |
# File 'lib/kowl/generators/views_and_helpers_generator.rb', line 34 def remove_application_layout remove_file 'app/views/layouts/application.html.erb' if %w[slim haml].include? [:template_engine] end |
#update_application_helpers ⇒ Object
Skip a flash type if the key is a cookie/session timeone, since this can occure so regularly
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/kowl/generators/views_and_helpers_generator.rb', line 70 def update_application_helpers flash_str = <<~STR \n# remove any blank devise timeout errors flash.delete(:timedout) STR # User to prevent blank devise timeout error from flashing up insert_into_file 'app/helpers/application_helper.rb', "\n#{optimize_indentation(flash_str.strip, 4)}", after: "return '' unless flash.any?\n" if [:framework] == 'bootstrap' # Make applicaction_helper immutable insert_into_file 'app/helpers/application_helper.rb', "# frozen_string_literal: true\n\n", before: "module ApplicationHelper\n" end |