class Qbrick::CustomModelGenerator
Public Instance Methods
add_controller()
click to toggle source
# File lib/generators/qbrick/custom_model_generator.rb, line 61 def add_controller generate 'controller', controller_name, '--no-helper --no-assets --no-test-framework' gsub_file "app/controllers/#{controller_name}_controller.rb", 'ApplicationController', 'Qbrick::BaseController' end
add_model_and_migration()
click to toggle source
# File lib/generators/qbrick/custom_model_generator.rb, line 33 def add_model_and_migration generate 'model', model_name, ARGV[1..-1].join(' '), '--no-test-framework' inject_into_file "app/models/#{model_name}.rb", before: 'class' do "require 'qbrick/cms_model'\n\n" end inject_into_file "app/models/#{model_name}.rb", before: 'end' do <<-eos.gsub(/^ {8}/, '').chomp include Qbrick::CMSModel # TODO: Define what attributes are shown in the form and permitted by strong parameters editable_attributes #{attribute_keys_as_string} # TODO: Define what attributes are shown in the index view index_attributes #{attribute_keys_as_string} eos end end
add_resource_translations()
click to toggle source
# File lib/generators/qbrick/custom_model_generator.rb, line 53 def add_resource_translations I18n.available_locales.each do |locale| I18n.with_locale(locale) do template 'translations/resource.yml.erb', "config/locales/#{locale}/#{model_name}.yml" end end end
add_route()
click to toggle source
# File lib/generators/qbrick/custom_model_generator.rb, line 21 def add_route generate 'resource_route', resource_route_name end
set_up_custom_models_base()
click to toggle source
# File lib/generators/qbrick/custom_model_generator.rb, line 12 def set_up_custom_models_base return if custom_models_base_already_installed? setup_base_controller setup_base_views setup_navigation setup_translation_file end
source_paths()
click to toggle source
# File lib/generators/qbrick/custom_model_generator.rb, line 5 def source_paths [ File.join(File.dirname(__FILE__), '../../../app/views/qbrick/cms/backend/'), File.join(File.dirname(__FILE__), '../../templates/qbrick/', self.class.name.demodulize.underscore) ] end
Private Instance Methods
attribute_keys_as_string()
click to toggle source
# File lib/generators/qbrick/custom_model_generator.rb, line 113 def attribute_keys_as_string ARGV[1..-1].map { |a| ":#{a.split(':').first}" }.join(', ') end
attributes()
click to toggle source
# File lib/generators/qbrick/custom_model_generator.rb, line 109 def attributes ARGV[1..-1].map { |x| x.split(':').first } end
controller_name()
click to toggle source
# File lib/generators/qbrick/custom_model_generator.rb, line 101 def controller_name "cms/#{model_name.pluralize}" end
custom_models_base_already_installed?()
click to toggle source
# File lib/generators/qbrick/custom_model_generator.rb, line 68 def custom_models_base_already_installed? File.exist?('app/controllers/qbrick/base_controller.rb') && File.exist?('app/views/qbrick/cms/backend/_main_navigation.html.haml') end
model_name()
click to toggle source
# File lib/generators/qbrick/custom_model_generator.rb, line 97 def model_name ARGV.first.downcase end
resource_route_name()
click to toggle source
# File lib/generators/qbrick/custom_model_generator.rb, line 93 def resource_route_name "cms/#{model_name}" end
route_name()
click to toggle source
# File lib/generators/qbrick/custom_model_generator.rb, line 105 def route_name controller_name.gsub('/', '_') end
setup_base_controller()
click to toggle source
# File lib/generators/qbrick/custom_model_generator.rb, line 72 def setup_base_controller empty_directory 'app/controllers/qbrick' template 'base_controller.rb', 'app/controllers/qbrick/base_controller.rb' end
setup_base_views()
click to toggle source
# File lib/generators/qbrick/custom_model_generator.rb, line 77 def setup_base_views directory 'inherited_views', 'app/views/qbrick' end
setup_translation_file()
click to toggle source
# File lib/generators/qbrick/custom_model_generator.rb, line 88 def setup_translation_file empty_directory 'config/locales/de' copy_file 'translations/qbrick_base.yml', 'config/locales/de/qbrick_base.yml' end