Skip to content

Commit

Permalink
Add rich text field
Browse files Browse the repository at this point in the history
  • Loading branch information
excid3 committed Mar 4, 2024
1 parent ef149e1 commit a345248
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
22 changes: 22 additions & 0 deletions app/views/fields/rich_text/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%#
# Text Form Partial
This partial renders a textarea element for a text attribute.
## Local variables:
- `f`:
A Rails form generator, used to help create the appropriate input fields.
- `field`:
An instance of [Administrate::Field::Text][1].
A wrapper around the Text pulled from the database.
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Text
%>

<div class="field-unit__label">
<%= f.label field.attribute %>
</div>
<div class="field-unit__field">
<%= f.rich_text_area field.attribute, data: { controller: "mentions", target: "mentions.field" } %>
</div>
18 changes: 18 additions & 0 deletions app/views/fields/rich_text/_index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<%#
# Text Index Partial
This partial renders a text attribute
to be displayed on a resource's index page.
By default, the attribute is rendered as a truncated string.
## Local variables:
- `field`:
An instance of [Administrate::Field::Text][1].
A wrapper around the Text pulled from the database.
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Text
%>

<%= field.truncate %>
18 changes: 18 additions & 0 deletions app/views/fields/rich_text/_show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<%#
# Text Show Partial
This partial renders a text attribute,
to be displayed on a resource's show page.
By default, the attribute is rendered as text with whitespace preserved.
## Local variables:
- `field`:
An instance of [Administrate::Field::Text][1].
A wrapper around the Text pulled from the database.
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Text
%>

<div class="preserve-whitespace"><%= field.data %></div>
11 changes: 11 additions & 0 deletions lib/administrate/field/rich_text.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require "administrate/field/text"

module Administrate
module Field
class RichText < Administrate::Field::Text
def to_s
data
end
end
end
end

0 comments on commit a345248

Please sign in to comment.