Class: SuperuserGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/superuser/superuser_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



5
6
7
# File 'lib/generators/superuser/superuser_generator.rb', line 5

def attributes
  @attributes
end

Instance Method Details

#generate_controllerObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/generators/superuser/superuser_generator.rb', line 33

def generate_controller

    if !File.exist?("app/controllers/superuser/base_controller.rb")
        copy_file "base_controller.rb", "app/controllers/superuser/base_controller.rb"
    end
    if !File.exist?("app/controllers/superuser/dashboard_controller.rb")
        copy_file "dashboard_controller.rb", "app/controllers/superuser/dashboard_controller.rb"
        copy_file "views/dashboard_index.html.erb", "app/views/superuser/dashboard/index.html.erb"
        route "\tnamespace :superuser do\n\t\troot to: 'dashboard#index'\n\tend"
        add_layout_links 'app/views/layouts/superuser/application.html.erb', search = '<div class="sidebar_dashboard_link">', "<%= link_to 'dashboard', [:superuser, :root] %>"
    end
    template "controller_template.rb", "app/controllers/superuser/#{naming(:resources)}_controller.rb"

end

#generate_css_fileObject

NOTE: the order of the following methods is important!



9
10
11
12
13
14
15
# File 'lib/generators/superuser/superuser_generator.rb', line 9

def generate_css_file

    if !File.exist?("app/assets/stylesheets/superuser/application.scss")
        copy_file "superuser_base.scss", "app/assets/stylesheets/superuser/application.scss"
      end

end

#generate_js_fileObject



17
18
19
20
21
22
23
# File 'lib/generators/superuser/superuser_generator.rb', line 17

def generate_js_file

    if !File.exist?("app/assets/javascripts/superuser/application.js")
    	copy_file "superuser_base.js", "app/assets/javascripts/superuser/application.js"
    	end

end

#generate_layoutObject



25
26
27
28
29
30
31
# File 'lib/generators/superuser/superuser_generator.rb', line 25

def generate_layout

    if !File.exist?("app/views/layouts/superuser/application.html.erb")
        template "views/layouts/application.html.erb", "app/views/layouts/superuser/application.html.erb"
    end

end


48
49
50
51
52
53
54
55
56
57
58
# File 'lib/generators/superuser/superuser_generator.rb', line 48

def generate_route_and_link

    # add resources to route if not exists
    route_replacement = "resources :#{resources}"
    r = add_resources_route 'config/routes.rb', search = 'namespace :superuser do', route_replacement

    # add link to resources in the layout if not exists
    link = "<%= link_to '#{resources}', [:superuser, :#{resources}] %>"
    add_layout_links 'app/views/layouts/superuser/application.html.erb', search = '<div class="sidebar_item">', link

end

#generate_search_formObject



70
71
72
73
74
# File 'lib/generators/superuser/superuser_generator.rb', line 70

def generate_search_form

    template "views/_search.html.erb", "app/views/shared/_search.html.erb"

end

#generate_viewsObject



60
61
62
63
64
65
66
67
68
# File 'lib/generators/superuser/superuser_generator.rb', line 60

def generate_views

    template "views/_form.html.erb", "app/views/superuser/#{naming(:resources)}/_form.html.erb"
    template "views/index.html.erb", "app/views/superuser/#{naming(:resources)}/index.html.erb"
    template "views/show.html.erb", "app/views/superuser/#{naming(:resources)}/show.html.erb"
    template "views/new.html.erb", "app/views/superuser/#{naming(:resources)}/new.html.erb"
    template "views/edit.html.erb", "app/views/superuser/#{naming(:resources)}/edit.html.erb"

end