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 +4 -4
- data/misc/plugin/title_tag.rb +15 -13
- data/misc/style/emptdiary/emptdiary_style.rb +95 -93
- data/misc/style/etdiary/etdiary_style.rb +364 -362
- data/misc/style/gfm/gfm_style.rb +129 -127
- data/misc/style/rd/rd_style.rb +158 -157
- data/spec/acceptance_helper.rb +2 -2
- data/spec/core/configuration_spec.rb +32 -0
- data/spec/core/style/emptdiary_style_spec.rb +2 -2
- data/spec/core/style/etdiary_style_spec.rb +2 -2
- data/spec/core/style/gfm_style_spec.rb +2 -2
- data/spec/core/style/rd_style_spec.rb +2 -2
- data/spec/core/style/tdiary_style_spec.rb +2 -2
- data/spec/core/style/wiki_style_spec.rb +2 -2
- data/tdiary.rb +7 -5
- data/tdiary/{config.rb → configuration.rb} +71 -69
- data/tdiary/io/base.rb +1 -1
- data/tdiary/io/pstore.rb +1 -1
- data/tdiary/style.rb +142 -148
- data/tdiary/style/tdiary_style.rb +149 -147
- data/tdiary/style/wiki_style.rb +167 -165
- data/tdiary/tasks/release.rake +40 -27
- data/tdiary/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f04df177eb9cdb1da5cdf4c260a2ce21acf5adca
|
4
|
+
data.tar.gz: fb82eb586136566043abcc0bd178b4265233c329
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a0fcf194925de5285c50782ee68d6deb455df5ec924a944199648995589bdeca8765f7e6327dec8541d7beec486058d30ca95c03b79bbb3a2ccf0a2daedd8eb
|
7
|
+
data.tar.gz: 06a7c5e731b231804d917a37f0b057ab444fd8d13f8daecbc1344378ec1d797f7278a10c8167f0c42e003b41bc067440fb587935865759f1176065feed156f45
|
data/misc/plugin/title_tag.rb
CHANGED
@@ -24,22 +24,24 @@
|
|
24
24
|
alias :title_tag2 :title_tag
|
25
25
|
|
26
26
|
module ::TDiary
|
27
|
-
module
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
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
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
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
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
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
|
-
|
137
|
-
|
138
|
-
|
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
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
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
|
-
|
159
|
-
|
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
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
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
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
r << %Q[
|
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
|
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
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
if
|
22
|
-
@subtitle
|
23
|
-
|
24
|
-
|
25
|
-
@subtitle
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
@
|
35
|
+
@subtitle = nil
|
36
|
+
@anchor_type = nil
|
32
37
|
end
|
33
|
-
|
34
|
-
@
|
35
|
-
@
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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 =
|
61
|
-
@anchor_type =
|
65
|
+
@subtitle = nil
|
66
|
+
@anchor_type = nil
|
62
67
|
end
|
63
|
-
|
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
|
-
|
71
|
-
|
72
|
-
|
71
|
+
def body=(str)
|
72
|
+
@bodies = str.split(/\n/)
|
73
|
+
end
|
73
74
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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
|
-
|
85
|
-
|
86
|
-
|
85
|
+
def set_body( bodies )
|
86
|
+
@bodies = bodies
|
87
|
+
end
|
87
88
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
89
|
+
def body
|
90
|
+
if @bodies then
|
91
|
+
@bodies.join('')
|
92
|
+
else
|
93
|
+
''
|
94
|
+
end
|
93
95
|
end
|
94
|
-
end
|
95
96
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
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
|
-
|
114
|
-
|
115
|
-
|
114
|
+
def << (string)
|
115
|
+
@bodies << string
|
116
|
+
end
|
116
117
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
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
|
-
|
135
|
-
|
136
|
-
|
135
|
+
def to_s
|
136
|
+
"subtitle=#{@subtitle}, body=#{body}"
|
137
|
+
end
|
137
138
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
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
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
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
|
-
|
159
|
-
|
160
|
-
|
159
|
+
def strip_subtitle
|
160
|
+
return nil unless @subtitle
|
161
|
+
@subtitle.sub(/^(\[(.*?)\])+\s*/,'')
|
162
|
+
end
|
161
163
|
end
|
162
|
-
end
|
163
164
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
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
|
-
|
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
|
-
|
182
|
-
|
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
|
-
|
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
|
-
|
199
|
-
|
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
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
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
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
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
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
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
|
-
|
301
|
-
|
302
|
-
|
301
|
+
def style
|
302
|
+
'etDiary'
|
303
|
+
end
|
303
304
|
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
305
|
+
def replace( date, title, body )
|
306
|
+
set_date( date )
|
307
|
+
set_title( title )
|
308
|
+
@sections = []
|
309
|
+
append( body )
|
310
|
+
end
|
310
311
|
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
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
|
-
|
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 <#{tag_kind}> 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 <#{tag_kind}> 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
|
-
|
353
|
-
|
354
|
-
|
353
|
+
def each_paragraph
|
354
|
+
@sections.each do |fragment|
|
355
|
+
yield fragment
|
356
|
+
end
|
355
357
|
end
|
356
|
-
end
|
357
358
|
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
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
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
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
|
-
|
381
|
-
|
382
|
-
|
381
|
+
def delete_section(index)
|
382
|
+
@sections.delete_at(index - 1)
|
383
|
+
end
|
383
384
|
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
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
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
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(/&/,"&").gsub(/</,"<").gsub(/>/,">")
|
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
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
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
|
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
|
-
|
435
|
-
|
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
|