Class: DrgcmsFormFields::Ckeditor

Inherits:
DrgcmsField
  • Object
show all
Defined in:
lib/patches/drgcms_form_field.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.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/patches/drgcms_form_field.rb', line 89

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