Class: Padrino::Generators::AdminPage

Inherits:
Thor::Group
  • Object
show all
Includes:
Actions, Padrino::Generators::Admin::Actions, Thor::Actions
Defined in:
padrino-admin/lib/padrino-admin/generators/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

Methods included from Padrino::Generators::Admin::Actions

#add_project_module, #ext, #fetch_app_name, #orm, #remove_project_module, #supported_ext, #supported_orm

Methods included from Actions

#already_exists?, #app_skeleton, #apply_component_for, #apply_default_fields, #check_app_existence, #destination_root, #empty_directory_with_keep_file, #execute_component_setup, #fetch_app_name, #fetch_component_choice, #fetch_project_name, #in_app_root?, #include_component_module_for, #initializer, #inject_into_file, #insert_hook, #insert_into_gemfile, #insert_middleware, #invalid_fields, #keep_file, #middleware, #recognize_path, #require_contrib, #require_dependencies, #resolve_valid_choice, #retrieve_component_config, #run_bundler, #store_component_choice, #store_component_config, #test?, #tiny?, #valid_choice?, #valid_constant?, #validate_namespace

Instance Attribute Details

#default_ormObject

Returns the value of attribute default_orm.



8
9
10
# File 'padrino-admin/lib/padrino-admin/generators/admin_page.rb', line 8

def default_orm
  @default_orm
end

Class Method Details

Defines the “banner” text for the CLI.



16
# File 'padrino-admin/lib/padrino-admin/generators/admin_page.rb', line 16

def self.banner; "padrino-gen admin_page [model]"; end

.source_rootObject

Define the source template root.



14
# File 'padrino-admin/lib/padrino-admin/generators/admin_page.rb', line 14

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

Instance Method Details

#create_controllerObject

Create controller for admin.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'padrino-admin/lib/padrino-admin/generators/admin_page.rb', line 42

def create_controller
  self.destination_root = options[:root]
  if in_app_root?
    @app_name = fetch_app_name
    @admin_name = options[:admin_name].classify
    @admin_path = options[:admin_name].underscore
    @admin_model = options[:admin_model]
    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_path+"/views/#{@orm.name_plural}")

      template "templates/page/controller.rb.tt",       destination_root(@admin_path+"/controllers/#{@orm.name_plural}.rb")
      template "templates/#{ext}/page/_form.#{ext}.tt", destination_root(@admin_path+"/views/#{@orm.name_plural}/_form.#{ext}")
      template "templates/#{ext}/page/edit.#{ext}.tt",  destination_root(@admin_path+"/views/#{@orm.name_plural}/edit.#{ext}")
      template "templates/#{ext}/page/index.#{ext}.tt", destination_root(@admin_path+"/views/#{@orm.name_plural}/index.#{ext}")
      template "templates/#{ext}/page/new.#{ext}.tt",   destination_root(@admin_path+"/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

#source_pathsObject

Look for custom template files in a generators folder under the project root.



24
25
26
27
28
29
30
# File 'padrino-admin/lib/padrino-admin/generators/admin_page.rb', line 24

def source_paths
  if File.exist? destination_root('generators')
    ["#{destination_root('generators')}", File.expand_path(File.dirname(__FILE__))]
  else
    [File.expand_path(File.dirname(__FILE__))]
  end
end