class Doing::MarkdownExport

Public Class Methods

render(wwid, items, variables: {}) click to toggle source
# File lib/doing/plugins/export/markdown_export.rb, line 36
def self.render(wwid, items, variables: {})
  return if items.nil?

  opt = variables[:options]

  all_items = []
  items.each do |i|
    if String.method_defined? :force_encoding
      title = i.title.force_encoding('utf-8').link_urls(format: :markdown)
      note = i.note.map { |line| line.force_encoding('utf-8').strip.link_urls(format: :markdown) } if i.note
    else
      title = i.title.link_urls(format: :markdown)
      note = i.note.map { |line| line.strip.link_urls(format: :markdown) } if i.note
    end

    title = "#{title} @section(#{i.section})" unless variables[:is_single]

    interval = wwid.get_interval(i, record: true) if i.title =~ /@done\((\d{4}-\d\d-\d\d \d\d:\d\d.*?)\)/ && opt[:times]
    interval ||= false

    done = i.title =~ /(?<= |^)@done/ ? 'x' : ' '

    all_items << {
      date: i.date.strftime('%a %-I:%M%p'),
      shortdate: i.date.relative_date,
      done: done,
      note: note,
      section: i.section,
      time: interval,
      title: title.strip
    }
  end

  template = if Doing.setting('export_templates.markdown') && File.exist?(File.expand_path(Doing.setting('export_templates.markdown')))
               IO.read(File.expand_path(Doing.setting('export_templates.markdown')))
             else
               self.template(nil)
             end

  totals = opt[:totals] ? wwid.tag_times(format: :markdown, sort_by: opt[:sort_tags], sort_order: opt[:tag_order]) : ''

  mdx = MarkdownRenderer.new(variables[:page_title], all_items, totals)
  Doing.logger.debug('Markdown Export:', "#{all_items.count} items output to Markdown")
  engine = ERB.new(template)
  @out = engine.result(mdx.get_binding)
end
settings() click to toggle source
# File lib/doing/plugins/export/markdown_export.rb, line 25
def self.settings
  {
    trigger: 'markdown|mk?d|gfm',
    templates: [{ name: 'markdown', trigger: 'mk?d|markdown', format: 'erb', filename: 'doing-markdown.erb' }]
  }
end
template(_trigger) click to toggle source
# File lib/doing/plugins/export/markdown_export.rb, line 32
def self.template(_trigger)
  IO.read(File.join(File.dirname(__FILE__), '../../../templates/doing-markdown.erb'))
end