tdiary 4.0.1 → 4.0.1.20130903

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b46d9ee7aa1e0915c351bbbc64c485d36659a263
4
- data.tar.gz: bf2231053a33b0c93c1292d6346c45318dbd67cf
3
+ metadata.gz: f04df177eb9cdb1da5cdf4c260a2ce21acf5adca
4
+ data.tar.gz: fb82eb586136566043abcc0bd178b4265233c329
5
5
  SHA512:
6
- metadata.gz: 1de72ffaaa4630b96be0e0991e1fe5a5aa6531200c261e67c376e6fbd49be409f238e216e0152183c921416e9db8f9de255383f3e93d6cfb707cd144e5403a81
7
- data.tar.gz: 2b4dbd5e980972847e510819ff81cd9212f3938714022a24e934b9933040a0b639c2b1001c46e98e7057384828c51e3135a482839e5fddfec634f7decf00f8f5
6
+ metadata.gz: 9a0fcf194925de5285c50782ee68d6deb455df5ec924a944199648995589bdeca8765f7e6327dec8541d7beec486058d30ca95c03b79bbb3a2ccf0a2daedd8eb
7
+ data.tar.gz: 06a7c5e731b231804d917a37f0b057ab444fd8d13f8daecbc1344378ec1d797f7278a10c8167f0c42e003b41bc067440fb587935865759f1176065feed156f45
@@ -24,22 +24,24 @@
24
24
  alias :title_tag2 :title_tag
25
25
 
26
26
  module ::TDiary
27
- module DiaryBase
28
- def all_subtitles_to_html
29
- titles = Array.new
30
- each_section do |section|
31
- titles << (section.subtitle_to_html || '').strip
27
+ module Style
28
+ module BaseDiary
29
+ def all_subtitles_to_html
30
+ titles = Array.new
31
+ each_section do |section|
32
+ titles << (section.subtitle_to_html || '').strip
33
+ end
34
+ return titles
32
35
  end
33
- return titles
34
- end
35
36
 
36
- def all_stripped_subtitles_to_html
37
- return all_subtitles_to_html unless categorizable?
38
- titles = Array.new
39
- each_section do |section|
40
- titles << (section.stripped_subtitle_to_html || '').strip
37
+ def all_stripped_subtitles_to_html
38
+ return all_subtitles_to_html unless categorizable?
39
+ titles = Array.new
40
+ each_section do |section|
41
+ titles << (section.stripped_subtitle_to_html || '').strip
42
+ end
43
+ return titles
41
44
  end
42
- return titles
43
45
  end
44
46
  end
45
47
  end
@@ -51,6 +51,7 @@ Please note that not all are documented.
51
51
  =end
52
52
 
53
53
  module TDiary
54
+ module Style
54
55
  =begin
55
56
  === TDiary::Emptdiary::EmptdiaryString < String
56
57
  Extended String class not to divide things between <% and %>.
@@ -61,69 +62,69 @@ Extended String class not to divide things between <% and %>.
61
62
  String showing a fragment of Regexp. This will be combined in a
