Module: DrgCms

Defined in:
lib/drg_cms.rb,
lib/drg_cms/engine.rb,
lib/drg_cms/version.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Engine

Constant Summary collapse

VERSION =

drg_cms gem version

"0.5.52.9"
@@paths =
{}

Class Method Summary collapse

Class Method Details

.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.expand_path("../../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.expand_path("../../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.expand_path('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

.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.expand_path("../../#{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.expand_path("../../app/models/#{model_name}.rb", __FILE__)  
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

.routesObject

All Routes required by DrgCms.

Usage: put DrgCms.routes line anywhere into your application routes file



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/drg_cms.rb', line 127

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
      get '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
    end
    match 'elfinder' => 'dc_elfinder#connector', via: [:get, :post]
    resources :cmsedit
    resources :cms, controller: :cmsedit
  end
end