diff --git a/app/dashboards/page_dashboard.rb b/app/dashboards/page_dashboard.rb index c010d9b..bfff135 100644 --- a/app/dashboards/page_dashboard.rb +++ b/app/dashboards/page_dashboard.rb @@ -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, } diff --git a/app/dashboards/photo_dashboard.rb b/app/dashboards/photo_dashboard.rb index 391867e..6e5b83e 100644 --- a/app/dashboards/photo_dashboard.rb +++ b/app/dashboards/photo_dashboard.rb @@ -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 diff --git a/app/fields/markdown_field.rb b/app/fields/markdown_field.rb new file mode 100644 index 0000000..4118b78 --- /dev/null +++ b/app/fields/markdown_field.rb @@ -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 diff --git a/app/views/fields/markdown_field/_form.html.erb b/app/views/fields/markdown_field/_form.html.erb index 60b9685..f6153c0 100644 --- a/app/views/fields/markdown_field/_form.html.erb +++ b/app/views/fields/markdown_field/_form.html.erb @@ -1,2 +1,6 @@ -<%= f.label field.attribute %> -<%= f.text_area field.attribute %> +