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,
|
id: Field::Number,
|
||||||
name: Field::String,
|
name: Field::String,
|
||||||
title: Field::String,
|
title: Field::String,
|
||||||
content: Field::Text,
|
content: Field::MarkdownField,
|
||||||
created_at: Field::DateTime,
|
created_at: Field::DateTime,
|
||||||
updated_at: Field::DateTime,
|
updated_at: Field::DateTime,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,7 +14,7 @@ class PhotoDashboard < Administrate::BaseDashboard
|
|||||||
created_at: Field::DateTime,
|
created_at: Field::DateTime,
|
||||||
updated_at: Field::DateTime,
|
updated_at: Field::DateTime,
|
||||||
title: Field::String,
|
title: Field::String,
|
||||||
description: Field::Text,
|
description: Field::MarkdownField,
|
||||||
sort: Field::Number,
|
sort: Field::Number,
|
||||||
featured: Field::Boolean,
|
featured: Field::Boolean,
|
||||||
enabled: Field::Boolean,
|
enabled: Field::Boolean,
|
||||||
@ -72,10 +72,7 @@ class PhotoDashboard < Administrate::BaseDashboard
|
|||||||
:categories,
|
:categories,
|
||||||
]
|
]
|
||||||
|
|
||||||
# Overwrite this method to customize how photos are displayed
|
def display_resource(photo)
|
||||||
# across all pages of the admin dashboard.
|
photo.title
|
||||||
#
|
end
|
||||||
# def display_resource(photo)
|
|
||||||
# "Photo ##{photo.id}"
|
|
||||||
# end
|
|
||||||
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 @@
|
|||||||
<%= f.label field.attribute %>
|
<div class="field-unit__label">
|
||||||
<%= f.text_area field.attribute %>
|
<%= f.label field.attribute %>
|
||||||
|
</div>
|
||||||
|
<div class="field-unit__field">
|
||||||
|
<%= f.text_area field.attribute %>
|
||||||
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user