Class: Bootstrap::Generators::ThemedGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/bootstrap/themed/themed_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(args, *options) ⇒ ThemedGenerator

Returns a new instance of ThemedGenerator.



13
14
15
16
# File 'lib/generators/bootstrap/themed/themed_generator.rb', line 13

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

Instance Method Details

#copy_form_builderObject



18
19
20
# File 'lib/generators/bootstrap/themed/themed_generator.rb', line 18

def copy_form_builder
  copy_file "builders/builder.rb", "app/form_builders/bootstrap_form_builder.rb"
end

#copy_helperObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/generators/bootstrap/themed/themed_generator.rb', line 22

def copy_helper
  if File.exist?('app/helpers/application_helper.rb')
  insert_into_file "app/helpers/application_helper.rb","  def bootstrap_form_for(object, options = {}, &block)
    options[:builder] = BootstrapFormBuilder
    form_for(object, options, &block)
  end\n", :after => "module ApplicationHelper\n"
  else
  copy_file "builders/helper.rb", "app/helpers/application_helper.rb"
  end
end

#copy_viewsObject



33
34
35
36
37
38
39
# File 'lib/generators/bootstrap/themed/themed_generator.rb', line 33

def copy_views
  generate_views
  gsub_file(File.join('app/views/layouts', "#{layout}.html.erb"), /\<ul\s+class=\"nav\">.*\<\/ul\>/mi) do |match|
    match.gsub!(/\<\/ul\>/, "")
      %|#{match} <li class="<%= controller.controller_path == '#{@controller_file_path}' ? 'active' : '' %>"><a href="<%= #{controller_routing_path}_path %>">#{plural_model_name}</a></li></ul>|
    end
end