Class: Effective::FormInputs::ArticleEditor

Inherits:
Effective::FormInput show all
Defined in:
app/models/effective/form_inputs/article_editor.rb

Constant Summary

Constants inherited from Effective::FormInput

Effective::FormInput::BLANK, Effective::FormInput::DEFAULT_FEEDBACK_OPTIONS, Effective::FormInput::DEFAULT_INPUT_GROUP_OPTIONS, Effective::FormInput::EMPTY_HASH, Effective::FormInput::EXCLUSIVE_CLASS_PREFIXES, Effective::FormInput::EXCLUSIVE_CLASS_SUFFIXES, Effective::FormInput::HORIZONTAL_LABEL_OPTIONS, Effective::FormInput::HORIZONTAL_WRAPPER_OPTIONS, Effective::FormInput::INLINE_LABEL_OPTIONS, Effective::FormInput::VERTICAL_WRAPPER_OPTIONS

Instance Attribute Summary

Attributes inherited from Effective::FormInput

#name, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Effective::FormInput

#feedback_options, #hint_options, #initialize, #input_group_options, #label_options, #to_html, #wrapper_options

Constructor Details

This class inherits a constructor from Effective::FormInput

Class Method Details

.defaultsObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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
118
119
120
121
122
# File 'app/models/effective/form_inputs/article_editor.rb', line 8

def self.defaults
  {
     # This is overridden by the active_storage() method below
    active_storage: nil,

    # This is overridden by the css() method below
    css: ['/assets/article_editor/arx-frame.min.css'],

    # This is overridden by the custom_css() method below
    custom: {
      css: ['application.css', '/assets/effective_bootstrap_article_editor.css']
    },

    # The rest of these are just normal Hash options
    align: {
      'left': 'text-left',
      'center': 'text-center',
      'right': 'text-right',
      'justify': false
    },
    cellcolors: {
      'primary': { title: 'Primary', classname: 'table-primary' },
      'secondary': { title: 'Secondary', classname: 'table-secondary' },
      'active': { title: 'Active', classname: 'table-active' },
      'success': { title: 'Success', classname: 'table-success' },
      'danger': { title: 'Danger', classname: 'table-danger' },
      'warning': { title: 'Warning', classname: 'table-warning' },
      'info': { title: 'Info', classname: 'table-info' },
      'light': { title: 'Light', classname: 'table-light' },
      'dark': { title: 'Dark', classname: 'table-dark' }
    },
    classes: { table: 'table' },
    editor: {
      csscache: true,  # Do not add ?=timestamp to css requests
      https: true      # Embed links use https
    },
    embed: { script: false }, # do not strip out script tag from embeds
    filelink: nil,
    format: ['p', 'h2', 'h3', 'h4', 'h5', 'ul', 'ol'],
    grid: {
      classname: 'row',
      columns: 12,
      gutter: '1px',
      offset: {
        left: '15px',
        right: '15px',
      },
      patterns: {
        '6|6': 'col-md-6|col-md-6',
        '4|4|4': 'col-md-4|col-md-4|col-md-4',
        '3|3|3|3': 'col-md-3|col-md-3|col-md-3|col-md-3',
        '2|2|2|2|2|2': 'col-md-2|col-md-2|col-md-2|col-md-2|col-md-2|col-md-2',
        '3|6|3': 'col-md-3|col-md-6|col-md-3',
        '2|8|2': 'col-md-2|col-md-8|col-md-2',
        '5|7': 'col-md-5|col-md-7',
        '7|5': 'col-md-7|col-md-5',
        '4|8': 'col-md-4|col-md-8',
        '8|4': 'col-md-8|col-md-4',
        '3|9': 'col-md-3|col-md-9',
        '9|3': 'col-md-9|col-md-3',
        '2|10': 'col-md-2|col-md-10',
        '10|2': 'col-md-10|col-md-2',
        '12': 'col-md-12'
      }
    },
    layer: false, # the layer button is confusing for the layperson
    link: { size: 500 }, # truncate after this length
    makebutton: {
      items: {
        primary: {
          title: 'Primary',
          params: { classname: 'btn btn-primary' }
        },
        secondary: {
          title: 'Secondary',
          params: { classname: 'btn btn-secondary' }
        },
        danger: {
          title: 'Danger',
          params: { classname: 'btn btn-danger' }
        },
        primary_large: {
          title: 'Primary (large)',
          params: { classname: 'btn btn-lg btn-primary' }
        },
        secondary_large: {
          title: 'Secondary (large)',
          params: { classname: 'btn btn-lg btn-secondary' }
        },
        danger_large: {
          title: 'Danger (large)',
          params: { classname: 'btn btn-lg btn-danger' }
        }
      }
    },
    outset: false, # tricky to design around
    plugins: ['blockcode', 'carousel', 'cellcolor', 'collapse', 'filelink', 'imageposition', 'imageresize', 'inlineformat', 'listitem', 'makebutton', 'removeformat', 'reorder', 'style'],

    quote: {
      template: '<blockquote class="blockquote text-center"><p class="mb-0"><strong>A well-known quote, contained in a blockquote element.</strong></p></blockquote>'
    },
    styles: {
      table: {
        'bordered': { title: 'Bordered', classname: 'table-bordered' },
        'responsive': { title: 'Responsive', classname: 'table-responsive' },
        'small': { title: 'Small', classname: 'table-sm' },
        'striped': { title: 'Striped', classname: 'table-striped' },
      }
    },
    topbar: {
      undoredo: true,
      shortcuts: true
    },
  }
