Class: AppThemer::ViewsGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/app_themer/views/views_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(args, *options) ⇒ ViewsGenerator

Returns a new instance of ViewsGenerator.



15
16
17
18
# File 'lib/generators/app_themer/views/views_generator.rb', line 15

def initialize(args, *options)
  super(args, *options)
  initialize_views_variables
end

Instance Method Details

#copy_viewsObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/generators/app_themer/views/views_generator.rb', line 20

def copy_views
  generate_views
  unless options.layout.blank?
    gsub_file(File.join('app/views/layouts', "#{options[:layout]}.html.#{options.engine}"), /\<nav\s+id=\"main-navigation\">.*\<\/ul\>/mi) do |match|
      match.gsub!(/\<\/ul\>/, "")
      if @engine.to_s =~ /haml/
        %|#{match}
      %li{:class => controller.controller_path == '#{@controller_file_path}' ? 'active' : '' }
        %a{:href => #{controller_routing_path}_path} #{plural_model_name}
      </ul>|
      else
        %|#{match} <li class="<%= controller.controller_path == '#{@controller_file_path}' ? 'active' : '' %>"><a href="<%= #{controller_routing_path}_path %>">#{plural_model_name}</a></li></ul>|
      end
    end
  end
end