Class: Adminpanel::ResourceGenerator

Inherits:
ActiveRecord::Generators::Base
  • Object
show all
Defined in:
lib/generators/adminpanel/resource/resource_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_resource_to_configObject



48
49
50
51
52
53
54
55
# File 'lib/generators/adminpanel/resource/resource_generator.rb', line 48

def add_resource_to_config
	if setup_is_found? && is_a_resource?
		inject_into_file 'config/initializers/adminpanel_setup.rb',
			after: 'config.displayable_resources = [' do
			indent "\n:#{pluralized_name},", 4
		end
	end
end

#change_fields_aliasesObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/generators/adminpanel/resource/resource_generator.rb', line 14

def change_fields_aliases
	fields.each do |attribute|
		type = attribute.split(':').second
		case type
		when 'wysiwyg'
			fields.delete(attribute)
			fields << attribute.split(':').first + ':' + 'text'
		end
	end
end

#generate_controllerObject



29
30
31
32
33
# File 'lib/generators/adminpanel/resource/resource_generator.rb', line 29

def generate_controller
	if is_a_resource?
		template "controller.rb", "app/controllers/adminpanel/#{pluralized_name}_controller.rb"
	end
end


42
43
44
45
46
# File 'lib/generators/adminpanel/resource/resource_generator.rb', line 42

def generate_gallery
	if has_gallery? && is_a_resource?
		invoke 'adminpanel:gallery', [lower_singularized_name]
	end
end

#generate_migrationObject



35
36
37
38
39
40
# File 'lib/generators/adminpanel/resource/resource_generator.rb', line 35

def generate_migration
	parameters = fields
	parameters.delete_if{ |pair| pair.split(':').second == 'has_many' }
	invoke :migration, ["create_adminpanel_#{pluralized_name}", parameters]
	puts parameters if ENV['RAILS_ENV']
end

#generate_modelObject



25
26
27
# File 'lib/generators/adminpanel/resource/resource_generator.rb', line 25

def generate_model
		template 'resource.rb', "app/models/adminpanel/#{lower_singularized_name}.rb"
end


57
58
59
# File 'lib/generators/adminpanel/resource/resource_generator.rb', line 57

def print_messages
	puts "don't forget to restart your server"
end