Class: DrgcmsFormFields::Ckeditor

Inherits:
DrgcmsField
  • Object
show all
Defined in:
app/models/drgcms_form_fields/ckeditor.rb

Overview

Class for creating ckeditor DRG CMS form field.

Instance Method Summary collapse

Instance Method Details

#renderObject

Return code required to render ckeditor DRG CMS form field.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/models/drgcms_form_fields/ckeditor.rb', line 34

def render
  return ro_standard if @readonly
  set_initial_value
# read configuration from site settings
  ck_config = '/assets/ckeditor_config.js'
  ck_css    = '/assets/ckeditor_css.css' 
  ck = @parent.dc_get_site ? @parent.dc_get_site.params['ckeditor'] : nil # site might not be available yet
  if ck
    ck_config = ck['config_file'] if ck['config_file']
    ck_css    = ck['css_file'] if ck['css_file']
  end
#  
  @yaml['options'] ||= ''
  @yaml['options'] << ", customConfig: '#{ck_config}'"
  @yaml['options'] << ", contentsCss: '#{ck_css}'" unless ck_css.blank?
  @yaml['options'] << ", language: '#{I18n.locale}'" unless @yaml['options'].match('language:')
  
  options = @yaml['options'] ? ",{#{@yaml['options']}}" : ''
  record = record_text_for(@yaml['name'])
  @html << @parent.text_area(record, @yaml['name'], @yaml['html']) 
  @js << "CKEDITOR.replace( '#{record}_#{@yaml['name']}'#{options} );"
  self
end