class Blade::BladeSetting
Public Class Methods
generate_base_files()
click to toggle source
# File lib/blade/setting.rb, line 156 def generate_base_files generator = Blade::Setting::ControllerTemplate::InstallGenerator.new application_helper = Blade::Setting::BaseTemplate::APPLICATION_HELPER application_builder = Blade::Setting::BaseTemplate::APPLICATION_JSON_BUILDER base_model_concern = Blade::Setting::BaseTemplate::BASE_MODEL_CONCERN response = Blade::Setting::BaseTemplate::RESPONSE response_json = Blade::Setting::BaseTemplate::RESPONSE_JSON application_helper_path = Rails.root.join('app', 'helpers', 'application_helper.rb') application_builder_path = Rails.root.join('app', 'views', 'layouts', 'application.json.jbuilder') response_path = Rails.root.join('app', 'models', 'response.rb') base_model_concern_path = Rails.root.join('app', 'models', 'concerns', 'base_model_concern.rb') response_json_path = Rails.root.join('app', 'views', 'common', '_response_status.json.jbuilder') generator.create_view_file(application_builder_path, application_builder) generator.create_view_file(application_helper_path, application_helper) generator.create_view_file(response_path, response) generator.create_view_file(base_model_concern_path, base_model_concern) generator.create_view_file(response_json_path, response_json) end
generate_crud(model_class, name, namespace)
click to toggle source
# File lib/blade/setting.rb, line 86 def generate_crud(model_class, name, namespace) model = model_class.name arg1 = name args = arg1.pluralize #generate routes Blade::Setting::ControllerTemplate::InstallGenerator.new.add_routes(args, namespace) #generate controller con_path = Rails.root.join('app', 'controllers', namespace, "#{args}_controller.rb") con_file = Blade::Setting::ControllerTemplate::InstallGenerator.controller_tmp(model_class, name, namespace); Blade::Setting::ControllerTemplate::InstallGenerator.new.create_view_file(con_path, con_file) #generate views index_view_path = Rails.root.join('app', 'views', namespace, args.to_s, 'index.json.jbuilder') common_view_path = Rails.root.join('app', 'views', namespace, 'common', "_#{arg1}.json.jbuilder") update_view_path = Rails.root.join('app', 'views', namespace, args.to_s, 'update.json.jbuilder') create_view_path = Rails.root.join('app', 'views', namespace, args.to_s, 'create.json.jbuilder') delete_view_path = Rails.root.join('app', 'views', namespace, args.to_s, 'destroy.json.jbuilder') index_content = <<-File json.#{args} do if @#{args}.present? render_json_array_partial(json,@#{args},'#{namespace}/common/#{arg1}',:#{arg1}) else {} end end File common_view_content = <<-File if #{arg1}.present? render_json_attrs(json, #{arg1}) else json.#{arg1} {} end File create_view_content = <<-File if @#{arg1}.present? json.#{arg1} do render_json_attrs(json, @#{arg1}) end else json.#{arg1} {} end File # update_view_content = <<-File json.#{arg1} do if @#{arg1}.present? render_json_attrs(json,@#{arg1}) else {} end end File Blade::Setting::ControllerTemplate::InstallGenerator.new.create_view_file(index_view_path, index_content) Blade::Setting::ControllerTemplate::InstallGenerator.new.create_view_file(create_view_path, create_view_content) Blade::Setting::ControllerTemplate::InstallGenerator.new.create_view_file(update_view_path, update_view_content) Blade::Setting::ControllerTemplate::InstallGenerator.new.create_view_file(common_view_path, common_view_content) Blade::Setting::ControllerTemplate::InstallGenerator.new.create_view_file(delete_view_path, '') end
generate_custom_yml(name)
click to toggle source
# File lib/blade/setting.rb, line 179 def generate_custom_yml(name) gt = Blade::Setting::ControllerTemplate::InstallGenerator.new end
generate_doc(model, name)
click to toggle source
# File lib/blade/setting.rb, line 192 def generate_doc(model, name) file = <<File require 'swagger_helper' describe '#{name}模块' do #{Blade::Setting::SwaggerTemplate.generate_template(model, name)} end File path = Rails.root.join('spec', 'integration', "#{model}_spec.rb") gt.create_view_file(path, file) end
generate_gem(name)
click to toggle source
# File lib/blade/setting.rb, line 188 def generate_gem(name) gt.add_gem(name) end
generate_model_template(model_class, name)
click to toggle source
# File lib/blade/setting.rb, line 56 def generate_model_template(model_class, name) model_file = Blade::Setting::ModelTemplate.model_template(model_class) path = Dir.pwd + "/app/models/" + name + ".rb" gt = Blade::Setting::ControllerTemplate::InstallGenerator.new file = nil file_path = Rails.root.join('app', 'models', "#{name}.rb") # if File.exist?(path) # file = File.open(path, "w") # else # file = File.new(path, "w") # end # file.write model_file; gt.create_view_file(file_path, model_file) end
generate_service_template(model_class,name)
click to toggle source
# File lib/blade/setting.rb, line 71 def generate_service_template(model_class,name) model_file = Blade::Setting::ServiceTemplate.service_template(model_class) path = Dir.pwd + "/app/services/" + name + "_service.rb" gt = Blade::Setting::ControllerTemplate::InstallGenerator.new file = nil file_path = Rails.root.join('app', 'services', "#{name}_service.rb") # if File.exist?(path) # file = File.open(path, "w") # else # file = File.new(path, "w") # end # file.write model_file; gt.create_view_file(file_path, model_file) end
generate_setting_logic(setting_path, configs = [])
click to toggle source
if in_rails_application? || in_rails_application_subdirectory?
exit(0)
else
exit(1)
end
# File lib/blade/setting.rb, line 21 def generate_setting_logic(setting_path, configs = []) configs.each do |config| path = Dir.pwd unless Dir.exist?(path + setting_path) FileUtils.mkdir_p path + setting_path end file = File.new(path + setting_path + '/' + config + '_setting.rb', 'w') file.write <<-File class #{config.camelize}Setting < Settingslogic source "#{'#{Rails.root}'}/config/#{config}.yml" namespace Rails.env end File end end
generate_setting_yml(yml_base_path, extra_path, configs = [])
click to toggle source
# File lib/blade/setting.rb, line 41 def generate_setting_yml(yml_base_path, extra_path, configs = []) all_environment_paths = extra_path all_environment_paths.each do |env_path| path = Dir.pwd unless Dir.exist?(path + yml_base_path + '/' + env_path) FileUtils.mkdir_p path + yml_base_path + '/' + env_path + '/' + 'config' end configs.each do |config| yml_file = "Blade::Setting::YmlTemplate::#{config.upcase}_YML".constantize file = File.new(path + yml_base_path + '/' + env_path + '/' + 'config' '/' + config + '.yml', 'w') file.write yml_file end end end
get_model(name)
click to toggle source
# File lib/blade/setting.rb, line 184 def get_model(name) ActiveSupport::Dependencies.constantize(name.classify) end
gt()
click to toggle source
# File lib/blade/setting.rb, line 208 def gt Blade::Setting::ControllerTemplate::InstallGenerator.new end