Module: DrgCms
- Defined in:
- lib/drg_cms.rb,
lib/drg_cms/engine.rb,
lib/drg_cms/version.rb
Overview
drg_cms gem version
Defined Under Namespace
Classes: Engine
Constant Summary collapse
- VERSION =
:nodoc:
'0.6.1.0'.freeze
- @@paths =
{}
Class Method Summary collapse
- .__cache_clear(key = nil) ⇒ Object
-
.add_forms_path(path) ⇒ Object
When new plugin with its own DRG forms is added to application, path to forms directory must be send to DrgCms module.
-
.add_patches_path(path) ⇒ Object
Patching is one of the rubies best strenghts and also its curse.
-
.add_path(type, path) ⇒ Object
General add path method.
-
.cache_clear(key = nil) ⇒ Object
Clear cache.
-
.from_root(file = nil) ⇒ Object
Will return name of file relative to drg_cms gem root.
- .model(model_name) ⇒ Object
-
.model_check(document, crash = false) ⇒ String
Checks if any errors exist on document and writes error log.
-
.paths(key) ⇒ Object
Will return value saved to internal @@paths hash.
-
.routes ⇒ Object
All Routes required by DrgCms.
Class Method Details
.__cache_clear(key = nil) ⇒ Object
172 173 174 175 176 |
# File 'lib/drg_cms.rb', line 172 def self.__cache_clear(key = nil) return Rails.cache.clear if key.nil? Rails.cache.delete_matched("#{key}*") end |
.add_forms_path(path) ⇒ Object
When new plugin with its own DRG forms is added to application, path to forms directory must be send to DrgCms module. Paths are saved into @@paths hash variable.
Adding path is best done in plugin mudule initialization code.
Parameters:
- path
-
String. Path to forms directory
Example:
# As used in MyPlugin plugin.
require "my_plugin/engine"
module MyPlugin
end
DrgCms.add_forms_path File.("../../app/forms", __FILE__)
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/drg_cms.rb', line 45 def self.add_forms_path(path) if @@paths[:forms].nil? @@paths[:forms] = [] # default application forms path # @@paths[:forms] << Rails.root.join('app/forms') # DrgCms forms path @@paths[:forms] << File.("../../app/forms", __FILE__) end @@paths[:forms] << path end |
.add_patches_path(path) ⇒ Object
Patching is one of the rubies best strenghts and also its curse. Loading patches in development has become real problem for developers. This is my way of patch loading.
Preferred location for patch files is lib/patches. But can be located anywhere in Rails application path. Add DrgCms.add_forms_path to initialization part and pass directory name where patching files are located as parameter.
Method will also load patch file so loading in config/initializers is not required.
Parameters:
- path
-
String. Path to patches directory
Example:
# As used in MyPlugin plugin.
require "my_plugin/engine"
module MyPlugin
end
DrgCms.add_patches_path File.dirname(__FILE__) + '/patches'
78 79 80 81 82 |
# File 'lib/drg_cms.rb', line 78 def self.add_patches_path(path) self.add_path(:patches, path) # Dir["#{path}/**/*.rb"].each { |path| p path; require_dependency path } # Dir["#{path}/**/*.rb"].each { |file| p file; require file } end |
.add_path(type, path) ⇒ Object
General add path method. Paths are saved into @@paths hash variable. Paths can then be reused in different parts of application.
Adding paths is best done in plugin mudule initialization code.
Parameters:
- type
-
Symbol. Defines type of data. Current used values are :forms, :patches
- path
-
String. Path or string which will be added to @@paths hash.
Example:
DrgCms.add_path(File.('patches', __FILE__), :patches)
97 98 99 100 |
# File 'lib/drg_cms.rb', line 97 def self.add_path(type, path) @@paths[type] ||= [] @@paths[type] << path end |
.cache_clear(key = nil) ⇒ Object
Clear cache. If key is specified only this key will be deleted.
162 163 164 165 166 167 168 169 170 |
# File 'lib/drg_cms.rb', line 162 def self.cache_clear(key = nil) return Rails.cache.clear if key.nil? if ((Rails.application.config.cache_store.first == :redis_cache_store) rescue false) Rails.cache.redis.del(key) else Rails.cache.delete_matched("#{key}*") end end |
.from_root(file = nil) ⇒ Object
Will return name of file relative to drg_cms gem root
117 118 119 |
# File 'lib/drg_cms.rb', line 117 def self.from_root(file=nil) File.("../../#{file}", __FILE__).to_s end |
.model(model_name) ⇒ Object
24 25 26 |
# File 'lib/drg_cms.rb', line 24 def self.model(model_name) File.("../../app/models/#{model_name}.rb", __FILE__) end |
.model_check(document, crash = false) ⇒ String
Checks if any errors exist on document and writes error log. It can also crash if requested. This is mostly usefull in development for debuging model errors or when updating multiple collections and each save must be checked if succesfull.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/drg_cms.rb', line 140 def self.model_check(document, crash = false) return nil unless document.errors.any? msg = "" document.errors.each do |attribute, errors_array| msg << "#{attribute}: #{errors_array}\n" end # if crash and msg.size > 0 msg = "Validation errors in #{document.class}:\n" + msg pp msg Rails.logger.error(msg) raise "Validation error. See log for more information." end msg end |
.paths(key) ⇒ Object
Will return value saved to internal @@paths hash.
Parameters:
- key
-
String. Key
forms_paths = DrgCms.paths(:forms) patches_paths = DrgCms.paths(:patches)
110 111 112 |
# File 'lib/drg_cms.rb', line 110 def self.paths(key) @@paths[key] end |
.routes ⇒ Object
All Routes required by DrgCms.
Usage: put DrgCms.routes line anywhere into your application routes file
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/drg_cms.rb', line 184 def self.routes Rails.application.routes.draw do # match '/dc_common/:action' => 'dc_common#:action', via: [:get, :put, :post] controller :dc_common do post 'dc_common/autocomplete' => :autocomplete post 'dc_common/ad_click' => :ad_click get 'dc_common/toggle_edit_mode' => :toggle_edit_mode match 'dc_common/process_login' => :process_login, via: [:put, :post] get 'dc_common/logout' => :logout get 'dc_common/login' => :login get 'dc_common/copy_clipboard' => :copy_clipboard match 'dc_common/paste_clipboard' => :paste_clipboard, via: [:get, :post] put 'dc_common/restore_from_journal' => :restore_from_journal get 'dc_common/add_json_ld_schema' => :add_json_ld_schema get 'dc_common/help' => :help end match 'elfinder' => 'dc_elfinder#connector', via: [:get, :post] match 'cmsedit/run' => 'cmsedit#run', via: [:get, :put, :post] resources :cmsedit resources :cms, controller: :cmsedit end end |