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



60
61
62
# File 'lib/tdiary/style.rb', line 60

def date
	@date
end

#delete_section(index) ⇒ Object



121
122
123
# File 'lib/tdiary/style.rb', line 121

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

#each_sectionObject



115
116
117
118
119
# File 'lib/tdiary/style.rb', line 115

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

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



125
126
127
# File 'lib/tdiary/style.rb', line 125

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

#init_diaryObject



54
55
56
57
58
# File 'lib/tdiary/style.rb', line 54

def init_diary
	init_comments
	init_referers
	@show = true
end

#last_modifiedObject



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

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



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

def last_modified=( lm )
	@last_modified  = lm
end

#replace(date, title, body) ⇒ Object



108
109
110
111
112
113
# File 'lib/tdiary/style.rb', line 108

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

#set_date(date) ⇒ Object



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

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



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

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

#show(s) ⇒ Object



104
105
106
# File 'lib/tdiary/style.rb', line 104

def show( s )
	@show = s
end

#titleObject



74
75
76
# File 'lib/tdiary/style.rb', line 74

def title
	@title || ''
end

#to_chtml(opt) ⇒ Object



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

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



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

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

#to_html4(opt) ⇒ Object



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

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

#to_sObject



166
167
168
# File 'lib/tdiary/style.rb', line 166

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

#to_srcObject



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

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

#visible?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/tdiary/style.rb', line 100

def visible?
	@show != false;
end