Class: Marksmith::Editor

Inherits:
Object
  • Object
show all
Defined in:
app/models/marksmith/editor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, upload_url: nil, rails_direct_uploads_url: nil, enable_file_uploads: nil, extra_preview_params: {}, form: nil, disabled: false, controller_data_attributes: {}, classes: nil, data_attributes: {}, placeholder: nil, autofocus: false, style: nil, value: nil, id: "marksmith-instance-#{rand(1000..9999)}", gallery: {}, **kwargs) ⇒ Editor

Returns a new instance of Editor.



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
# File 'app/models/marksmith/editor.rb', line 18

def initialize(name:,
  upload_url: nil,
  rails_direct_uploads_url: nil,
  enable_file_uploads: nil,
  extra_preview_params: {},
  form: nil,
  disabled: false,
  controller_data_attributes: {},
  classes: nil,
  data_attributes: {},
  placeholder: nil,
  autofocus: false,
  style: nil,
  value: nil,
  id: "marksmith-instance-#{rand(1000..9999)}",
  gallery: {},
  **kwargs)
  @name = name
  @kwargs = kwargs

  @upload_url = upload_url
  @rails_direct_uploads_url = rails_direct_uploads_url
  @enable_file_uploads = enable_file_uploads
  @extra_preview_params = extra_preview_params
  @form = form
  @disabled = disabled
  @controller_data_attributes = controller_data_attributes
  @classes = classes
  @data_attributes = data_attributes
  @placeholder = placeholder
  @autofocus = autofocus
  @style = style
  @value = value
  @id = id
  @gallery = gallery
end

Instance Attribute Details

#autofocusObject (readonly)

Returns the value of attribute autofocus.



4
5
6
# File 'app/models/marksmith/editor.rb', line 4

def autofocus
  @autofocus
end

#classesObject (readonly)

Returns the value of attribute classes.



4
5
6
# File 'app/models/marksmith/editor.rb', line 4

def classes
  @classes
end

#controller_data_attributesObject (readonly)

Returns the value of attribute controller_data_attributes.



4
5
6
# File 'app/models/marksmith/editor.rb', line 4

def controller_data_attributes
  @controller_data_attributes
end

#data_attributesObject (readonly)

Returns the value of attribute data_attributes.



4
5
6
# File 'app/models/marksmith/editor.rb', line 4

def data_attributes
  @data_attributes
end

#disabledObject (readonly)

Returns the value of attribute disabled.



4
5
6
# File 'app/models/marksmith/editor.rb', line 4

def disabled
  @disabled
end

#extra_preview_paramsObject (readonly)

Returns the value of attribute extra_preview_params.



4
5
6
# File 'app/models/marksmith/editor.rb', line 4

def extra_preview_params
  @extra_preview_params
end

#formObject (readonly)

Returns the value of attribute form.



4
5
6
# File 'app/models/marksmith/editor.rb', line 4

def form
  @form
end

Returns the value of attribute gallery.



4
5
6
# File 'app/models/marksmith/editor.rb', line 4

def gallery
  @gallery
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'app/models/marksmith/editor.rb', line 4

def id
  @id
end

#kwargsObject (readonly)

Returns the value of attribute kwargs.



4
5
6
# File 'app/models/marksmith/editor.rb', line 4

def kwargs
  @kwargs
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'app/models/marksmith/editor.rb', line 4

def name
  @name
end

#placeholderObject (readonly)

Returns the value of attribute placeholder.



4
5
6
# File 'app/models/marksmith/editor.rb', line 4

def placeholder
  @placeholder
end

#styleObject (readonly)

Returns the value of attribute style.



4
5
6
# File 'app/models/marksmith/editor.rb', line 4

def style
  @style
end

Instance Method Details

#enable_file_uploadsObject



87
88
89
90
91
92
93
94
95
# File 'app/models/marksmith/editor.rb', line 87

def enable_file_uploads
  if upload_url.blank?
    false
  elsif @enable_file_uploads.nil?
    true
  else
    @enable_file_uploads
  end
end

#field_nameObject



97
98
99
# File 'app/models/marksmith/editor.rb', line 97

def field_name
  form&.field_name(name) || name
end


55
56
57
# File 'app/models/marksmith/editor.rb', line 55

def gallery_enabled
  gallery.fetch(:enabled, false)
end


71
72
73
74
75
76
77
# File 'app/models/marksmith/editor.rb', line 71

def gallery_full_path
  if gallery_open_path.present?
    uri = URI.parse(gallery_open_path)
    uri.query = [ uri.query, gallery_params.map { |k, v| "#{k}=#{v}" }.join("&") ].compact.join("&")
    uri.to_s
  end
end


59
60
61
# File 'app/models/marksmith/editor.rb', line 59

def gallery_open_path
  gallery.fetch(:open_path, nil)
end


63
64
65
# File 'app/models/marksmith/editor.rb', line 63

def gallery_params
  gallery.fetch(:params, {})
end


67
68
69
# File 'app/models/marksmith/editor.rb', line 67

def gallery_turbo_frame
  gallery.fetch(:turbo_frame, nil)
end

#preview_pane_idObject



109
110
111
# File 'app/models/marksmith/editor.rb', line 109

def preview_pane_id
  "#{id}-preview-pane"
end

#textarea_idObject



105
106
107
# File 'app/models/marksmith/editor.rb', line 105

def textarea_id
  "#{id}-textarea"
end

#upload_urlObject



79
80
81
82
83
84
85
# File 'app/models/marksmith/editor.rb', line 79

def upload_url
  if @upload_url.present?
    @upload_url
  elsif defined?(ActiveStorage)
    @rails_direct_uploads_url
  end
end

#valueObject



101
102
103
# File 'app/models/marksmith/editor.rb', line 101

def value
  form&.object&.send(name) || @value || nil
end