mirror of
https://github.com/danbee/danbarberphoto
synced 2025-03-04 08:49:07 +00:00
Add markdown field
This commit is contained in:
parent
824a259d7b
commit
df3a5a6613
@ -11,7 +11,7 @@ class PageDashboard < Administrate::BaseDashboard
|
||||
id: Field::Number,
|
||||
name: Field::String,
|
||||
title: Field::String,
|
||||
content: Field::Text,
|
||||
content: Field::MarkdownField,
|
||||
created_at: Field::DateTime,
|
||||
updated_at: Field::DateTime,
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@ class PhotoDashboard < Administrate::BaseDashboard
|
||||
created_at: Field::DateTime,
|
||||
updated_at: Field::DateTime,
|
||||
title: Field::String,
|
||||
description: Field::Text,
|
||||
description: Field::MarkdownField,
|
||||
sort: Field::Number,
|
||||
featured: Field::Boolean,
|
||||
enabled: Field::Boolean,
|
||||
@ -72,10 +72,7 @@ class PhotoDashboard < Administrate::BaseDashboard
|
||||
:categories,
|
||||
]
|
||||
|
||||
# Overwrite this method to customize how photos are displayed
|
||||
# across all pages of the admin dashboard.
|
||||
#
|
||||
# def display_resource(photo)
|
||||
# "Photo ##{photo.id}"
|
||||
# end
|
||||
def display_resource(photo)
|
||||
photo.title
|
||||
end
|
||||
end
|
||||
|
||||
21
app/fields/markdown_field.rb
Normal file
21
app/fields/markdown_field.rb
Normal file
@ -0,0 +1,21 @@
|
||||
require "administrate/field/base"
|
||||
|
||||
class MarkdownField < Administrate::Field::Base
|
||||
def to_s
|
||||
data
|
||||
end
|
||||
|
||||
def rendered
|
||||
Kramdown::Document.new(data).to_html.html_safe
|
||||
end
|
||||
|
||||
def truncate
|
||||
data.to_s[0...truncation_length]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def truncation_length
|
||||
options.fetch(:truncate, 50)
|
||||
end
|
||||
end
|
||||
@ -1,2 +1,6 @@
|
||||
<div class="field-unit__label">
|
||||
<%= f.label field.attribute %>
|
||||
</div>
|
||||
<div class="field-unit__field">
|
||||
<%= f.text_area field.attribute %>
|
||||
</div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user