Class: TDiary::Style::GfmDiary

Inherits:
Object
  • Object
show all
Defined in:
lib/tdiary/style/gfm.rb

Instance Method Summary collapse

Constructor Details

#initialize(date, title, body, modified = Time.now) ⇒ GfmDiary

Returns a new instance of GfmDiary.



218
219
220
221
222
# File 'lib/tdiary/style/gfm.rb', line 218

def initialize(date, title, body, modified = Time.now)
  init_diary
  replace( date, title, body )
  @last_modified = modified
end

Instance Method Details

#add_section(subtitle, body) ⇒ Object



256
257
258
259
# File 'lib/tdiary/style/gfm.rb', line 256

def add_section(subtitle, body)
  @sections = GfmSection.new("\# #{subtitle}\n\n#{body}")
  @sections.size
end

#append(body, author = nil) ⇒ Object



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/tdiary/style/gfm.rb', line 228

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

#styleObject



224
225
226
# File 'lib/tdiary/style/gfm.rb', line 224

def style
  'GFM'
end