Files
nairobi/app/models/legislation/draft_version.rb
Karim Semmoud 3faaa8521d Render markdown tables in legislation draft
* Add Tables option to Redcarpet in Legislation draft

* Allow table tags in Admin Legislation Sanitizer

* Add Test to render markdown tables in Legislation drafts

* Add Test for Admin Legislation Sanitizer

We include test for image, table and h1 to h6 tags and additional tests to strengthen the allowed and disallowed parameters

* Add Table from markdown test in System and Factories

* Add test to render  tables for admin user

* Remove comment line about Redcarpet options

* Edit custom css for legislation draft table to make it responsive
2023-06-29 20:48:01 +02:00

54 lines
1.4 KiB
Ruby

class Legislation::DraftVersion < ApplicationRecord
VALID_STATUSES = %w[draft published].freeze
acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases
translates :title, touch: true
translates :changelog, touch: true
translates :body, touch: true
include Globalizable
belongs_to :process, foreign_key: "legislation_process_id", inverse_of: :draft_versions
has_many :annotations,
foreign_key: "legislation_draft_version_id",
inverse_of: :draft_version,
dependent: :destroy
validates_translation :title, presence: true
validates_translation :body, presence: true
validates :status, presence: true, inclusion: { in: ->(*) { VALID_STATUSES }}
scope :published, -> { where(status: "published").order("id DESC") }
def body_html
render_options = {
with_toc_data: true
}
renderer = Redcarpet::Render::HTML.new(render_options)
extensions = {
tables: true
}
Redcarpet::Markdown.new(renderer, extensions).render(body)
end
def toc_html
renderer = Redcarpet::Render::HTML_TOC.new(with_toc_data: true)
Redcarpet::Markdown.new(renderer).render(body)
end
def display_title
status == "draft" ? "#{title} *" : title
end
def total_comments
annotations.sum(:comments_count)
end
def best_comments
Comment.where(commentable: annotations, ancestry: nil).sort_by_supports.limit(10)
end
end