Class: TDiary::Style::MarkdownDiary
- Inherits:
-
Object
- Object
- TDiary::Style::MarkdownDiary
- Defined in:
- lib/tdiary/style/markdown.rb
Instance Method Summary collapse
- #add_section(subtitle, body) ⇒ Object
- #append(body, author = nil) ⇒ Object
-
#initialize(date, title, body, modified = Time.now) ⇒ MarkdownDiary
constructor
A new instance of MarkdownDiary.
- #style ⇒ Object
Constructor Details
#initialize(date, title, body, modified = Time.now) ⇒ MarkdownDiary
Returns a new instance of MarkdownDiary.
158 159 160 161 162 |
# File 'lib/tdiary/style/markdown.rb', line 158 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
196 197 198 199 |
# File 'lib/tdiary/style/markdown.rb', line 196 def add_section(subtitle, body) @sections = MarkdownSection.new("\# #{subtitle}\n\n#{body}") @sections.size end |
#append(body, author = nil) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/tdiary/style/markdown.rb', line 168 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 << MarkdownSection.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 << MarkdownSection.new(section, ) end @last_modified = Time.now self end |
#style ⇒ Object
164 165 166 |
# File 'lib/tdiary/style/markdown.rb', line 164 def style 'Markdown' end |