1
0
mirror of https://github.com/danbee/danbarberphoto synced 2025-03-04 08:49:07 +00:00

Add markdown field

This commit is contained in:
Daniel Barber 2016-04-20 12:13:31 +01:00
parent 824a259d7b
commit df3a5a6613
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
4 changed files with 32 additions and 10 deletions

View File

@ -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,
} }

View File

@ -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

View 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

View File

@ -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>