Class: Doing::MarkdownExport
- Inherits:
-
Object
show all
- Includes:
- Util
- Defined in:
- lib/doing/plugins/export/markdown_export.rb
Overview
Class Method Summary
collapse
Methods included from Util
args_for_editor, deep_merge_hashes, deep_merge_hashes!, default_editor, duplicable?, duplicate_frozen_values, editor_with_args, exec_available, find_default_editor, first_available_exec, mergable?, merge_default_proc, merge_values, safe_load_file, user_home, write_to_file
Class Method Details
.render(wwid, items, variables: {}) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/doing/plugins/export/markdown_export.rb', line 38
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]
if i.title =~ /@done\((\d{4}-\d\d-\d\d \d\d:\d\d.*?)\)/ && opt[:times]
interval = wwid.get_interval(i,
record: true)
end
interval ||= false
finished = i.title =~ /(?<= |^)@done/ ? true : false
done = finished ? 'x' : ' '
all_items << {
date: i.date.strftime('%a %-I:%M%p'),
shortdate: i.date.relative_date,
flagged: i.title =~ /(?<= |^)@#{Doing.setting('marker_tag')}/,
done: done,
finished: finished,
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 = if opt[:totals]
wwid.tag_times(format: :markdown, sort_by: opt[:sort_tags],
sort_order: opt[:tag_order])
else
''
end
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
|
27
28
29
30
31
32
|
# File 'lib/doing/plugins/export/markdown_export.rb', line 27
def self.settings
{
trigger: 'markdown|mk?d|gfm',
templates: [{ name: 'markdown', trigger: 'mk?d|markdown', format: 'erb', filename: 'doing-markdown.erb' }]
}
end
|
.template(_trigger) ⇒ Object
34
35
36
|
# File 'lib/doing/plugins/export/markdown_export.rb', line 34
def self.template(_trigger)
IO.read(File.join(File.dirname(__FILE__), '../../../templates/doing-markdown.erb'))
end
|