Class: Adminpanel::Generators::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_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 "controller.rb", "app/controllers/adminpanel/#{pluralized_name}_controller.rb"
  end
end


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', [lower_singularized_name]
  end
end

#generate_migrations ⇒ Object



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

def generate_migrations
  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 'resource.rb', "app/models/adminpanel/#{lower_singularized_name}.rb"
end


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

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