Sha256: 752f121a1a8732332bf2f64bc75d09389a9ed8a2ad93455b604a8cf69a6b4049
Contents?: true
Size: 1.95 KB
Versions: 12
Compression:
Stored size: 1.95 KB
Contents
require 'rails/generators' module Navigation module Generators class NavigationGenerator < ::Rails::Generators::Base source_root File.expand_path("../templates", __FILE__) # Add navigation links def add_navigation_links app = ::Rails.application ext = app.config.generators.options[:rails][:template_engine] || :erb copy_file "navigation_links.html.erb", "app/views/layouts/_navigation_links.html.erb" # ABOUT append_file 'app/views/layouts/_navigation_links.html.erb', "<li><%= link_to 'About', page_path('about') %></li>\n" if File.exists?("app/views/pages/about.html.#{ext}") # CONTACT append_file 'app/views/layouts/_navigation_links.html.erb', "<li><%= link_to 'Contact', new_contact_path %></li>\n" if File.exists?("app/views/contacts/new.html.#{ext}") # DEVISE LOGIN and LOGOUT if File.exists?("app/views/devise/sessions/new.html.#{ext}") append_file 'app/views/layouts/_navigation_links.html.erb' do <<-LINKS <% if user_signed_in? %> <li><%= link_to 'Logout', destroy_user_session_path, :method=>'delete' %></li> <% else %> <li><%= link_to 'Login', new_user_session_path %></li> <% end %> LINKS end end # DEVISE SIGN UP if File.exists?("app/views/devise/registrations/new.html.#{ext}") append_file 'app/views/layouts/_navigation_links.html.erb' do <<-LINKS <% if user_signed_in? %> <li><%= link_to 'Edit account', edit_user_registration_path %></li> <% else %> <li><%= link_to 'Sign up', new_user_registration_path %></li> <% end %> LINKS end end # ADMIN LINK if File.exists?("app/views/users/index.html.#{ext}") append_file 'app/views/layouts/_navigation_links.html.erb' do <<-LINKS <% if user_signed_in? %> <% if current_user.has_role? :admin %> <li><%= link_to 'Admin', users_path %></li> <% end %> <% end %> LINKS end end end end end end
Version data entries
12 entries across 12 versions & 1 rubygems