tdiary 4.0.1.20130903 → 4.0.1.20130929

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,83 +0,0 @@
1
- =begin
2
- = etDiaryスタイル
3
-
4
- == etDiaryスタイルとは
5
- ((<tDiary|URL:http://www.tdiary.org/>)) の変種である((<etDiary|URL:http://www.enbug.org/etdiary.html>)) の書式をtDiary本体で利用するためのスタイルです.
6
-
7
- 基本的にはtDiaryスタイルと同じくHTMLをベースとした書式ですが, HTMLタグを意識せずとも
8
- だいたい見た目の通りになる
9
- という違いがあります.
10
-
11
- == 使用準備
12
- このスタイルを使うには,
13
-
14
- (1) etdiary_style.rb ファイルを、tdiary/ ディレクトリにコピーしてくだ
15
- さい。tdiary/ ディレクトリは、tdiary.rb ファイルのあるトップディレク
16
- トリの下にあります。
17
- (2) tdiary.confに以下の行を書いてください。
18
- @style = 'etdiary'
19
-
20
- 正しく設定されると, 更新フォームに
21
- 本文(etdiaryスタイル):
22
- と表示されます.
23
-
24
- == etDiaryスタイルの使い方
25
- etDiaryスタイルは, 行という単位はあまり意味がありません. つまり, 任意の個所に改行が入れられます. 空行(連続した改行)が段落の境界になります. たとえば
26
-
27
- ほげほげ
28
- ふがふが
29
-
30
- ふがほげ
31
- ほげら
32
-
33
- は,
34
-
35
- <p>
36
- ほげほげ
37
- ふがふが
38
- </p>
39
-
40
- <p>
41
- ふがほげ
42
- ほげら
43
- </p>
44
-
45
- と変換されます.
46
-
47
- サブタイトルは明示的に「<<」と「>>」で囲みます. たとえば
48
-
49
- <<サブタイトル>>
50
- 本文
51
-
52
- は,
53
-
54
- <h3>サブタイトル</h3>
55
- <p>
56
- 本文
57
- </p>
58
-
59
- と変換されます.
60
-
61
- == 書式のルール
62
-
63
- * サブタイトルは「<<」と「>>」で囲む.
64
- * <h3>ではなく<h4>で囲みたいときは「<<<>」と「>>」で囲む.
65
- * サブタイトルの中身がない場合, つまり, 「<<>>」と書かれた場合, サブタイトルなしで新しいセクションを開始する.
66
- * 「<<<>>>」と書かれた場合もサブタイトルなしで新しいセクションを開始する. ただし, アンカーリンクは生成しない.
67
- * 二つ以上の改行は段落の区切りとなる.
68
- * 段落の初めが「<」の場合, その段落は整形対象外となる. 終了タグがその段落内に含まれない場合, 終了タグが存在する段落まで, 空行を残したまま処理される. これが嫌なら, スペースを先頭に入れると良い.
69
- * 一般的なHTML同様, "<", ">", "&" はそれぞれ "&lt;", "&gt;", "&amp;" と書く必要がある. ただし, 「<pre>」ではじめた段落に関してはこの限りではない.
70
-
71
- == 謝辞
72
- ただただしさんをはじめとする, tDiaryおよびスタイル変更機能を実装いただきました皆様に感謝致します.
73
-
74
- Yoshinori K. Okuji さんが tDiary-1.4.3 をベースに etDiary を実装され, etDiary フォーマットを考案されることがなかったならば, このスタイルが実装されることはありませんでした. また, 当文書も, Okuji さんのページをほぼそのまま写させていただきました. この文書を書けるのも, ひとえに Okuji さんのおかげです. ここに感謝の意を表します.
75
-
76
- その他, etDiary スタイルを利用してくださっている皆様, ご意見頂戴しました皆様に, 御礼申し上げます.
77
-
78
- == 著作権
79
- Copyright 2003 simm <simm at fan.jp>
80
-
81
- Permission is granted for use, copying, modification, distribution, and distribution of modified versions of this work under the terms of GPL version 2 or later.
82
-
83
- =end
@@ -1,448 +0,0 @@
1
- # -*- coding: utf-8; -*-
2
- #
3
- # etdiary_style.rb: tDiary style class for etDiary format.
4
- # $Id: etdiary_style.rb,v 1.20 2008-03-02 09:01:20 kazuhiko Exp $
5
- #
6
- # if you want to use this style, add @style into tdiary.conf below:
7
- #
8
- # @style = 'etDiary'
9
- #
10
- module TDiary
11
- module Style
12
- class EtdiarySection
13
- attr_reader :subtitle, :bodies, :author, :anchor_type
14
- attr_reader :categories, :stripped_subtitle
15
-
16
- alias :subtitle_to_html :subtitle
17
- alias :stripped_subtitle_to_html :stripped_subtitle
18
-
19
- def initialize( title, author = nil )
20
- @subtitle = title
21
- if @subtitle then
22
- if "" == @subtitle then
23
- @subtitle = nil
24
- @anchor_type = :P
25
- elsif "<>" == @subtitle then
26
- @subtitle = nil
27
- @anchor_type = :A
28
- elsif /^<>/ =~ @subtitle then
29
- @subtitle = @subtitle[2..-1]
30
- @anchor_type = :H4
31
- else
32
- @anchor_type = :H3
33
- end
34
- else
35
- @subtitle = nil
36
- @anchor_type = nil
37
- end
38
- @bodies = []
39
- @categories = get_categories
40
- @stripped_subtitle = strip_subtitle
41
- end
42
-
43
- def subtitle=(subtitle)
44
- cat_str = ""
45
- @categories.each {|cat|
46
- cat_str << "[#{cat}]"
47
- }
48
- cat_str << " " unless cat_str.empty?
49
- @subtitle = subtitle
50
- if @subtitle then
51
- if "" == @subtitle then
52
- @subtitle = nil
53
- @anchor_type = :P
54
- elsif "<>" == @subtitle then
55
- @subtitle = nil
56
- @anchor_type = :A
57
- elsif /^<>/ =~ @subtitle then
58
- @subtitle = @subtitle[2..-1]
59
- @anchor_type = :H4
60
- else
61
- @subtitle = cat_str + subtitle
62
- @anchor_type = :H3
63
- end
64
- else
65
- @subtitle = nil
66
- @anchor_type = nil
67
- end
68
- @stripped_subtitle = strip_subtitle
69
- end
70
-
71
- def body=(str)
72
- @bodies = str.split(/\n/)
73
- end
74
-
75
- def categories=(categories)
76
- @categories = categories
77
- cat_str = ""
78
- categories.each {|cat|
79
- cat_str << "[#{cat}]"
80
- }
81
- @subtitle = @subtitle ? (cat_str + @stripped_subtitle) : nil
82
- @stripped_subtitle = strip_subtitle
83
- end
84
-
85
- def set_body( bodies )
86
- @bodies = bodies
87
- end
88
-
89
- def body
90
- if @bodies then
91
- @bodies.join('')
92
- else
93
- ''
94
- end
95
- end
96
-
97
- def body_to_html
98
- if @bodies then
99
- r = ''
100
- in_p = false
101
- @bodies.join('').each_line("\n\n") do |p|
102
- if /\A</ !~ p then
103
- r << "<p>#{p.chomp}</p>\n"
104
- else
105
- r << p
106
- end
107
- end
108
- r
109
- else
110
- ''
111
- end
112
- end
113
-
114
- def << (string)
115
- @bodies << string
116
- end
117
-
118
- def to_src
119
- s = ''
120
- case @anchor_type
121
- when :A
122
- s << "<<<>>>\n"
123
- when :P
124
- s << "<<>>\n"
125
- when :H4
126
- s << "[#{@author}]" if @author
127
- s << "<<<>" + @subtitle + ">>\n"
128
- when :H3
129
- s << "[#{@author}]" if @author
130
- s << "<<" + @subtitle + ">>\n"
131
- end
132
- s + ( if "" != body then body else "\n" end )
133
- end
134
-
135
- def to_s
136
- "subtitle=#{@subtitle}, body=#{body}"
137
- end
138
-
139
- def get_categories
140
- return [] unless @subtitle
141
- cat = /^(\[(.*?)\])+/.match(@subtitle).to_a[0]
142
- return [] unless cat
143
- cat.scan(/\[(.*?)\]/).collect do |c|
144
- c[0].split(/,/)
145
- end.flatten
146
- end
147
-
148
- def categorized_subtitle
149
- return "" unless @subtitle
150
- cat = /^(\[(.*?)\])+/.match(@subtitle).to_a[0]
151
- return @stripped_subtitle unless cat
152
- cat.gsub(/\[(.*?)\]/) do
153
- $1.split(/,/).collect do |c|
154
- %Q|<%= category_anchor("#{c}") %>|
155
- end.join
156
- end + @stripped_subtitle
157
- end
158
-
159
- def strip_subtitle
160
- return nil unless @subtitle
161
- @subtitle.sub(/^(\[(.*?)\])+\s*/,'')
162
- end
163
- end
164
-
165
- class EtHtml4Factory
166
- def initialize( opt, idx = 1 )
167
- @opt = opt
168
- @idx = idx
169
- end
170
- def title( date, fragment )
171
- return nil if nil == fragment.anchor_type
172
- name = 'p%02d' % @idx
173
- @idx += 1
174
- if :A == fragment.anchor_type then
175
- if @opt['anchor'] then
176
- return "<a name=\"#{name}\"></a>"
177
- else
178
- return nil
179
- end
180
- end
181
-
182
- r = ''
183
- if @opt['index']
184
- if fragment.subtitle
185
- r << %Q[<%= subtitle_proc( Time::at( #{date.to_i} ), #{fragment.subtitle.dump.gsub( /%/, '\\\\045' )} ) %>]
186
- else
187
- r << %Q[<%= subtitle_proc( Time::at( #{date.to_i} ), nil ) %>]
188
- end
189
- end
190
-
191
- case fragment.anchor_type
192
- when :P
193
- r
194
- when :H4
195
- "<h4>" + r + ":</h4>\n"
196
- when :H3
197
- "<h3>" + r + "</h3>\n"
198
- end
199
- end
200
- def section_start( date )
201
- %Q[<div class="section">\n<%=section_enter_proc( Time::at( #{date.to_i} ) )%>\n]
202
- end
203
- def section_end( date )
204
- "<%=section_leave_proc( Time::at( #{date.to_i} ) )%>\n</div>\n"
205
- end
206
- def block_title?( fragment )
207
- case fragment.anchor_type
208
- when :H3, :H4
209
- true
210
- else
211
- false
212
- end
213
- end
214
- def p_start
215
- "<p>"
216
- end
217
- def p_end
218
- "</p>"
219
- end
220
- def pre_start
221
- "<pre>"
222
- end
223
- def pre_end
224
- "</pre>"
225
- end
226
- end
227
-
228
- class EtCHtmlFactory
229
- def initialize( opt, idx = 1 )
230
- @opt = opt
231
- @idx = idx
232
- end
233
- def title( date, fragment )
234
- return nil if nil == fragment.anchor_type
235
- name = 'p%02d' % @idx
236
- return "<A NAME=\"#{name}\"></A>" if :A == fragment.anchor_type
237
- r = ""
238
- if fragment.subtitle
239
- r << %Q[<%= subtitle_proc( Time::at( #{date.to_i} ), #{fragment.subtitle.dump.gsub( /%/, '\\\\045' )} ) %>]
240
- else
241
- r << %Q[<%= subtitle_proc( Time::at( #{date.to_i} ), nil ) %>]
242
- end
243
- @idx += 1
244
- case fragment.anchor_type
245
- when :P
246
- r
247
- when :H4
248
- r + ": "
249
- when :H3
250
- "<H3>" + r + "</H3>\n"
251
- end
252
- end
253
- def section_start( date )
254
- "<%=section_enter_proc( Time::at( #{date.to_i} ) )%>\n"
255
- end
256
- def section_end( date )
257
- "<%=section_leave_proc( Time::at( #{date.to_i} ) )%>\n"
258
- end
259
- def block_title?( fragment )
260
- case fragment.anchor_type
261
- when :H3
262
- true
263
- else
264
- false
265
- end
266
- end
267
- def p_start
268
- "<P>"
269
- end
270
- def p_end
271
- "</P>"
272
- end
273
- def pre_start
274
- "<PRE>"
275
- end
276
- def pre_end
277
- "</PRE>"
278
- end
279
- end
280
-
281
- class EtdiaryDiary
282
- include BaseDiary
283
- include CategorizableDiary
284
-
285
- TAG_BEG_REGEXP = /\A<([A-Za-z][0-9A-Za-z]*)([^>]*)>([^\r]*)\z/
286
- TAG_END_REGEXP = /\A([^\r]*)<\/([A-Za-z][0-9A-Za-z]*)>\n*\z/
287
- PRE_REGEXP = /\A<[Pp][Rr][Ee][^>]*>([^\r]*)<\/[Pp][Rr][Ee]>\n*\z/
288
- TITLE_REGEXP = /\A<<([^\r]*?)>>[^>]/
289
-
290
- def initialize( date, title, body, modified = Time::now )
291
- init_diary
292
- set_date( date )
293
- set_title( title )
294
- @sections = []
295
- if body != '' then
296
- append( body )
297
- end
298
- @last_modified = modified
299
- end
300
-
301
- def style
302
- 'etDiary'
303
- end
304
-
305
- def replace( date, title, body )
306
- set_date( date )
307
- set_title( title )
308
- @sections = []
309
- append( body )
310
- end
311
-
312
- def append( body, author = nil )
313
- section = nil
314
- buffer = nil
315
- tag_kind = nil
316
- body.gsub(/\r/,'').sub(/\A\n*/,'').sub(/\n*\z/,"\n\n").each_line('') do |fragment|
317
- if buffer and TAG_END_REGEXP =~ fragment and $2.downcase == tag_kind then
318
- section << buffer + fragment.sub(/\n*\z/,"\n\n")
319
- tag_kind = nil
320
- buffer = nil
321
- elsif buffer then
322
- buffer << fragment
323
- else
324
- if section
325
- @sections << section
326
- end
327
- title = TITLE_REGEXP.match(fragment+"\n").to_a[1]
328
- section = EtdiarySection::new( title, author )
329
- fragment = fragment[ title.length + 4 .. -1 ].sub(/\A\n/,'') if title
330
- if TAG_BEG_REGEXP =~ fragment then
331
- tag_kind = $1.downcase
332
- if TAG_END_REGEXP =~ fragment and $2.downcase == tag_kind then
333
- section << fragment.sub(/\n*\z/,"\n\n")
334
- tag_kind = nil
335
- else
336
- buffer = fragment
337
- end
338
- else
339
- section << fragment
340
- end
341
- end
342
- end
343
- if buffer
344
- section << buffer << "</#{tag_kind}>(tDiary warning: tag &lt;#{tag_kind}&gt; is not terminated.)"
345
- end
346
- if section
347
- @sections << section
348
- end
349
- @last_modified = Time::now
350
- self
351
- end
352
-
353
- def each_paragraph
354
- @sections.each do |fragment|
355
- yield fragment
356
- end
357
- end
358
-
359
- def each_section
360
- section = nil
361
- each_paragraph do |fragment|
362
- if section and nil == fragment.anchor_type then
363
- section << fragment.body
364
- else
365
- yield section if section and section.anchor_type
366
- section = fragment.dup
367
- section.set_body( [ fragment.body ] )
368
- end
369
- end
370
- yield section if section
371
- end
372
-
373
- def add_section(subtitle, body)
374
- sec = EtdiarySection::new( '' )
375
- sec.subtitle = subtitle
376
- sec.body = body
377
- @sections << sec
378
- @sections.size
379
- end
380
-
381
- def delete_section(index)
382
- @sections.delete_at(index - 1)
383
- end
384
-
385
- def to_src
386
- src = ''
387
- each_paragraph do |fragment|
388
- src << fragment.to_src
389
- end
390
- src.sub(/\n*\z/,"\n")
391
- end
392
-
393
- def to_html_section(section, factory)
394
- r = ''
395
- s = if section.bodies then section.body else nil end
396
- t = factory.title( date, section )
397
- if factory.block_title?(section) then
398
- r << t if t
399
- t = nil
400
- end
401
- if s && PRE_REGEXP =~ s then
402
- r << factory.p_start << t << factory.p_end << "\n" if t
403
- r << factory.pre_start
404
- r << $1.gsub(/&/,"&amp;").gsub(/</,"&lt;").gsub(/>/,"&gt;")
405
- r << factory.pre_end << "\n"
406
- elsif s && /\A</ =~ s then
407
- r << factory.p_start << t << factory.p_end << "\n" if t
408
- r << s.sub( /\n*\z/, "\n" )
409
- else
410
- r << factory.p_start if t || s
411
- r << t if t
412
- r << s.sub(/\A\n*/,"\n").sub(/\n*\z/, "\n") if s
413
- r << factory.p_end << "\n" if t || s
414
- end
415
- r
416
- end
417
-
418
- def to_html( opt = {'anchor' => true, 'index' => true}, mode = :HTML )
419
- case mode
420
- when :CHTML
421
- f = EtCHtmlFactory::new(opt)
422
- else
423
- f = EtHtml4Factory::new(opt)
424
- end
425
- r = f.section_start( date )
426
- each_paragraph do |fragment|
427
- if :H3 == fragment.anchor_type and r != f.section_start( date ) then
428
- r << f.section_end( date ) << "\n" << f.section_start( date )
429
- end
430
- r << to_html_section(fragment,f)
431
- end
432
- r + f.section_end( date )
433
- end
434
-
435
- def to_s
436
- "date=#{date.strftime('%Y%m%d')}, title=#{title}, " \
437
- + "body=[#{@sections.join('][')}]"
438
- end
439
- end
440
- end
441
- end
442
-
443
- # Local Variables:
444
- # mode: ruby
445
- # indent-tabs-mode: t
446
- # tab-width: 3
447
- # ruby-indent-level: 3
448
- # End: