Class: Adminpanel::ResourceGenerator
- Inherits:
-
ActiveRecord::Generators::Base
- Object
- ActiveRecord::Generators::Base
- Adminpanel::ResourceGenerator
show all
- Includes:
- ResourceGeneratorHelper
- Defined in:
- lib/generators/adminpanel/resource/resource_generator.rb
Instance Method Summary
collapse
#assign_attributes_variables, #associations, #attribute_hash, #belongs_to_association, #belongs_to_field, #belongs_to_form_hash, #boolean_form_hash, #camelized_resource, #datepicker_form_hash, #file_field_form_hash, #float_form_hash, #form_type, #gallery_name, #get_attribute_hash, #get_gallery, #has_associations?, #has_gallery?, #has_many_association, #has_many_field, #has_many_form_hash, #integer_form_hash, #is_a_resource?, #label_type, #model_type, #placeholder_type, #pluralized_name, #resource_class_name, #resource_name, #setup_is_found?, #string_form_hash, #symbolized_attributes, #text_form_hash
Instance Method Details
#add_resource_to_config ⇒ Object
49
50
51
52
53
54
55
56
|
# File 'lib/generators/adminpanel/resource/resource_generator.rb', line 49
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_aliases ⇒ Object
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/generators/adminpanel/resource/resource_generator.rb', line 16
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_controller ⇒ Object
31
32
33
34
35
|
# File 'lib/generators/adminpanel/resource/resource_generator.rb', line 31
def generate_controller
if is_a_resource?
template 'adminpanel_controller_template.rb', "app/controllers/adminpanel/#{pluralized_name}_controller.rb"
end
end
|
#generate_gallery ⇒ Object
43
44
45
46
47
|
# File 'lib/generators/adminpanel/resource/resource_generator.rb', line 43
def generate_gallery
if has_gallery? && is_a_resource?
invoke 'adminpanel:gallery', [resource_name]
end
end
|
#generate_migration ⇒ Object
37
38
39
40
41
|
# File 'lib/generators/adminpanel/resource/resource_generator.rb', line 37
def generate_migration
parameters = fields
parameters.delete_if{ |pair| pair.split(':').second == 'has_many' }
invoke :migration, ["create_adminpanel_#{pluralized_name}", parameters]
end
|
#generate_model ⇒ Object
27
28
29
|
# File 'lib/generators/adminpanel/resource/resource_generator.rb', line 27
def generate_model
template 'adminpanel_resource_template.rb', "app/models/adminpanel/#{resource_name}.rb"
end
|
#print_messages ⇒ Object
58
59
60
|
# File 'lib/generators/adminpanel/resource/resource_generator.rb', line 58
def print_messages
puts "don't forget to restart your server and migrate db"
end
|