Class: Doing::HTMLExport

Inherits:
Object show all
Includes:
Util
Defined in:
lib/doing/plugins/export/html_export.rb

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



29
30
31
32
33
34
35
36
37
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
# File 'lib/doing/plugins/export/html_export.rb', line 29

def self.render(wwid, items, variables: {})
  return if items.nil?

  opt = variables[:options]

  items_out = []
  items.each do |i|
    # if i.has_key?('note')
    #   note = '<span class="note">' + i.note.map{|n| n.strip }.join('<br>') + '</span>'
    # else
    #   note = ''
    # end
    if String.method_defined? :force_encoding
      title = i.title.force_encoding('utf-8').link_urls
      note = i.note.map { |line| line.force_encoding('utf-8').strip.link_urls } if i.note
    else
      title = i.title.link_urls
      note = i.note.map { |line| line.strip.link_urls } if i.note
    end

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

    items_out << {
      date: i.date.strftime('%a %-I:%M%p'),
      title: title.gsub(/(@[^ (]+(\(.*?\))?)/im, '<span class="tag">\1</span>').strip, #+ " #{note}"
      note: note,
      time: interval,
      section: i.section
    }
  end

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

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

  totals = opt[:totals] ? wwid.tag_times(format: :html, sort_by: opt[:sort_tags], sort_order: opt[:tag_order]) : ''
  engine = Haml::Engine.new(template)
  Doing.logger.debug('HTML Export:', "#{items_out.count} items output to HTML")
  @out = engine.render(Object.new,
                     { :@items => items_out, :@page_title => variables[:page_title], :@style => style, :@totals => totals })
end

.settingsObject



11
12
13
14
15
16
17
18
19
# File 'lib/doing/plugins/export/html_export.rb', line 11

def self.settings
  {
    trigger: 'html?|web(?:page)?',
    templates: [
      { name: 'html', trigger: 'h[ta]ml?|web', format: 'haml', filename: 'html_export.haml' },
      { name: 'html_style', trigger: 'css|styl(?:e|us)', format: 'css', filename: 'html_export.css' }
    ]
  }
end

.template(trigger) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/doing/plugins/export/html_export.rb', line 21

def self.template(trigger)
  if trigger =~ /^(css|sty)/
    IO.read(File.join(File.dirname(__FILE__), '../../../templates/doing.css'))
  else
    IO.read(File.join(File.dirname(__FILE__), '../../../templates/doing.haml'))
  end
end