Class: FlexaLib::CrudGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/flexa_lib/crud/crud_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(args, *options) ⇒ CrudGenerator

Returns a new instance of CrudGenerator.



30
31
32
33
34
35
# File 'lib/generators/flexa_lib/crud/crud_generator.rb', line 30

def initialize(args, *options)
  #p args.to_yaml
  
  super(args, *options)
  initialize_views_variables
end

Instance Method Details

#copy_viewsObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/generators/flexa_lib/crud/crud_generator.rb', line 45

def copy_views
  generate_views      
  unless options.layout.blank?
    if options.engine =~ /erb/
      gsub_file(File.join('app/views/layouts', "#{options[:layout]}.html.#{options.engine}"), /\<div\s+id=\"main-navigation\">.*\<\/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
    elsif options.engine =~ /haml/
      gsub_file(File.join('app/views/layouts', "#{options[:layout]}.html.#{options.engine}"), /#main-navigation.*#wrapper.wat-cf/mi) do |match|
        match.gsub!(/      #wrapper.wat-cf/, "")
        %|#{match}| +
        "  "*6 + %|%li{:class => controller.controller_path == '#{@controller_file_path}' ? 'active' : '' }\n| +
        "  "*7 + %|%a{:href => #{controller_routing_path}_path} #{plural_model_name}\n| +
        "  "*3 + %|#wrapper.wat-cf|
      end
    end
  end
end

#create_controller_filesObject



38
39
40
41
42
43
# File 'lib/generators/flexa_lib/crud/crud_generator.rb', line 38

def create_controller_files
  if !options.no_controller
    template "controller.rb", File.join('app/controllers', "#{@controller_file_path}_controller.rb")
    route("resources :#{plural_resource_name}")
  end
end