lib/generators/katapult/clearance/clearance_generator.rb in katapult-0.2.0 vs lib/generators/katapult/clearance/clearance_generator.rb in katapult-0.3.0

- old
+ new

@@ -4,12 +4,13 @@ module Katapult module Generators class ClearanceGenerator < Katapult::Generator - desc 'Generate authentication with Clearance' + MENU_BAR = 'app/views/layouts/_menu_bar.html.haml' + desc 'Generate authentication with Clearance' check_class_collision source_root File.expand_path('../templates', __FILE__) def migrate @@ -72,10 +73,21 @@ resources :passwords, controller: 'passwords', only: [:create, :new] delete '/logout', to: 'clearance/sessions#destroy', as: 'sign_out' ROUTES end + def add_current_user_to_layout + template 'app/views/layouts/_current_user.html.haml' + inject_into_file MENU_BAR, <<-CONTENT, after: /^\s+#navbar.*\n/ + = render 'layouts/current_user' if signed_in? + CONTENT + end + + def hide_navigation_unless_signed_in + gsub_file MENU_BAR, /(render.*navigation')/, '\1 if signed_in?' + end + def add_sign_in_background_to_all_features Dir['features/*.feature'].each do |file| inject_into_file file, <<-CONTENT, after: /^Feature: .*$/ @@ -108,10 +120,10 @@ CONTENT end def add_user_factory - inject_into_file 'spec/factories/factories.rb', <<-'CONTENT', after: 'FactoryGirl.define do' + inject_into_file 'spec/factories/factories.rb', <<-'CONTENT', after: 'FactoryBot.define do' factory :user do sequence(:email) { |i| "user-#{ i }@example.com" } password 'password' end