57 lines
1.6 KiB
Ruby
57 lines
1.6 KiB
Ruby
class Rails::QisGenerator < Rails::Generators::NamedBase
|
|
source_root File.expand_path('templates', __dir__)
|
|
|
|
include Rails::Generators::ModelHelpers
|
|
|
|
argument :attributes, type: :array, default: [], banner: "field[:type][:index] field[:type][:index]"
|
|
|
|
|
|
include Rails::Generators::ResourceHelpers
|
|
|
|
|
|
def create_views_files
|
|
template "_class.html.haml", File.join("app/views", "admin", plural_name, "_#{singular_name}.html.haml")
|
|
template "_form.html.haml", File.join("app/views", "admin", plural_name, "_form.html.haml")
|
|
template "create.js.erb", File.join("app/views", "admin", plural_name, "create.js.erb")
|
|
template "destroy.js.erb", File.join("app/views", "admin", plural_name, "destroy.js.erb")
|
|
template "edit.js.erb", File.join("app/views", "admin", plural_name, "edit.js.erb")
|
|
template "index.html.haml", File.join("app/views", "admin", plural_name, "index.html.haml")
|
|
template "new.js.erb", File.join("app/views", "admin", plural_name, "new.js.erb")
|
|
template "show.html.haml", File.join("app/views", "admin", plural_name, "show.html.haml")
|
|
template "update.js.erb", File.join("app/views", "admin", plural_name, "update.js.erb")
|
|
|
|
|
|
route "namespace :admin do
|
|
resources :#{plural_name} do
|
|
member do
|
|
|
|
end
|
|
collection do
|
|
|
|
end
|
|
end
|
|
end
|
|
|
|
"
|
|
|
|
|
|
end
|
|
|
|
|
|
def create_controller_file
|
|
|
|
|
|
template "controller.rb", File.join("app/controllers", "admin", "#{controller_file_name}_controller.rb")
|
|
|
|
|
|
end
|
|
|
|
def run_other_generators
|
|
invoke "rails:model"
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
# V 0.1 |