Class: TDiary::Style::MarkdownDiary

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of MarkdownDiary.



149
150
151
152
153
# File 'lib/tdiary/style/markdown.rb', line 149

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



187
188
189
190
# File 'lib/tdiary/style/markdown.rb', line 187

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

#append(body, author = nil) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/tdiary/style/markdown.rb', line 159

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 << MarkdownSection.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 << MarkdownSection.new(section, author)
	end
	@last_modified = Time.now
	self
end

#styleObject



155
156
157
# File 'lib/tdiary/style/markdown.rb', line 155

def style
	'Markdown'
end