Sha256: 93c52f5afdc56a6d6956adb166fd013bf8bc94add6e70a8c2157318a6ba6af0a
Contents?: true
Size: 1.59 KB
Versions: 2
Compression:
Stored size: 1.59 KB
Contents
require 'rails/generators' module Layout module Generators class LayoutGenerator < ::Rails::Generators::Base source_root File.expand_path("../templates", __FILE__) argument :framework_name, :type => :string, :default => "simple" attr_reader :app_name # Create an application layout file with partials for messages and navigation def generate_layout app = ::Rails.application @app_name = app.class.to_s.split("::").first ext = app.config.generators.options[:rails][:template_engine] || :erb # so far, I've only got templates for ERB, but Haml and Slim could be added template "#{framework_name}-application.html.#{ext}", "app/views/layouts/application.html.#{ext}" copy_file "#{framework_name}-messages.html.#{ext}", "app/views/layouts/_messages.html.#{ext}" copy_file "#{framework_name}-navigation.html.#{ext}", "app/views/layouts/_navigation.html.#{ext}" end # If 'About' or 'Contact' views exist in known locations, add navigation links def add_navigation_links # not yet accommodating Haml and Slim (we'll need different substitutions) if File.exists?('app/views/pages/about.html.erb') insert_into_file 'app/views/layouts/_navigation.html.erb', "\n <li><%= link_to 'About', page_path('about') %></li>", :before => "\n</ul>" end if File.exists?('app/views/contacts/new.html.erb') insert_into_file 'app/views/layouts/_navigation.html.erb', "\n <li><%= link_to 'Contact', new_contact_path %></li>", :before => "\n</ul>" end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rails_layout-0.1.3 | lib/generators/layout/layout_generator.rb |
rails_layout-0.1.2 | lib/generators/layout/layout_generator.rb |