Class: Blade::BladeSetting

Inherits:
Object
  • Object
show all
Defined in:
lib/blade/setting.rb

Class Method Summary collapse

Class Method Details

.generate_base_filesObject



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/blade/setting.rb', line 139

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, namespace) ⇒ Object



69
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
# File 'lib/blade/setting.rb', line 69

def generate_crud(model_class, namespace)

  model = model_class.name
  arg1 = model_class.name.downcase
  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, 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},'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



162
163
164
# File 'lib/blade/setting.rb', line 162

def generate_custom_yml(name)
 gt =  Blade::Setting::ControllerTemplate::InstallGenerator.new
end

.generate_model_template(model_class) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/blade/setting.rb', line 54

def generate_model_template(model_class)
  model_file = Blade::Setting::ModelTemplate.model_template(model_class)
  path = Dir.pwd + "/app/models/" + model_class.name.downcase + ".rb"
  gt = Blade::Setting::ControllerTemplate::InstallGenerator.new
  file = nil
  file_path = Rails.root.join('app','models',"#{model_class.name.downcase}.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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/blade/setting.rb', line 19

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.singularize}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



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/blade/setting.rb', line 39

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



167
168
169
# File 'lib/blade/setting.rb', line 167

def get_model(name)
  ActiveSupport::Dependencies.constantize(name.classify)
end