Module: TDiary::Style::BaseDiary

Includes:
ERB::Util, CommentManager, RefererManager
Defined in:
lib/tdiary/style.rb

Instance Method Summary collapse

Methods included from RefererManager

#add_referer, #clear_referers, #count_referers, #each_referer

Methods included from CommentManager

#add_comment, #count_comments, #each_comment, #each_comment_tail, #each_visible_comment, #each_visible_trackback, #each_visible_trackback_tail

Instance Method Details

#dateObject



58
59
60
# File 'lib/tdiary/style.rb', line 58

def date
	@date
end

#delete_section(index) ⇒ Object



119
120
121
# File 'lib/tdiary/style.rb', line 119

def delete_section(index)
	@sections.delete_at(index - 1)
end

#each_sectionObject



113
114
115
116
117
# File 'lib/tdiary/style.rb', line 113

def each_section
	@sections.each do |section|
		yield section
	end
end

#eval_rhtml(opt, path = "#{File.dirname(__FILE__)}/../..") ⇒ Object



123
124
125
# File 'lib/tdiary/style.rb', line 123

def eval_rhtml( opt, path = "#{File.dirname(__FILE__)}/../.." )
	ERB.new(File.read("#{path}/views/#{opt['prefix']}diary.rhtml")).result(binding)
end

#init_diaryObject



52
53
54
55
56
# File 'lib/tdiary/style.rb', line 52

def init_diary
	init_comments
	init_referers
	@show = true
end

#last_modifiedObject



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

def last_modified
	# 日本語を含むツッコミを入れると diary.last_modified が String になる (原因不明)
	# (PStore 保存前は Time だが, 保存後に String となる)
	# 暫定的に String だったら Time へ変換する
	if @last_modified.instance_of? String
		@last_modified = Time.at(0)
	elsif @last_modified
		@last_modified
	else
		Time::at( 0 )
	end
end

#last_modified=(lm) ⇒ Object



94
95
96
# File 'lib/tdiary/style.rb', line 94

def last_modified=( lm )
	@last_modified  = lm
end

#replace(date, title, body) ⇒ Object



106
107
108
109
110
111
# File 'lib/tdiary/style.rb', line 106

def replace(date, title, body)
	set_date( date )
	set_title( title )
	@sections = []
	append( body )
end

#set_date(date) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/tdiary/style.rb', line 62

def set_date( date )
	if date.class == String then
		y, m, d = date.scan( /^(\d{4})(\d\d)(\d\d)$/ )[0]
		raise ArgumentError::new( 'date string needs YYYYMMDD format.' ) unless y
		@date = Time::local( y, m, d )
	else
		@date = date
	end
end

#set_title(title) ⇒ Object



76
77
78
79
# File 'lib/tdiary/style.rb', line 76

def set_title( title )
	@title = title
	@last_modified = Time::now
end

#show(s) ⇒ Object



102
103
104
# File 'lib/tdiary/style.rb', line 102

def show( s )
	@show = s
end

#titleObject



72
73
74
# File 'lib/tdiary/style.rb', line 72

def title
	@title || ''
end

#to_chtml(opt) ⇒ Object



154
155
156
157
158
159
160
161
162
# File 'lib/tdiary/style.rb', line 154

def to_chtml( opt )
	r = ''
	idx = 1
	each_section do |section|
		r << section.chtml( date, idx, opt )
		idx += 1
	end
	r
end

#to_html(opt = {}, mode = :HTML) ⇒ Object



135
136
137
138
139
140
141
142
# File 'lib/tdiary/style.rb', line 135

def to_html( opt = {}, mode = :HTML )
	case mode
	when :CHTML
		to_chtml( opt )
	else
		to_html4( opt )
	end
end

#to_html4(opt) ⇒ Object



144
145
146
147
148
149
150
151
152
# File 'lib/tdiary/style.rb', line 144

def to_html4(opt)
	r = ''
	idx = 1
	each_section do |section|
		r << section.html4( date, idx, opt )
		idx += 1
	end
	r
end

#to_sObject



164
165
166
# File 'lib/tdiary/style.rb', line 164

def to_s
	"date=#{date.strftime('%Y%m%d')}, title=#{title}, body=[#{@sections.join('][')}]"
end

#to_srcObject



127
128
129
130
131
132
133
# File 'lib/tdiary/style.rb', line 127

def to_src
	r = ''
	each_section do |section|
		r << section.to_src
	end
	r
end

#visible?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/tdiary/style.rb', line 98

def visible?
	@show != false;
end