class TDiary::Style::OrgSection
Public Class Methods
new(fragment, author = nil)
click to toggle source
# File lib/tdiary/style/org.rb, line 17 def initialize(fragment, author = nil) @author = author @subtitle, @body = fragment.split(/\n/, 2) @body ||= '' @categories = get_categories @stripped_subtitle = strip_subtitle @subtitle_to_html = @subtitle ? to_html('* ' + @subtitle).strip.gsub(/\A<h\d>|<\/h\d>\z/io, '') : nil @stripped_subtitle_to_html = @stripped_subtitle ? to_html(@stripped_subtitle).strip.gsub(/\A<h\d>|<\/h\d>\z/io, '') : nil @body_to_html = to_html(@body) end
Public Instance Methods
categories=(categories)
click to toggle source
# File lib/tdiary/style/org.rb, line 33 def categories=(categories) @subtitle = "#{categories_to_string} " + (strip_subtitle || '') @strip_subtitle = strip_subtitle end
do_html4(date, idx, opt)
click to toggle source
# File lib/tdiary/style/org.rb, line 44 def do_html4(date, idx, opt) subtitle = to_html(@subtitle) subtitle.sub!( %r!<h3>(.+?)</h3>!m ) do "<h3><%= subtitle_proc( Time.at( #{date.to_i} ), #{$1.dump.gsub( /%/, '\\\\045' )} ) %></h3>" end if opt['multi_user'] and @author then subtitle.sub!(/<\/h3>/,%Q|[#{@author}]</h3>|) end r = subtitle r << @body_to_html end
subtitle=(subtitle)
click to toggle source
# File lib/tdiary/style/org.rb, line 28 def subtitle=(subtitle) @subtitle = (subtitle || '').sub(/^# /,"\##{categories_to_string} ") @strip_subtitle = strip_subtitle end
to_src()
click to toggle source
# File lib/tdiary/style/org.rb, line 38 def to_src r = '' r << "#{@subtitle}\n" if @subtitle r << @body.gsub(/\n\n\z/io,"\n") end
Private Instance Methods
get_categories()
click to toggle source
# File lib/tdiary/style/org.rb, line 68 def get_categories return [] unless @subtitle org = Orgmode::Parser.new(@subtitle, {markup_file: File.dirname(__FILE__) + '/org/html_tags.yml', skip_syntax_highlight: false} ) unless org.headlines[0] == nil cat = org.headlines[0].tags.flatten else cat = [] end return cat end
strip_subtitle()
click to toggle source
# File lib/tdiary/style/org.rb, line 79 def strip_subtitle unless @subtitle return nil else return '* ' + Orgmode::Parser.new(@subtitle, {markup_file: File.dirname(__FILE__) + '/org/html_tags.yml'} ).headlines[0].headline_text end end
to_html(string)
click to toggle source
# File lib/tdiary/style/org.rb, line 58 def to_html(string) r = string.dup renderer = Orgmode::Parser.new(string, {markup_file: File.dirname(__FILE__) + '/org/html_tags.yml', skip_syntax_highlight: false } ) r = renderer.to_html # for tDiary plugin r = r.gsub(/\(\(%(.+?)%\)\)/m,'<%=\1%>') r = r.gsub('‘','\'').gsub('’','\'') r = r.gsub('“','"').gsub('”','"') end