Class: TDiary::Style::EtdiarySection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, author = nil) ⇒ EtdiarySection

Returns a new instance of EtdiarySection.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/tdiary/style/etdiary.rb', line 12

def initialize( title, author = nil )
	@subtitle = title
	if @subtitle then
		if "" == @subtitle then
			@subtitle = nil
			@anchor_type = :P
		elsif "<>" == @subtitle then
			@subtitle = nil
			@anchor_type = :A
		elsif /^<>/ =~ @subtitle then
			@subtitle = @subtitle[2..-1]
			@anchor_type = :H4
		else
			@anchor_type = :H3
		end
	else
		@subtitle = nil
		@anchor_type = nil
	end
	@bodies = []
	@categories = get_categories
	@stripped_subtitle = strip_subtitle
end

Instance Attribute Details

#anchor_typeObject (readonly)

Returns the value of attribute anchor_type.



6
7
8
# File 'lib/tdiary/style/etdiary.rb', line 6

def anchor_type
  @anchor_type
end

#authorObject (readonly)

Returns the value of attribute author.



6
7
8
# File 'lib/tdiary/style/etdiary.rb', line 6

def author
  @author
end

#bodiesObject (readonly)

Returns the value of attribute bodies.



6
7
8
# File 'lib/tdiary/style/etdiary.rb', line 6

def bodies
  @bodies
end

#categoriesObject

Returns the value of attribute categories.



7
8
9
# File 'lib/tdiary/style/etdiary.rb', line 7

def categories
  @categories
end

#stripped_subtitleObject (readonly) Also known as: stripped_subtitle_to_html

Returns the value of attribute stripped_subtitle.



7
8
9
# File 'lib/tdiary/style/etdiary.rb', line 7

def stripped_subtitle
  @stripped_subtitle
end

#subtitleObject Also known as: subtitle_to_html

Returns the value of attribute subtitle.



6
7
8
# File 'lib/tdiary/style/etdiary.rb', line 6

def subtitle
  @subtitle
end

Instance Method Details

#<<(string) ⇒ Object



107
108
109
# File 'lib/tdiary/style/etdiary.rb', line 107

def << (string)
	@bodies << string
end

#bodyObject



82
83
84
85
86
87
88
# File 'lib/tdiary/style/etdiary.rb', line 82

def body
	if @bodies then
		@bodies.join('')
	else
		''
	end
end

#body=(str) ⇒ Object



64
65
66
# File 'lib/tdiary/style/etdiary.rb', line 64

def body=(str)
	@bodies = str.split(/\n/)
end

#body_to_htmlObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/tdiary/style/etdiary.rb', line 90

def body_to_html
	if @bodies then
		r = ''
		in_p = false
		@bodies.join('').each_line("\n\n") do |p|
			if /\A</ !~ p then
				r << "<p>#{p.chomp}</p>\n"
			else
				r << p
			end
		end
		r
	else
		''
	end
end

#categorized_subtitleObject



141
142
143
144
145
146
147
148
149
150
# File 'lib/tdiary/style/etdiary.rb', line 141

def categorized_subtitle
	return "" unless @subtitle
	cat = /^(\[(.*?)\])+/.match(@subtitle).to_a[0]
	return @stripped_subtitle unless cat
	cat.gsub(/\[(.*?)\]/) do
		$1.split(/,/).collect do |c|
			%Q|<%= category_anchor("#{c}") %>|
		end.join
	end + @stripped_subtitle
end

#get_categoriesObject



132
133
134
135
136
137
138
139
# File 'lib/tdiary/style/etdiary.rb', line 132

def get_categories
	return [] unless @subtitle
	cat = /^(\[(.*?)\])+/.match(@subtitle).to_a[0]
	return [] unless cat
	cat.scan(/\[(.*?)\]/).collect do |c|
		c[0].split(/,/)
	end.flatten
end

#set_body(bodies) ⇒ Object



78
79
80
# File 'lib/tdiary/style/etdiary.rb', line 78

def set_body( bodies )
	@bodies = bodies
end

#strip_subtitleObject



152
153
154
155
# File 'lib/tdiary/style/etdiary.rb', line 152

def strip_subtitle
	return nil unless @subtitle
	@subtitle.sub(/^(\[(.*?)\])+\s*/,'')
end

#to_sObject



128
129
130
# File 'lib/tdiary/style/etdiary.rb', line 128

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

#to_srcObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/tdiary/style/etdiary.rb', line 111

def to_src
	s = ''
	case @anchor_type
	when :A
		s << "<<<>>>\n"
	when :P
		s << "<<>>\n"
	when :H4
		s << "[#{@author}]" if @author
		s << "<<<>" + @subtitle + ">>\n"
	when :H3
		s << "[#{@author}]" if @author
		s << "<<" + @subtitle + ">>\n"
	end
	s + ( if "" != body then body else "\n" end )
end