Class: TDiary::Style::TdiarySection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fragment, author = nil) ⇒ TdiarySection

Returns a new instance of TdiarySection.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/tdiary/style/tdiary.rb', line 20

def initialize( fragment, author = nil )
	@author = author
	lines = fragment.split( /\n+/ )
	if lines.size > 1 then
		if /^<</ =~ lines[0]
			@subtitle = lines.shift.chomp.sub( /^</, '' )
		elsif /^[  <]/u !~ lines[0]
			@subtitle = lines.shift.chomp
		end
	end
	@body = lines.join( "\n" )

	@categories = get_categories
	@stripped_subtitle = strip_subtitle
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



14
15
16
# File 'lib/tdiary/style/tdiary.rb', line 14

def author
  @author
end

#bodyObject

Returns the value of attribute body.



14
15
16
# File 'lib/tdiary/style/tdiary.rb', line 14

def body
  @body
end

#categoriesObject

Returns the value of attribute categories.



15
16
17
# File 'lib/tdiary/style/tdiary.rb', line 15

def categories
  @categories
end

#stripped_subtitleObject (readonly) Also known as: stripped_subtitle_to_html

Returns the value of attribute stripped_subtitle.



15
16
17
# File 'lib/tdiary/style/tdiary.rb', line 15

def stripped_subtitle
  @stripped_subtitle
end

#subtitleObject Also known as: subtitle_to_html

Returns the value of attribute subtitle.



14
15
16
# File 'lib/tdiary/style/tdiary.rb', line 14

def subtitle
  @subtitle
end

Instance Method Details

#body_to_htmlObject



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/tdiary/style/tdiary.rb', line 79

def body_to_html
	html = ""
	@body.lines.each do |p|
		if p[0] == ?< then
			html = @body.dup
			break
		end
		html << "<p>#{p}</p>"
	end
	html
end

#categorized_subtitleObject



95
96
97
98
99
# File 'lib/tdiary/style/tdiary.rb', line 95

def categorized_subtitle
	@categories.collect do |c|
		%Q|<%= category_anchor("#{c}") %>|
	end.join + @stripped_subtitle.to_s
end

#to_sObject



91
92
93
# File 'lib/tdiary/style/tdiary.rb', line 91

def to_s
	"subtitle=#{@subtitle}, body=#{@body}"
end

#to_srcObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/tdiary/style/tdiary.rb', line 61

def to_src
	s = ''
	if @stripped_subtitle then
		s += "[#{@author}]" if @author
		cat_str = ""
		@categories.each {|cat|
			cat_str << "[#{cat}]"
		}
		cat_str << " " unless cat_str.empty?
		s += cat_str
		s += '<' if /^</=~@subtitle
		s += @stripped_subtitle + "\n"
	else
		#s += ' ' unless @body =~ /\A\s</
	end
	"#{s}#{@body}\n\n"
end