Class: TDiary::Style::GfmDiary
- Inherits:
-
Object
- Object
- TDiary::Style::GfmDiary
- Defined in:
- lib/tdiary/style/gfm.rb
Instance Method Summary collapse
- #add_section(subtitle, body) ⇒ Object
- #append(body, author = nil) ⇒ Object
-
#initialize(date, title, body, modified = Time.now) ⇒ GfmDiary
constructor
A new instance of GfmDiary.
- #style ⇒ Object
Constructor Details
#initialize(date, title, body, modified = Time.now) ⇒ GfmDiary
Returns a new instance of GfmDiary.
188 189 190 191 192 |
# File 'lib/tdiary/style/gfm.rb', line 188 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
226 227 228 229 |
# File 'lib/tdiary/style/gfm.rb', line 226 def add_section(subtitle, body) @sections = GfmSection.new("\# #{subtitle}\n\n#{body}") @sections.size end |
#append(body, author = nil) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/tdiary/style/gfm.rb', line 198 def append(body, = 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, ) 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, ) end @last_modified = Time.now self end |
#style ⇒ Object
194 195 196 |
# File 'lib/tdiary/style/gfm.rb', line 194 def style 'GFM' end |