Class: Padrino::Generators::BsAdminPage

Inherits:
Thor::Group
  • Object
show all
Includes:
Actions, Admin::Actions, Thor::Actions
Defined in:
lib/bootstrap-on/bs_admin_page.rb

Overview

Defines the generator for creating a new admin page.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_ormObject

Returns the value of attribute default_orm.



7
8
9
# File 'lib/bootstrap-on/bs_admin_page.rb', line 7

def default_orm
  @default_orm
end

Class Method Details

Defines the “banner” text for the CLI.



15
# File 'lib/bootstrap-on/bs_admin_page.rb', line 15

def self.banner; "padrino g bs_admin_page [model]"; end

.source_rootObject

Define the source template root



13
# File 'lib/bootstrap-on/bs_admin_page.rb', line 13

def self.source_root; File.expand_path(File.dirname(__FILE__)); end

Instance Method Details

#create_controllerObject

Create controller for admin



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/bootstrap-on/bs_admin_page.rb', line 33

def create_controller
  self.destination_root = options[:root]
  if in_app_root?
    models.each do |model|
      @orm = default_orm || Padrino::Admin::Generators::Orm.new(model, adapter)
      self.behavior = :revoke if options[:destroy]
      empty_directory destination_root("/admin/views/#{@orm.name_plural}")

      template "templates/page/controller.rb.tt",       destination_root("/admin/controllers/#{@orm.name_plural}.rb")
      template "templates/#{ext}/page/_form.#{ext}.tt", destination_root("/admin/views/#{@orm.name_plural}/_form.#{ext}")
      template "templates/#{ext}/page/edit.#{ext}.tt",  destination_root("/admin/views/#{@orm.name_plural}/edit.#{ext}")
      template "templates/#{ext}/page/index.#{ext}.tt", destination_root("/admin/views/#{@orm.name_plural}/index.#{ext}")
      template "templates/#{ext}/page/new.#{ext}.tt",   destination_root("/admin/views/#{@orm.name_plural}/new.#{ext}")

      options[:destroy] ? remove_project_module(@orm.name_plural) : add_project_module(@orm.name_plural)
    end
  else
    say "You are not at the root of a Padrino application! (config/boot.rb not found)"
  end
end