62
63
  Regexp like: /(#{delimiter)|<%|%>)/.
63
64
  =end
64
- class Emptdiary
65
- class EmptdiaryString < String
66
- def split_unless_plugin( delimiter = "\n\n+" )
67
- result = Array.new
68
- fragment = ''
69
- nest = 0
70
- remain = self.gsub(/.*?(#{delimiter}|<%|%>)/m) do
71
- fragment += $&
72
- case $1
73
- when '<%'
74
- nest += 1
75
- when '%>'
76
- nest -= 1
77
- else
78
- if nest == 0 then
79
- fragment.sub!( /#{delimiter}\z/, '' )
80
- result << Emptdiary::EmptdiaryString.new( fragment ) unless fragment.empty?
81
- fragment = ''
65
+ class Emptdiary
66
+ class EmptdiaryString < String
67
+ def split_unless_plugin( delimiter = "\n\n+" )
68
+ result = Array.new
69
+ fragment = ''
70
+ nest = 0
71
+ remain = self.gsub(/.*?(#{delimiter}|<%|%>)/m) do
72
+ fragment += $&
73
+ case $1
74
+ when '<%'
75
+ nest += 1
76
+ when '%>'
77
+ nest -= 1
78
+ else
79
+ if nest == 0 then
80
+ fragment.sub!( /#{delimiter}\z/, '' )
81
+ result << Emptdiary::EmptdiaryString.new( fragment ) unless fragment.empty?
82
+ fragment = ''
83
+ end
82
84
  end
85
+ ''
83
86
  end
84
- ''
87
+ fragment += remain
88
+ fragment.sub!( /#{delimiter}\z/, '' )
89
+ result << Emptdiary::EmptdiaryString.new( fragment ) unless fragment.empty?
90
+ result
85
91
  end
86
- fragment += remain
87
- fragment.sub!( /#{delimiter}\z/, '' )
88
- result << Emptdiary::EmptdiaryString.new( fragment ) unless fragment.empty?
89
- result
90
92
  end
91
93
  end
92
- end
93
94
 
94
95
  =begin
95
96
  === TDiary::EmptdiartySection < TdiarySection
96
97
  Almost the same as TdiarySection but usess split_unless_plugin instead
97
98
  of split. initialize method is overrideen.
98
99
  =end
99
- class EmptdiarySection < TdiarySection
100
- def initialize( fragment, author = nil )
101
- @author = author
102
- lines = fragment.split_unless_plugin( "\n+" )
103
- if lines.size > 1 then
104
- if /\A<</ =~ lines[0]
105
- @subtitle = lines.shift.chomp.sub( /\A</, '' )
106
- elsif /\A[  <]/u !~ lines[0]
107
- @subtitle = lines.shift.chomp
100
+ class EmptdiarySection < TdiarySection
101
+ def initialize( fragment, author = nil )
102
+ @author = author
103
+ lines = fragment.split_unless_plugin( "\n+" )
104
+ if lines.size > 1 then
105
+ if /\A<</ =~ lines[0]
106
+ @subtitle = lines.shift.chomp.sub( /\A</, '' )
107
+ elsif /\A[  <]/u !~ lines[0]
108
+ @subtitle = lines.shift.chomp
109
+ end
108
110
  end
111
+ @body = Emptdiary::EmptdiaryString.new( lines.join( "\n" ) )
112
+ @categories = get_categories
113
+ @stripped_subtitle = strip_subtitle
109
114
  end
110
- @body = Emptdiary::EmptdiaryString.new( lines.join( "\n" ) )
111
- @categories = get_categories
112
- @stripped_subtitle = strip_subtitle
113
- end
114
115
 
115
- def body_to_html
116
- html = ""
117
- @body.split_unless_plugin( "\n" ).each do |p|
118
- if /\A</ =~ p then
119
- html << p
120
- else
121
- html << "<p>#{p}</p>"
116
+ def body_to_html
117
+ html = ""
118
+ @body.split_unless_plugin( "\n" ).each do |p|
119
+ if /\A</ =~ p then
120
+ html << p
121
+ else
122
+ html << "<p>#{p}</p>"
123
+ end
122
124
  end
125
+ html
123
126
  end
124
- html
125
127
  end
126
- end
127
128
 
128
129
  =begin
129
130
  === TDiary::EmptdiaryDiary < TdiaryDiary
@@ -133,60 +134,61 @@ body being an EmptdiaryString. Also, to_html4 and to_chtml methods are
133
134
  overridden to split_unless_plugin before collect'ing the body of the
134
135
  sections.
135
136
  =end
136
- class EmptdiaryDiary < TdiaryDiary
137
- def style
138
- 'emptdiary'
139
- end
140
-
141
- def append( body, author = nil )
142
- Emptdiary::EmptdiaryString.new(body.gsub( /\r/, '' )).split_unless_plugin( "\n\n+" ).each do |fragment|
143
- section = EmptdiarySection::new( fragment, author )
144
- @sections << section if section
137
+ class EmptdiaryDiary < TdiaryDiary
138
+ def style
139
+ 'emptdiary'
145
140
  end
146
- @last_modified = Time::now
147
- self
148
- end
149
-
150
- def to_html4( opt )
151
- r = ''
152
- each_section do |section|
153
- r << %Q[<div class="section">\n]
154
- r << %Q[<%=section_enter_proc( Time::at( #{date.to_i} ) )%>\n]
155
- if section.subtitle then
156
- r << %Q[<h3><%= subtitle_proc( Time::at( #{date.to_i} ), #{section.subtitle.dump.gsub( /%/, '\\\\045' )} ) %></h3>\n]
141
+
142
+ def append( body, author = nil )
143
+ Emptdiary::EmptdiaryString.new(body.gsub( /\r/, '' )).split_unless_plugin( "\n\n+" ).each do |fragment|
144
+ section = EmptdiarySection::new( fragment, author )
145
+ @sections << section if section
157
146
  end
158
- if /\A</ =~ section.body then
159
- r << %Q[#{section.body}]
160
- elsif section.subtitle
161
- r << %Q[<p>#{section.body.split_unless_plugin( "\n+" ).collect{|l|l.chomp.sub( /\A[  ]/u, '')}.join( "</p>\n<p>" )}</p>]
162
- else
163
- r << %Q[<p><%= subtitle_proc( Time::at( #{date.to_i} ), nil ) %>]
164
- r << %Q[#{section.body.split_unless_plugin( "\n+" ).collect{|l|l.chomp.sub( /\A[  ]/u, '' )}.join( "</p>\n<p>" )}</p>]
165
- end
166
- r << %Q[<%=section_leave_proc( Time::at( #{date.to_i} ) )%>\n]
167
- r << %Q[</div>]
147
+ @last_modified = Time::now
148
+ self
168
149
  end
169
- r
170
- end
171
150
 
172
- def to_chtml( opt )
173
- r = ''
174
- each_section do |section|
175
- r << %Q[<%=section_enter_proc( Time::at( #{date.to_i} ) )%>\n]
176
- if section.subtitle then
177
- r << %Q[<H3><%= subtitle_proc( Time::at( #{date.to_i} ), #{section.subtitle.dump.gsub( /%/, '\\\\045' )} ) %></H3>\n]
151
+ def to_html4( opt )
152
+ r = ''
153
+ each_section do |section|
154
+ r << %Q[<div class="section">\n]
155
+ r << %Q[<%=section_enter_proc( Time::at( #{date.to_i} ) )%>\n]
156
+ if section.subtitle then
157
+ r << %Q[<h3><%= subtitle_proc( Time::at( #{date.to_i} ), #{section.subtitle.dump.gsub( /%/, '\\\\045' )} ) %></h3>\n]
158
+ end
159
+ if /\A</ =~ section.body then
160
+ r << %Q[#{section.body}]
161
+ elsif section.subtitle
162
+ r << %Q[<p>#{section.body.split_unless_plugin( "\n+" ).collect{|l|l.chomp.sub( /\A[  ]/u, '')}.join( "</p>\n<p>" )}</p>]
163
+ else
164
+ r << %Q[<p><%= subtitle_proc( Time::at( #{date.to_i} ), nil ) %>]
165
+ r << %Q[#{section.body.split_unless_plugin( "\n+" ).collect{|l|l.chomp.sub( /\A[  ]/u, '' )}.join( "</p>\n<p>" )}</p>]
166
+ end
167
+ r << %Q[<%=section_leave_proc( Time::at( #{date.to_i} ) )%>\n]
168
+ r << %Q[</div>]
178
169
  end
179
- if /\A</ =~ section.body then
180
- r << section.body
181
- elsif section.subtitle
182
- r << %Q[<P>#{section.body.split_unless_plugin( "\n+" ).collect{|l|l.chomp.sub( /\A[  ]/u, '' )}.join( "</P>\n<P>" )}</P>]
183
- else
184
- r << %Q[<P><%= subtitle_proc( Time::at( #{date.to_i} ), nil ) %>]
185
- r << %Q[#{section.body.split_unless_plugin( "\n+" ).collect{|l|l.chomp.sub( /\A[  ]/u, '' )}.join( "</P>\n<P>" )}</P>]
170
+ r
171
+ end
172
+
173
+ def to_chtml( opt )
174
+ r = ''
175
+ each_section do |section|
176
+ r << %Q[<%=section_enter_proc( Time::at( #{date.to_i} ) )%>\n]
177
+ if section.subtitle then
178
+ r << %Q[<H3><%= subtitle_proc( Time::at( #{date.to_i} ), #{section.subtitle.dump.gsub( /%/, '\\\\045' )} ) %></H3>\n]
179
+ end
180
+ if /\A</ =~ section.body then
181
+ r << section.body
182
+ elsif section.subtitle
183
+ r << %Q[<P>#{section.body.split_unless_plugin( "\n+" ).collect{|l|l.chomp.sub( /\A[  ]/u, '' )}.join( "</P>\n<P>" )}</P>]
184
+ else
185
+ r << %Q[<P><%= subtitle_proc( Time::at( #{date.to_i} ), nil ) %>]
186
+ r << %Q[#{section.body.split_unless_plugin( "\n+" ).collect{|l|l.chomp.sub( /\A[  ]/u, '' )}.join( "</P>\n<P>" )}</P>]
187
+ end
188
+ r << %Q[<%=section_leave_proc( Time::at( #{date.to_i} ) )%>\n]
186
189
  end
187
- r << %Q[<%=section_leave_proc( Time::at( #{date.to_i} ) )%>\n]
190
+ r
188
191
  end
189
- r
190
192
  end
191
193
  end
192
194
  end
@@ -8,432 +8,434 @@
8
8
  # @style = 'etDiary'
9
9
  #
10
10
  module TDiary
11
- class EtdiarySection
12
- attr_reader :subtitle, :bodies, :author, :anchor_type
13
- attr_reader :categories, :stripped_subtitle
14
-
15
- alias :subtitle_to_html :subtitle
16
- alias :stripped_subtitle_to_html :stripped_subtitle
17
-
18
- def initialize( title, author = nil )
19
- @subtitle = title
20
- if @subtitle then
21
- if "" == @subtitle then
22
- @subtitle = nil
23
- @anchor_type = :P
24
- elsif "<>" == @subtitle then
25
- @subtitle = nil
26
- @anchor_type = :A
27
- elsif /^<>/ =~ @subtitle then
28
- @subtitle = @subtitle[2..-1]
29
- @anchor_type = :H4
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
30
34
  else
31
- @anchor_type = :H3
35
+ @subtitle = nil
36
+ @anchor_type = nil
32
37
  end
33
- else
34
- @subtitle = nil
35
- @anchor_type = nil
38
+ @bodies = []
39
+ @categories = get_categories
40
+ @stripped_subtitle = strip_subtitle
36
41
  end
37
- @bodies = []
38
- @categories = get_categories
39
- @stripped_subtitle = strip_subtitle
40
- end
41
42
 
42
- def subtitle=(subtitle)
43
- cat_str = ""
44
- @categories.each {|cat|
45
- cat_str << "[#{cat}]"
46
- }
47
- cat_str << " " unless cat_str.empty?
48
- @subtitle = subtitle
49
- if @subtitle then
50
- if "" == @subtitle then
51
- @subtitle = nil
52
- @anchor_type = :P
53
- elsif "<>" == @subtitle then
54
- @subtitle = nil
55
- @anchor_type = :A
56
- elsif /^<>/ =~ @subtitle then
57
- @subtitle = @subtitle[2..-1]
58
- @anchor_type = :H4
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
59
64
  else
60
- @subtitle = cat_str + subtitle
61
- @anchor_type = :H3
65
+ @subtitle = nil
66
+ @anchor_type = nil
62
67
  end
63
- else
64
- @subtitle = nil
65
- @anchor_type = nil
68
+ @stripped_subtitle = strip_subtitle
66
69
  end
67
- @stripped_subtitle = strip_subtitle
68
- end
69
70
 
70
- def body=(str)
71
- @bodies = str.split(/\n/)
72
- end
71
+ def body=(str)
72
+ @bodies = str.split(/\n/)
73
+ end
73
74
 
74
- def categories=(categories)
75
- @categories = categories
76
- cat_str = ""
77
- categories.each {|cat|
78
- cat_str << "[#{cat}]"
79
- }
80
- @subtitle = @subtitle ? (cat_str + @stripped_subtitle) : nil
81
- @stripped_subtitle = strip_subtitle
82
- end
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
83
84
 
84
- def set_body( bodies )
85
- @bodies = bodies
86
- end
85
+ def set_body( bodies )
86
+ @bodies = bodies
87
+ end
87
88
 
88
- def body
89
- if @bodies then
90
- @bodies.join('')
91
- else
92
- ''
89
+ def body
90
+ if @bodies then
91
+ @bodies.join('')
92
+ else
93
+ ''
94
+ end
93
95
  end
94
- end
95
96
 
96
- def body_to_html
97
- if @bodies then
98
- r = ''
99
- in_p = false
100
- @bodies.join('').each_line("\n\n") do |p|
101
- if /\A</ !~ p then
102
- r << "<p>#{p.chomp}</p>\n"
103
- else
104
- r << p
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
105
107
  end
108
+ r
109
+ else
110
+ ''
106
111
  end
107
- r
108
- else
109
- ''
110
112
  end
111
- end
112
113
 
113
- def << (string)
114
- @bodies << string
115
- end
114
+ def << (string)
115
+ @bodies << string
116
+ end
116
117
 
117
- def to_src
118
- s = ''
119
- case @anchor_type
120
- when :A
121
- s << "<<<>>>\n"
122
- when :P
123
- s << "<<>>\n"
124
- when :H4
125
- s << "[#{@author}]" if @author
126
- s << "<<<>" + @subtitle + ">>\n"
127
- when :H3
128
- s << "[#{@author}]" if @author
129
- s << "<<" + @subtitle + ">>\n"
130
- end
131
- s + ( if "" != body then body else "\n" end )
132
- end
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
133
134
 
134
- def to_s
135
- "subtitle=#{@subtitle}, body=#{body}"
136
- end
135
+ def to_s
136
+ "subtitle=#{@subtitle}, body=#{body}"
137
+ end
137
138
 
138
- def get_categories
139
- return [] unless @subtitle
140
- cat = /^(\[(.*?)\])+/.match(@subtitle).to_a[0]
141
- return [] unless cat
142
- cat.scan(/\[(.*?)\]/).collect do |c|
143
- c[0].split(/,/)
144
- end.flatten
145
- end
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
146
147
 
147
- def categorized_subtitle
148
- return "" unless @subtitle
149
- cat = /^(\[(.*?)\])+/.match(@subtitle).to_a[0]
150
- return @stripped_subtitle unless cat
151
- cat.gsub(/\[(.*?)\]/) do
152
- $1.split(/,/).collect do |c|
153
- %Q|<%= category_anchor("#{c}") %>|
154
- end.join
155
- end + @stripped_subtitle
156
- end
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
157
158
 
158
- def strip_subtitle
159
- return nil unless @subtitle
160
- @subtitle.sub(/^(\[(.*?)\])+\s*/,'')
159
+ def strip_subtitle
160
+ return nil unless @subtitle
161
+ @subtitle.sub(/^(\[(.*?)\])+\s*/,'')
162
+ end
161
163
  end
162
- end
163
164
 
164
- class EtHtml4Factory
165
- def initialize( opt, idx = 1 )
166
- @opt = opt
167
- @idx = idx
168
- end
169
- def title( date, fragment )
170
- return nil if nil == fragment.anchor_type
171
- name = 'p%02d' % @idx
172
- @idx += 1
173
- if :A == fragment.anchor_type then
174
- if @opt['anchor'] then
175
- return "<a name=\"#{name}\"></a>"
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
176
210
  else
177
- return nil
211
+ false
178
212
  end
179
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
180
227
 
181
- r = ''
182
- if @opt['index']
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 = ""
183
238
  if fragment.subtitle
184
239
  r << %Q[<%= subtitle_proc( Time::at( #{date.to_i} ), #{fragment.subtitle.dump.gsub( /%/, '\\\\045' )} ) %>]
185
240
  else
186
241
  r << %Q[<%= subtitle_proc( Time::at( #{date.to_i} ), nil ) %>]
187
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
188
252
  end
189
-
190
- case fragment.anchor_type
191
- when :P
192
- r
193
- when :H4
194
- "<h4>" + r + ":</h4>\n"
195
- when :H3
196
- "<h3>" + r + "</h3>\n"
253
+ def section_start( date )
254
+ "<%=section_enter_proc( Time::at( #{date.to_i} ) )%>\n"
197
255
  end
198
- end
199
- def section_start( date )
200
- %Q[<div class="section">\n<%=section_enter_proc( Time::at( #{date.to_i} ) )%>\n]
201
- end
202
- def section_end( date )
203
- "<%=section_leave_proc( Time::at( #{date.to_i} ) )%>\n</div>\n"
204
- end
205
- def block_title?( fragment )
206
- case fragment.anchor_type
207
- when :H3, :H4
208
- true
209
- else
210
- false
256
+ def section_end( date )
257
+ "<%=section_leave_proc( Time::at( #{date.to_i} ) )%>\n"
211
258
  end
212
- end
213
- def p_start
214
- "<p>"
215
- end
216
- def p_end
217
- "</p>"
218
- end
219
- def pre_start
220
- "<pre>"
221
- end
222
- def pre_end
223
- "</pre>"
224
- end
225
- end
226
-
227
- class EtCHtmlFactory
228
- def initialize( opt, idx = 1 )
229
- @opt = opt
230
- @idx = idx
231
- end
232
- def title( date, fragment )
233
- return nil if nil == fragment.anchor_type
234
- name = 'p%02d' % @idx
235
- return "<A NAME=\"#{name}\"></A>" if :A == fragment.anchor_type
236
- r = ""
237
- if fragment.subtitle
238
- r << %Q[<%= subtitle_proc( Time::at( #{date.to_i} ), #{fragment.subtitle.dump.gsub( /%/, '\\\\045' )} ) %>]
239
- else
240
- r << %Q[<%= subtitle_proc( Time::at( #{date.to_i} ), nil ) %>]
241
- end
242
- @idx += 1
243
- case fragment.anchor_type
244
- when :P
245
- r
246
- when :H4
247
- r + ": "
248
- when :H3
249
- "<H3>" + r + "</H3>\n"
259
+ def block_title?( fragment )
260
+ case fragment.anchor_type
261
+ when :H3
262
+ true
263
+ else
264
+ false
265
+ end
250
266
  end
251
- end
252
- def section_start( date )
253
- "<%=section_enter_proc( Time::at( #{date.to_i} ) )%>\n"
254
- end
255
- def section_end( date )
256
- "<%=section_leave_proc( Time::at( #{date.to_i} ) )%>\n"
257
- end
258
- def block_title?( fragment )
259
- case fragment.anchor_type
260
- when :H3
261
- true
262
- else
263
- false
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>"
264
278
  end
265
279
  end
266
- def p_start
267
- "<P>"
268
- end
269
- def p_end
270
- "</P>"
271
- end
272
- def pre_start
273
- "<PRE>"
274
- end
275
- def pre_end
276
- "</PRE>"
277
- end
278
- end
279
280
 
280
- class EtdiaryDiary
281
- include DiaryBase
282
- include CategorizableDiary
283
-
284
- TAG_BEG_REGEXP = /\A<([A-Za-z][0-9A-Za-z]*)([^>]*)>([^\r]*)\z/
285
- TAG_END_REGEXP = /\A([^\r]*)<\/([A-Za-z][0-9A-Za-z]*)>\n*\z/
286
- PRE_REGEXP = /\A<[Pp][Rr][Ee][^>]*>([^\r]*)<\/[Pp][Rr][Ee]>\n*\z/
287
- TITLE_REGEXP = /\A<<([^\r]*?)>>[^>]/
288
-
289
- def initialize( date, title, body, modified = Time::now )
290
- init_diary
291
- set_date( date )
292
- set_title( title )
293
- @sections = []
294
- if body != '' then
295
- append( body )
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
296
299
  end
297
- @last_modified = modified
298
- end
299
300
 
300
- def style
301
- 'etDiary'
302
- end
301
+ def style
302
+ 'etDiary'
303
+ end
303
304
 
304
- def replace( date, title, body )
305
- set_date( date )
306
- set_title( title )
307
- @sections = []
308
- append( body )
309
- end
305
+ def replace( date, title, body )
306
+ set_date( date )
307
+ set_title( title )
308
+ @sections = []
309
+ append( body )
310
+ end
310
311
 
311
- def append( body, author = nil )
312
- section = nil
313
- buffer = nil
314
- tag_kind = nil
315
- body.gsub(/\r/,'').sub(/\A\n*/,'').sub(/\n*\z/,"\n\n").each_line('') do |fragment|
316
- if buffer and TAG_END_REGEXP =~ fragment and $2.downcase == tag_kind then
317
- section << buffer + fragment.sub(/\n*\z/,"\n\n")
318
- tag_kind = nil
319
- buffer = nil
320
- elsif buffer then
321
- buffer << fragment
322
- else
323
- if section
324
- @sections << section
325
- end
326
- title = TITLE_REGEXP.match(fragment+"\n").to_a[1]
327
- section = EtdiarySection::new( title, author )
328
- fragment = fragment[ title.length + 4 .. -1 ].sub(/\A\n/,'') if title
329
- if TAG_BEG_REGEXP =~ fragment then
330
- tag_kind = $1.downcase
331
- if TAG_END_REGEXP =~ fragment and $2.downcase == tag_kind then
332
- section << fragment.sub(/\n*\z/,"\n\n")
333
- tag_kind = nil
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
334
338
  else
335
- buffer = fragment
339
+ section << fragment
336
340
  end
337
- else
338
- section << fragment
339
341
  end
340
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
341
351
  end
342
- if buffer
343
- section << buffer << "</#{tag_kind}>(tDiary warning: tag &lt;#{tag_kind}&gt; is not terminated.)"
344
- end
345
- if section
346
- @sections << section
347
- end
348
- @last_modified = Time::now
349
- self
350
- end
351
352
 
352
- def each_paragraph
353
- @sections.each do |fragment|
354
- yield fragment
353
+ def each_paragraph
354
+ @sections.each do |fragment|
355
+ yield fragment
356
+ end
355
357
  end
356
- end
357
358
 
358
- def each_section
359
- section = nil
360
- each_paragraph do |fragment|
361
- if section and nil == fragment.anchor_type then
362
- section << fragment.body
363
- else
364
- yield section if section and section.anchor_type
365
- section = fragment.dup
366
- section.set_body( [ fragment.body ] )
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
367
369
  end
370
+ yield section if section
368
371
  end
369
- yield section if section
370
- end
371
372
 
372
- def add_section(subtitle, body)
373
- sec = EtdiarySection::new( '' )
374
- sec.subtitle = subtitle
375
- sec.body = body
376
- @sections << sec
377
- @sections.size
378
- end
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
379
380
 
380
- def delete_section(index)
381
- @sections.delete_at(index - 1)
382
- end
381
+ def delete_section(index)
382
+ @sections.delete_at(index - 1)
383
+ end
383
384
 
384
- def to_src
385
- src = ''
386
- each_paragraph do |fragment|
387
- src << fragment.to_src
385
+ def to_src
386
+ src = ''
387
+ each_paragraph do |fragment|
388
+ src << fragment.to_src
389
+ end
390
+ src.sub(/\n*\z/,"\n")
388
391
  end
389
- src.sub(/\n*\z/,"\n")
390
- end
391
392
 
392
- def to_html_section(section, factory)
393
- r = ''
394
- s = if section.bodies then section.body else nil end
395
- t = factory.title( date, section )
396
- if factory.block_title?(section) then
397
- r << t if t
398
- t = nil
399
- end
400
- if s && PRE_REGEXP =~ s then
401
- r << factory.p_start << t << factory.p_end << "\n" if t
402
- r << factory.pre_start
403
- r << $1.gsub(/&/,"&amp;").gsub(/</,"&lt;").gsub(/>/,"&gt;")
404
- r << factory.pre_end << "\n"
405
- elsif s && /\A</ =~ s then
406
- r << factory.p_start << t << factory.p_end << "\n" if t
407
- r << s.sub( /\n*\z/, "\n" )
408
- else
409
- r << factory.p_start if t || s
410
- r << t if t
411
- r << s.sub(/\A\n*/,"\n").sub(/\n*\z/, "\n") if s
412
- r << factory.p_end << "\n" if t || s
413
- end
414
- r
415
- end
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
416
417
 
417
- def to_html( opt = {'anchor' => true, 'index' => true}, mode = :HTML )
418
- case mode
419
- when :CHTML
420
- f = EtCHtmlFactory::new(opt)
421
- else
422
- f = EtHtml4Factory::new(opt)
423
- end
424
- r = f.section_start( date )
425
- each_paragraph do |fragment|
426
- if :H3 == fragment.anchor_type and r != f.section_start( date ) then
427
- r << f.section_end( date ) << "\n" << f.section_start( date )
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)
428
424
  end
429
- r << to_html_section(fragment,f)
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 )
430
433
  end
431
- r + f.section_end( date )
432
- end
433
434
 
434
- def to_s
435
- "date=#{date.strftime('%Y%m%d')}, title=#{title}, " \
435
+ def to_s
436
+ "date=#{date.strftime('%Y%m%d')}, title=#{title}, " \
436
437
  + "body=[#{@sections.join('][')}]"
438
+ end
437
439
  end
438
440
  end
439
441
  end