Class: Decidim::Proposals::DocToMarkdown
- Inherits:
-
Object
- Object
- Decidim::Proposals::DocToMarkdown
- Defined in:
- lib/decidim/proposals/doc_to_markdown.rb
Overview
This class parses a participatory text document in markdown and produces Proposals in the form of sections and articles.
This implementation uses Redcarpet Base renderer. Redcarpet::Render::Base performs a callback for every block it finds, what MarkdownToProposals does is to implement callbacks for the blocks which it is interested in performing some actions.
Constant Summary collapse
- MARKDOWN_MIME_TYPE =
"text/markdown"
- TEXT_PLAIN_MIME_TYPE =
sometimes markdown documents are classified as text/plain
"text/plain"
- ODT_MIME_TYPE =
"application/vnd.oasis.opendocument.text"
- ACCEPTED_MIME_TYPES =
Accepted mime types keys: are used for dynamic help text on admin form. values: are used to validate the file format of imported document.
{ md: MARKDOWN_MIME_TYPE, odt: ODT_MIME_TYPE }.freeze
Instance Method Summary collapse
-
#initialize(doc, mime_type) ⇒ DocToMarkdown
constructor
Public: Initializes the serializer with a proposal.
- #to_md ⇒ Object
Constructor Details
#initialize(doc, mime_type) ⇒ DocToMarkdown
Public: Initializes the serializer with a proposal.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/decidim/proposals/doc_to_markdown.rb', line 30 def initialize(doc, mime_type) @doc = doc @transformer = case mime_type # when MARKDOWN_MIME_TYPE # no transformer required when ODT_MIME_TYPE # convert libreoffice odt to markdown OdtToMarkdown.new(doc) end end |
Instance Method Details
#to_md ⇒ Object
41 42 43 |
# File 'lib/decidim/proposals/doc_to_markdown.rb', line 41 def to_md @transformer ? @transformer.to_md : @doc end |