Class: Blade::BladeSetting
- Inherits:
-
Object
- Object
- Blade::BladeSetting
- Defined in:
- lib/blade/setting.rb
Class Method Summary collapse
- .generate_base_files ⇒ Object
- .generate_crud(model_class, name, namespace) ⇒ Object
- .generate_custom_yml(name) ⇒ Object
- .generate_doc(model, name) ⇒ Object
- .generate_gem(name) ⇒ Object
- .generate_model_template(model_class, name) ⇒ Object
-
.generate_setting_logic(setting_path, configs = []) ⇒ Object
if in_rails_application? || in_rails_application_subdirectory? exit(0) else exit(1) end.
- .generate_setting_yml(yml_base_path, extra_path, configs = []) ⇒ Object
- .get_model(name) ⇒ Object
- .gt ⇒ Object
Class Method Details
.generate_base_files ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/blade/setting.rb', line 140 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) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/blade/setting.rb', line 70 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 = "\njson.\#{args} do\nif @\#{args}.present?\n render_json_array_partial(json,@\#{args},'\#{namespace}/common/\#{arg1}',:\#{arg1})\nelse\n {}\nend\nend\n File\n common_view_content = <<-File\nif \#{arg1}.present?\n render_json_attrs(json, \#{arg1})\n else\n json.\#{arg1} {}\nend\n\n File\n\n create_view_content = <<-File\nif @\#{arg1}.present?\n json.\#{arg1} do\n render_json_attrs(json, @\#{arg1})\n end\n else\n json.\#{arg1} {}\nend\n File\n #\n update_view_content = <<-File\njson.\#{arg1} do\n if @\#{arg1}.present?\n render_json_attrs(json,@\#{arg1})\n else\n {}\n end\nend\n\n File\n\n Blade::Setting::ControllerTemplate::InstallGenerator.new.create_view_file(index_view_path, index_content)\n Blade::Setting::ControllerTemplate::InstallGenerator.new.create_view_file(create_view_path, create_view_content)\n Blade::Setting::ControllerTemplate::InstallGenerator.new.create_view_file(update_view_path, update_view_content)\n Blade::Setting::ControllerTemplate::InstallGenerator.new.create_view_file(common_view_path, common_view_content)\n Blade::Setting::ControllerTemplate::InstallGenerator.new.create_view_file(delete_view_path, '')\n\nend\n" |
.generate_custom_yml(name) ⇒ Object
163 164 165 |
# File 'lib/blade/setting.rb', line 163 def generate_custom_yml(name) gt = Blade::Setting::ControllerTemplate::InstallGenerator.new end |
.generate_doc(model, name) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/blade/setting.rb', line 176 def generate_doc(model, name) file = "require 'swagger_helper'\n\ndescribe '\#{name}\u6A21\u5757' do\n\n\#{Blade::Setting::SwaggerTemplate.generate_template(model, name)}\n\nend\n\n" path = Rails.root.join('spec', 'integration', "#{model}_spec.rb") gt.create_view_file(path, file) end |
.generate_gem(name) ⇒ Object
172 173 174 |
# File 'lib/blade/setting.rb', line 172 def generate_gem(name) gt.add_gem(name) end |
.generate_model_template(model_class, name) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/blade/setting.rb', line 55 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_setting_logic(setting_path, configs = []) ⇒ Object
if in_rails_application? || in_rails_application_subdirectory?
exit(0)
else
exit(1)
end
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/blade/setting.rb', line 20 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 "# frozen_string_literal: true\nclass \#{config.camelize}Setting < Settingslogic\n source \"\#{'\#{Rails.root}'}/config/\#{config}.yml\"\n namespace Rails.env\nend\n File\n end\nend\n" |
.generate_setting_yml(yml_base_path, extra_path, configs = []) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/blade/setting.rb', line 40 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) ⇒ Object
168 169 170 |
# File 'lib/blade/setting.rb', line 168 def get_model(name) ActiveSupport::Dependencies.constantize(name.classify) end |
.gt ⇒ Object
192 193 194 |
# File 'lib/blade/setting.rb', line 192 def gt Blade::Setting::ControllerTemplate::InstallGenerator.new end |