end

Instance Method Details

#active_storageObject



169
170
171
172
173
174
175
176
177
# File 'app/models/effective/form_inputs/article_editor.rb', line 169

def active_storage
  return @active_storage unless @active_storage.nil?

  @active_storage = if options.key?(:active_storage)
    options.delete(:active_storage)
  else
    defined?(ActiveStorage).present?
  end
end

#build_input(&block) ⇒ Object



142
143
144
# File 'app/models/effective/form_inputs/article_editor.rb', line 142

def build_input(&block)
  @builder.super_text_area(name, options[:input].merge(value: content))
end

#contentObject



138
139
140
# File 'app/models/effective/form_inputs/article_editor.rb', line 138

def content
  (defined?(ActionText::RichText) && value.kind_of?(ActionText::RichText)) ? value.body&.to_html : value
end

#cssObject



161
162
163
# File 'app/models/effective/form_inputs/article_editor.rb', line 161

def css
  [asset_path('article_editor/arx-frame.min.css')]
end

#custom_cssObject



165
166
167
# File 'app/models/effective/form_inputs/article_editor.rb', line 165

def custom_css
  [asset_path('application.css'), asset_path('effective_bootstrap_article_editor.css')]
end

#default_modeObject



124
125
126
# File 'app/models/effective/form_inputs/article_editor.rb', line 124

def default_mode
  self.class.defaults
end

#input_html_optionsObject



146
147
148
# File 'app/models/effective/form_inputs/article_editor.rb', line 146

def input_html_options
  { class: 'effective_article_editor form-control', id: unique_id, autocomplete: 'off' }
end

#input_js_optionsObject



150
151
152
153
154
155
156
157
158
159
# File 'app/models/effective/form_inputs/article_editor.rb', line 150

def input_js_options
  case mode
  when :default, :admin
    default_mode.merge(active_storage: active_storage, css: css, custom: { css: custom_css })
  when :restricted
    restricted_mode.merge(active_storage: false, css: css, custom: { css: custom_css })
  else
    raise("unexpected mode: #{mode}. Try :default or :restricted")
  end
end

#modeObject



179
180
181
182
183
184
185
186
187
# File 'app/models/effective/form_inputs/article_editor.rb', line 179

def mode
  return @mode unless @mode.nil?

  @mode = if options.key?(:mode)
    options.delete(:mode)
  else
    select_mode()
  end
end

#restricted_modeObject



128
129
130
131
132
133
134
135
136
# File 'app/models/effective/form_inputs/article_editor.rb', line 128

def restricted_mode
  self.class.defaults.merge(
    code: false,
    editor: { csscache: true, https: true, drop: false },
    embed: false,
    image: false,
    plugins: ['blockcode', 'cellcolor', 'inlineformat', 'listitem', 'removeformat', 'reorder', 'style']
  )
end

#select_modeObject



189
190
191
# File 'app/models/effective/form_inputs/article_editor.rb', line 189

def select_mode
  EffectiveResources.authorized?(@template, :admin, :effective_article_editor) ? :default : :restricted
end