Class: Marksmith::Editor
- Inherits:
-
Object
- Object
- Marksmith::Editor
- Defined in:
- app/models/marksmith/editor.rb
Instance Attribute Summary collapse
-
#autofocus ⇒ Object
readonly
Returns the value of attribute autofocus.
-
#classes ⇒ Object
readonly
Returns the value of attribute classes.
-
#controller_data_attributes ⇒ Object
readonly
Returns the value of attribute controller_data_attributes.
-
#data_attributes ⇒ Object
readonly
Returns the value of attribute data_attributes.
-
#disabled ⇒ Object
readonly
Returns the value of attribute disabled.
-
#extra_preview_params ⇒ Object
readonly
Returns the value of attribute extra_preview_params.
-
#form ⇒ Object
readonly
Returns the value of attribute form.
-
#gallery ⇒ Object
readonly
Returns the value of attribute gallery.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#kwargs ⇒ Object
readonly
Returns the value of attribute kwargs.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#placeholder ⇒ Object
readonly
Returns the value of attribute placeholder.
-
#style ⇒ Object
readonly
Returns the value of attribute style.
Instance Method Summary collapse
- #enable_file_uploads ⇒ Object
- #field_name ⇒ Object
- #gallery_enabled ⇒ Object
- #gallery_full_path ⇒ Object
- #gallery_open_path ⇒ Object
- #gallery_params ⇒ Object
- #gallery_turbo_frame ⇒ Object
-
#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
constructor
A new instance of Editor.
- #preview_pane_id ⇒ Object
- #textarea_id ⇒ Object
- #upload_url ⇒ Object
- #value ⇒ Object
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
#autofocus ⇒ Object (readonly)
Returns the value of attribute autofocus.
4 5 6 |
# File 'app/models/marksmith/editor.rb', line 4 def autofocus @autofocus end |
#classes ⇒ Object (readonly)
Returns the value of attribute classes.
4 5 6 |
# File 'app/models/marksmith/editor.rb', line 4 def classes @classes end |
#controller_data_attributes ⇒ Object (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_attributes ⇒ Object (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 |
#disabled ⇒ Object (readonly)
Returns the value of attribute disabled.
4 5 6 |
# File 'app/models/marksmith/editor.rb', line 4 def disabled @disabled end |
#extra_preview_params ⇒ Object (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 |
#form ⇒ Object (readonly)
Returns the value of attribute form.
4 5 6 |
# File 'app/models/marksmith/editor.rb', line 4 def form @form end |
#gallery ⇒ Object (readonly)
Returns the value of attribute gallery.
4 5 6 |
# File 'app/models/marksmith/editor.rb', line 4 def gallery @gallery end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'app/models/marksmith/editor.rb', line 4 def id @id end |
#kwargs ⇒ Object (readonly)
Returns the value of attribute kwargs.
4 5 6 |
# File 'app/models/marksmith/editor.rb', line 4 def kwargs @kwargs end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'app/models/marksmith/editor.rb', line 4 def name @name end |
#placeholder ⇒ Object (readonly)
Returns the value of attribute placeholder.
4 5 6 |
# File 'app/models/marksmith/editor.rb', line 4 def placeholder @placeholder end |
#style ⇒ Object (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_uploads ⇒ Object
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_name ⇒ Object
97 98 99 |
# File 'app/models/marksmith/editor.rb', line 97 def field_name form&.field_name(name) || name end |
#gallery_enabled ⇒ Object
55 56 57 |
# File 'app/models/marksmith/editor.rb', line 55 def gallery_enabled gallery.fetch(:enabled, false) end |
#gallery_full_path ⇒ Object
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 |
#gallery_open_path ⇒ Object
59 60 61 |
# File 'app/models/marksmith/editor.rb', line 59 def gallery_open_path gallery.fetch(:open_path, nil) end |
#gallery_params ⇒ Object
63 64 65 |
# File 'app/models/marksmith/editor.rb', line 63 def gallery_params gallery.fetch(:params, {}) end |
#gallery_turbo_frame ⇒ Object
67 68 69 |
# File 'app/models/marksmith/editor.rb', line 67 def gallery_turbo_frame gallery.fetch(:turbo_frame, nil) end |
#preview_pane_id ⇒ Object
109 110 111 |
# File 'app/models/marksmith/editor.rb', line 109 def preview_pane_id "#{id}-preview-pane" end |
#textarea_id ⇒ Object
105 106 107 |
# File 'app/models/marksmith/editor.rb', line 105 def textarea_id "#{id}-textarea" end |
#upload_url ⇒ Object
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 |
#value ⇒ Object
101 102 103 |
# File 'app/models/marksmith/editor.rb', line 101 def value form&.object&.send(name) || @value || nil end |