Class: TDiary::Style::RDSection

Inherits:
Object
  • Object
show all
Includes:
RD
Defined in:
lib/tdiary/style/rd.rb

Constant Summary

Constants included from RD

RD::TDIARY_BASE_LEVEL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fragment, author = nil) ⇒ RDSection

Returns a new instance of RDSection.



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/tdiary/style/rd.rb', line 197

def initialize( fragment, author = nil )
	@author = author
	if /\A=(?!=)/ =~ fragment then
		@subtitle, @body = fragment.split( /\n/, 2 )
		@subtitle.sub!( /^\=\s*/, '' )
	else
		@subtitle = nil
		@body = fragment.dup
	end
	@body = @body || ''
	@body.sub!( /[\n\r]+\Z/, '' )
	@body << "\n\n"

	@categories = get_categories
	@stripped_subtitle = strip_subtitle

	@subtitle_to_html = manufacture(@subtitle, true)
	@stripped_subtitle_to_html = manufacture(@stripped_subtitle, true)
	@body_to_html = manufacture(@body, false)
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



194
195
196
# File 'lib/tdiary/style/rd.rb', line 194

def author
  @author
end

#body_to_htmlObject (readonly)

Returns the value of attribute body_to_html.



195
196
197
# File 'lib/tdiary/style/rd.rb', line 195

def body_to_html
  @body_to_html
end

#categoriesObject

Returns the value of attribute categories.



194
195
196
# File 'lib/tdiary/style/rd.rb', line 194

def categories
  @categories
end

#stripped_subtitleObject (readonly)

Returns the value of attribute stripped_subtitle.



194
195
196
# File 'lib/tdiary/style/rd.rb', line 194

def stripped_subtitle
  @stripped_subtitle
end

#stripped_subtitle_to_htmlObject (readonly)

Returns the value of attribute stripped_subtitle_to_html.



195
196
197
# File 'lib/tdiary/style/rd.rb', line 195

def stripped_subtitle_to_html
  @stripped_subtitle_to_html
end

#subtitleObject

Returns the value of attribute subtitle.



194
195
196
# File 'lib/tdiary/style/rd.rb', line 194

def subtitle
  @subtitle
end

#subtitle_to_htmlObject (readonly)

Returns the value of attribute subtitle_to_html.



195
196
197
# File 'lib/tdiary/style/rd.rb', line 195

def subtitle_to_html
  @subtitle_to_html
end

Instance Method Details

#bodyObject



232
233
234
# File 'lib/tdiary/style/rd.rb', line 232

def body
	@body.dup
end

#body=(str) ⇒ Object



228
229
230
# File 'lib/tdiary/style/rd.rb', line 228

def body=(str)
	@body = str
end

#html(date, idx, opt, mode = :HTML) ⇒ Object



253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/tdiary/style/rd.rb', line 253

def html( date, idx, opt, mode = :HTML)
	if mode == :CHTML
		visitor = RD2tDiaryCHTMLVistor.new( date, idx, opt, @author)
		section_open = "<%=section_enter_proc( Time::at( #{date.to_i} ))%>\n"
		section_close = "<%=section_leave_proc( Time::at( #{date.to_i} ))%>\n"
	else
		visitor = RD2tDiaryVisitor.new( date, idx, opt, @author )
		section_open = %Q[<div class="section">\n<%=section_enter_proc( Time::at( #{date.to_i} ))%>\n]
		section_close = "<%=section_leave_proc( Time::at( #{date.to_i} ))%>\n</div>\n"
	end

	src = to_src.split(/^/)
	src.unshift("=begin\n").push("=end\n")
	tree = RDTree.new( src, nil, nil)
	begin
		tree.parse
	rescue ParseError
		raise SyntaxError, $!.message
	end

	r = "#{section_open}#{visitor.visit( tree )}#{section_close}"
end

#to_srcObject



247
248
249
250
251
# File 'lib/tdiary/style/rd.rb', line 247

def to_src
	r = ''
	r << "= #{@subtitle}\n" if @subtitle
	r << @body
end