class TDiary::Style::GfmDiary

Public Class Methods

new(date, title, body, modified = Time.now) click to toggle source
# File lib/tdiary/style/gfm.rb, line 178
def initialize(date, title, body, modified = Time.now)
        init_diary
        replace( date, title, body )
        @last_modified = modified
end

Public Instance Methods

add_section(subtitle, body) click to toggle source
# File lib/tdiary/style/gfm.rb, line 216
def add_section(subtitle, body)
        @sections = GfmSection.new("\# #{subtitle}\n\n#{body}")
        @sections.size
end
append(body, author = nil) click to toggle source
# File lib/tdiary/style/gfm.rb, line 188
def append(body, author = nil)
        in_code_block = false
        section = nil
        body.each_line do |l|
                case l
                when /^\#[^\#]/
                        if in_code_block
                                section << l
                        else
                                @sections << GfmSection.new(section, author) if section
                                section = l
                        end
                when /^```/
                        in_code_block = !in_code_block
                        section << l
                else
                        section = '' unless section
                        section << l
                end
        end
        if section
                section << "\n" unless section =~ /\n\n\z/
                @sections << GfmSection.new(section, author)
        end
        @last_modified = Time.now
        self
end
style() click to toggle source
# File lib/tdiary/style/gfm.rb, line 184
def style
        'GFM'
end