class Decidim::Proposals::OdtToMarkdown
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.
Public Class Methods
new(doc)
click to toggle source
Public: Initializes the serializer with a proposal.
# File lib/decidim/proposals/odt_to_markdown.rb, line 17 def initialize(doc) @doc = doc end
Public Instance Methods
to_md()
click to toggle source
# File lib/decidim/proposals/odt_to_markdown.rb, line 21 def to_md doc_file = doc_to_tmp_file md_file = transform_to_md_file(doc_file) md_file.read end
Private Instance Methods
doc_to_tmp_file()
click to toggle source
# File lib/decidim/proposals/odt_to_markdown.rb, line 33 def doc_to_tmp_file file = Tempfile.new("doc-to-markdown-odt", encoding: "ascii-8bit") file.write(@doc) file end
transform_to_md_file(doc_file)
click to toggle source
# File lib/decidim/proposals/odt_to_markdown.rb, line 39 def transform_to_md_file(doc_file) md_file = Tempfile.new Doc2Text::Odt::Document.parse_and_save doc_file, md_file md_file end