Class: Kogno::Application
- Inherits:
-
Object
- Object
- Kogno::Application
- Includes:
- ActiveSupport::Configurable
- Defined in:
- lib/kogno.rb
Class Method Summary collapse
- .core_path ⇒ Object
- .create_project_folders ⇒ Object
- .file_path(file) ⇒ Object
-
.load_app ⇒ Object
Load App’s files: templates/*, controllers/*, helpers/* and models/*.
- .load_core ⇒ Object
- .load_locales ⇒ Object
- .project_path ⇒ Object
Class Method Details
.core_path ⇒ Object
51 52 53 |
# File 'lib/kogno.rb', line 51 def core_path File.('../../',__FILE__) end |
.create_project_folders ⇒ Object
59 60 61 62 63 64 |
# File 'lib/kogno.rb', line 59 def create_project_folders tmp = File.join(project_path,"tmp") logs = File.join(project_path,"logs") Dir.mkdir(tmp,0755) unless File.exist?(tmp) Dir.mkdir(logs,0755) unless File.exist?(logs) end |
.file_path(file) ⇒ Object
119 120 121 122 123 124 125 |
# File 'lib/kogno.rb', line 119 def file_path(file) if File.exist?(file) else File.open(file, "w") {|f| f.write("") } end return file end |
.load_app ⇒ Object
Load App’s files: templates/*, controllers/*, helpers/* and models/*
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 |
# File 'lib/kogno.rb', line 88 def load_app # Load App's files: templates/*, controllers/*, helpers/* and models/* $context_blocks = {} $context_html_templates = {} $contexts = Dir[File.join(self.project_path,'bot','contexts','*.rb')].map{|c| c.split("/").last.sub("_context.rb","")} rescue [] conversation_file = Dir[File.join(self.project_path,'bot','conversation.rb')] app_files = Dir[File.join(self.project_path,'bot','**','*.rb')] notification_template_files = Dir[File.join(self.project_path,'bot','**','*.erb')] html_template_files = Dir[File.join(self.project_path,'bot','**','*.rhtml')] lib_files = Dir[File.join(self.project_path,'lib','**','*.rb')] (conversation_file+app_files+notification_template_files+html_template_files+lib_files).each do |required_file| if required_file.include?("bot/templates/") file_extension = required_file.split(".").last.to_sym context = File.dirname(required_file).split("/").last.to_sym case file_extension when :erb action = File.basename(required_file,".erb").to_sym $context_blocks[context] = {} if $context_blocks[context].nil? # $context_blocks[context][action] = File.read(required_file) $context_blocks[context][action] = Tilt.new(required_file, nil, default_encoding: "utf-8") when :rhtml action = File.basename(required_file,".rhtml").to_sym $context_html_templates[context] = {} if $context_html_templates[context].nil? $context_html_templates[context][action] = Tilt.new(required_file, nil, default_encoding: "utf-8") end else load required_file end end return true end |
.load_core ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/kogno.rb', line 66 def load_core ignore_files = Dir[File.join(core_path,'lib','core','web','inc','*.rb')] files_to_load_later = [] Dir[File.join(core_path,'lib','core','**','*.rb')].each do |required_file| if !required_file.include?("lib/messenger/") and !required_file.include?("lib/telegram/") and !required_file.include?("lib/whatsapp/") load required_file unless ignore_files.include?(required_file) else files_to_load_later << required_file end end files_to_load_later.each do |required_file| load required_file unless ignore_files.include?(required_file) end end |
.load_locales ⇒ Object
82 83 84 85 86 |
# File 'lib/kogno.rb', line 82 def load_locales I18n.load_path = Dir[File.join(self.project_path,'config','locales','*.yml')] I18n.config.available_locales = self.config.available_locales I18n.default_locale = self.config.default_locale end |
.project_path ⇒ Object
55 56 57 |
# File 'lib/kogno.rb', line 55 def project_path File.(Dir.pwd) end |