tdiary 4.0.1 → 4.0.1.20130903

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.
@@ -10,182 +10,184 @@
10
10
  # You can redistribute it and/or modify it under GPL2.
11
11
  #
12
12
  module TDiary
13
- class TdiarySection
14
- attr_reader :subtitle, :body, :author
15
- attr_reader :categories, :stripped_subtitle
16
-
17
- alias :subtitle_to_html :subtitle
18
- alias :stripped_subtitle_to_html :stripped_subtitle
19
-
20
- def initialize( fragment, author = nil )
21
- @author = author
22
- lines = fragment.split( /\n+/ )
23
- if lines.size > 1 then
24
- if /^<</ =~ lines[0]
25
- @subtitle = lines.shift.chomp.sub( /^</, '' )
26
- elsif /^[  <]/u !~ lines[0]
27
- @subtitle = lines.shift.chomp
13
+ module Style
14
+ class TdiarySection
15
+ attr_reader :subtitle, :body, :author
16
+ attr_reader :categories, :stripped_subtitle
17
+
18
+ alias :subtitle_to_html :subtitle
19
+ alias :stripped_subtitle_to_html :stripped_subtitle
20
+
21
+ def initialize( fragment, author = nil )
22
+ @author = author
23
+ lines = fragment.split( /\n+/ )
24
+ if lines.size > 1 then
25
+ if /^<</ =~ lines[0]
26
+ @subtitle = lines.shift.chomp.sub( /^</, '' )
27
+ elsif /^[  <]/u !~ lines[0]
28
+ @subtitle = lines.shift.chomp
29
+ end
28
30
  end
29
- end
30
- @body = lines.join( "\n" )
31
-
32
- @categories = get_categories
33
- @stripped_subtitle = strip_subtitle
34
- end
31
+ @body = lines.join( "\n" )
35
32
 
36
- def subtitle=(subtitle)
37
- cat_str = ""
38
- @categories.each {|cat|
39
- cat_str << "[#{cat}]"
40
- }
41
- cat_str << " " unless cat_str.empty?
42
- @subtitle = subtitle ? (cat_str + subtitle) : nil
43
- @stripped_subtitle = strip_subtitle
44
- end
33
+ @categories = get_categories
34
+ @stripped_subtitle = strip_subtitle
35
+ end
45
36
 
46
- def body=(str)
47
- @body = str
48
- end
37
+ def subtitle=(subtitle)
38
+ cat_str = ""
39
+ @categories.each {|cat|
40
+ cat_str << "[#{cat}]"
41
+ }
42
+ cat_str << " " unless cat_str.empty?
43
+ @subtitle = subtitle ? (cat_str + subtitle) : nil
44
+ @stripped_subtitle = strip_subtitle
45
+ end
49
46
 
50
- def categories=(categories)
51
- @categories = categories
52
- cat_str = ""
53
- categories.each {|cat|
54
- cat_str << "[#{cat}]"
55
- }
56
- cat_str << " " unless cat_str.empty?
57
- @subtitle = @subtitle ? (cat_str + @stripped_subtitle) : nil
58
- @stripped_subtitle = strip_subtitle
59
- end
47
+ def body=(str)
48
+ @body = str
49
+ end
60
50
 
61
- def to_src
62
- s = ''
63
- if @stripped_subtitle then
64
- s += "[#{@author}]" if @author
51
+ def categories=(categories)
52
+ @categories = categories
65
53
  cat_str = ""
66
- @categories.each {|cat|
67
- cat_str << "[#{cat}]"
54
+ categories.each {|cat|
55
+ cat_str << "[#{cat}]"
68
56
  }
69
57
  cat_str << " " unless cat_str.empty?
70
- s += cat_str
71
- s += '<' if /^</=~@subtitle
72
- s += @stripped_subtitle + "\n"
73
- else
74
- #s += ' ' unless @body =~ /\A\s</
58
+ @subtitle = @subtitle ? (cat_str + @stripped_subtitle) : nil
59
+ @stripped_subtitle = strip_subtitle
75
60
  end
76
- "#{s}#{@body}\n\n"
77
- end
78
61
 
79
- def body_to_html
80
- html = ""
81
- tag = false
82
- @body.lines.each do |p|
83
- if p[0] == ?< then
84
- html = @body.dup
85
- break
62
+ def to_src
63
+ s = ''
64
+ if @stripped_subtitle then
65
+ s += "[#{@author}]" if @author
66
+ cat_str = ""
67
+ @categories.each {|cat|
68
+ cat_str << "[#{cat}]"
69
+ }
70
+ cat_str << " " unless cat_str.empty?
71
+ s += cat_str
72
+ s += '<' if /^</=~@subtitle
73
+ s += @stripped_subtitle + "\n"
74
+ else
75
+ #s += ' ' unless @body =~ /\A\s</
86
76
  end
87
- html << "<p>#{p}</p>"
77
+ "#{s}#{@body}\n\n"
88
78
  end
89
- html
90
- end
91
-
92
- def to_s
93
- "subtitle=#{@subtitle}, body=#{@body}"
94
- end
95
79
 
96
- def categorized_subtitle
97
- @categories.collect do |c|
98
- %Q|<%= category_anchor("#{c}") %>|
99
- end.join + @stripped_subtitle.to_s
100
- end
80
+ def body_to_html
81
+ html = ""
82
+ tag = false
83
+ @body.lines.each do |p|
84
+ if p[0] == ?< then
85
+ html = @body.dup
86
+ break
87
+ end
88
+ html << "<p>#{p}</p>"
89
+ end
90
+ html
91
+ end
101
92
 
102
- private
103
- def get_categories
104
- return [] unless @subtitle
105
- cat = /^(\[(.*?)\])+/.match(@subtitle).to_a[0]
106
- return [] unless cat
107
- cat.scan(/\[(.*?)\]/).collect do |c|
108
- c[0].split(/,/)
109
- end.flatten
110
- end
93
+ def to_s
94
+ "subtitle=#{@subtitle}, body=#{@body}"
95
+ end
111
96
 
112
- def strip_subtitle
113
- return nil unless @subtitle
114
- @subtitle.sub( /^(\[(.*?)\])+\s*/, '' )
115
- end
116
- end
97
+ def categorized_subtitle
98
+ @categories.collect do |c|
99
+ %Q|<%= category_anchor("#{c}") %>|
100
+ end.join + @stripped_subtitle.to_s
101
+ end
117
102
 
118
- class TdiaryDiary
119
- include DiaryBase
120
- include CategorizableDiary
103
+ private
104
+ def get_categories
105
+ return [] unless @subtitle
106
+ cat = /^(\[(.*?)\])+/.match(@subtitle).to_a[0]
107
+ return [] unless cat
108
+ cat.scan(/\[(.*?)\]/).collect do |c|
109
+ c[0].split(/,/)
110
+ end.flatten
111
+ end
121
112
 
122
- def initialize( date, title, body, modified = Time::now )
123
- init_diary
124
- replace( date, title, body )
125
- @last_modified = modified
113
+ def strip_subtitle
114
+ return nil unless @subtitle
115
+ @subtitle.sub( /^(\[(.*?)\])+\s*/, '' )
116
+ end
126
117
  end
127
118
 
128
- def style
129
- 'tDiary'
130
- end
119
+ class TdiaryDiary
120
+ include BaseDiary
121
+ include CategorizableDiary
131
122
 
132
- def append( body, author = nil )
133
- body.gsub( /\r/, '' ).split( /\n\n+/ ).each do |fragment|
134
- section = TdiarySection::new( fragment, author )
135
- @sections << section if section
123
+ def initialize( date, title, body, modified = Time::now )
124
+ init_diary
125
+ replace( date, title, body )
126
+ @last_modified = modified
136
127
  end
137
- @last_modified = Time::now
138
- self
139
- end
140
128
 
141
- def add_section(subtitle, body)
142
- sec = TdiarySection::new("\n\n ")
143
- sec.subtitle = subtitle
144
- sec.body = body
145
- @sections << sec
146
- @sections.size
147
- end
129
+ def style
130
+ 'tDiary'
131
+ end
148
132
 
149
- def to_html4( opt )
150
- r = ''
151
- each_section do |section|
152
- r << %Q[<div class="section">\n]
153
- r << %Q[<%= section_enter_proc( Time::at( #{date.to_i} ) ) %>\n]
154
- if section.subtitle then
155
- r << %Q[<h3><%= subtitle_proc( Time::at( #{date.to_i} ), #{section.subtitle.dump.gsub( /%/, '\\\\045' )} ) %></h3>\n]
133
+ def append( body, author = nil )
134
+ body.gsub( /\r/, '' ).split( /\n\n+/ ).each do |fragment|
135
+ section = TdiarySection::new( fragment, author )
136
+ @sections << section if section
156
137
  end
157
- if /^</ =~ section.body then
158
- r << %Q[#{section.body}]
159
- elsif section.subtitle
160
- r << %Q[<p>#{section.body.lines.collect{|l|l.chomp.sub( /^[  ]/u, '')}.join( "</p>\n<p>" )}</p>\n]
161
- else
162
- r << %Q[<p><%= subtitle_proc( Time::at( #{date.to_i} ), nil ) %>]
163
- r << %Q[#{section.body.lines.collect{|l|l.chomp.sub( /^[  ]/u, '' )}.join( "</p>\n<p>" )}</p>]
164
- end
165
- r << %Q[<%= section_leave_proc( Time::at( #{date.to_i} ) ) %>\n]
166
- r << %Q[</div>]
138
+ @last_modified = Time::now
139
+ self
167
140
  end
168
- r
169
- end
170
141
 
171
- def to_chtml( opt )
172
- r = ''
173
- each_section do |section|
174
- r << %Q[<%= section_enter_proc( Time::at( #{date.to_i} ) ) %>\n]
175
- if section.subtitle then
176
- r << %Q[<H3><%= subtitle_proc( Time::at( #{date.to_i} ), #{section.subtitle.dump.gsub( /%/, '\\\\045' )} ) %></H3>\n]
142
+ def add_section(subtitle, body)
143
+ sec = TdiarySection::new("\n\n ")
144
+ sec.subtitle = subtitle
145
+ sec.body = body
146
+ @sections << sec
147
+ @sections.size
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]
157
+ end
158
+ if /^</ =~ section.body then
159
+ r << %Q[#{section.body}]
160
+ elsif section.subtitle
161
+ r << %Q[<p>#{section.body.lines.collect{|l|l.chomp.sub( /^[  ]/u, '')}.join( "</p>\n<p>" )}</p>\n]
162
+ else
163
+ r << %Q[<p><%= subtitle_proc( Time::at( #{date.to_i} ), nil ) %>]
164
+ r << %Q[#{section.body.lines.collect{|l|l.chomp.sub( /^[  ]/u, '' )}.join( "</p>\n<p>" )}</p>]
165
+ end
166
+ r << %Q[<%= section_leave_proc( Time::at( #{date.to_i} ) ) %>\n]
167
+ r << %Q[</div>]
177
168
  end
178
- if /^</ =~ section.body then
179
- r << section.body
180
- elsif section.subtitle
181
- r << %Q[<P>#{section.body.lines.collect{|l|l.chomp.sub( /^[  ]/u, '' )}.join( "</P>\n<P>" )}</P>\n]
182
- else
183
- r << %Q[<P><%= subtitle_proc( Time::at( #{date.to_i} ), nil ) %>]
184
- r << %Q[#{section.body.lines.collect{|l|l.chomp.sub( /^[  ]/u, '' )}.join( "</P>\n<P>" )}</P>\n]
169
+ r
170
+ end
171
+
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]
178
+ end
179
+ if /^</ =~ section.body then
180
+ r << section.body
181
+ elsif section.subtitle
182
+ r << %Q[<P>#{section.body.lines.collect{|l|l.chomp.sub( /^[  ]/u, '' )}.join( "</P>\n<P>" )}</P>\n]
183
+ else
184
+ r << %Q[<P><%= subtitle_proc( Time::at( #{date.to_i} ), nil ) %>]
185
+ r << %Q[#{section.body.lines.collect{|l|l.chomp.sub( /^[  ]/u, '' )}.join( "</P>\n<P>" )}</P>\n]
186
+ end
187
+ r << %Q[<%= section_leave_proc( Time::at( #{date.to_i} ) ) %>\n]
185
188
  end
186
- r << %Q[<%= section_leave_proc( Time::at( #{date.to_i} ) ) %>\n]
189
+ r
187
190
  end
188
- r
189
191
  end
190
192
  end
191
193
  end
@@ -13,199 +13,201 @@
13
13
  require 'hikidoc'
14
14
 
15
15
  module TDiary
16
- class WikiSection
17
- include SectionBase
18
-
19
- def initialize( fragment, author = nil )
20
- @author = author
21
- if fragment[0] == ?! then
22
- @subtitle, @body = fragment.split( /\n/, 2 )
23
- @subtitle.sub!( /^\!\s*/, '' )
24
- else
25
- @subtitle = nil
26
- @body = fragment.dup
16
+ module Style
17
+ class WikiSection
18
+ include BaseSection
19
+
20
+ def initialize( fragment, author = nil )
21
+ @author = author
22
+ if fragment[0] == ?! then
23
+ @subtitle, @body = fragment.split( /\n/, 2 )
24
+ @subtitle.sub!( /^\!\s*/, '' )
25
+ else
26
+ @subtitle = nil
27
+ @body = fragment.dup
28
+ end
29
+ @body = @body || ''
30
+ @body.sub!( /[\n\r]+\Z/, '' )
31
+ @body << "\n\n"
32
+ @categories = get_categories
33
+ @stripped_subtitle = strip_subtitle
34
+
35
+ @subtitle_to_html = @subtitle ? to_html( "!#{@subtitle}" ) : ''
36
+ @body_to_html = to_html( @body )
37
+ @html = @subtitle_to_html + "\n" + @body_to_html + "\n"
38
+ @subtitle_to_html = strip_headings( @subtitle_to_html )
39
+ @body_to_html = strip_headings( @body_to_html )
40
+ @stripped_subtitle_to_html = @stripped_subtitle ? strip_headings( to_html( "!#{@stripped_subtitle}" ) ) : nil
27
41
  end
28
- @body = @body || ''
29
- @body.sub!( /[\n\r]+\Z/, '' )
30
- @body << "\n\n"
31
- @categories = get_categories
32
- @stripped_subtitle = strip_subtitle
33
-
34
- @subtitle_to_html = @subtitle ? to_html( "!#{@subtitle}" ) : ''
35
- @body_to_html = to_html( @body )
36
- @html = @subtitle_to_html + "\n" + @body_to_html + "\n"
37
- @subtitle_to_html = strip_headings( @subtitle_to_html )
38
- @body_to_html = strip_headings( @body_to_html )
39
- @stripped_subtitle_to_html = @stripped_subtitle ? strip_headings( to_html( "!#{@stripped_subtitle}" ) ) : nil
40
- end
41
-
42
- def subtitle=(subtitle)
43
- @subtitle = subtitle ? (categories_to_string + subtitle) : nil
44
- @stripped_subtitle = strip_subtitle
45
- end
46
-
47
- def categories=(categories)
48
- @subtitle = @subtitle ? (categories_to_string + @stripped_subtitle) : nil
49
- @stripped_subtitle = strip_subtitle
50
- end
51
42
 
52
- def to_src
53
- r = ''
54
- r << "! #{@subtitle}\n" if @subtitle
55
- r << @body
56
- end
43
+ def subtitle=(subtitle)
44
+ @subtitle = subtitle ? (categories_to_string + subtitle) : nil
45
+ @stripped_subtitle = strip_subtitle
46
+ end
57
47
 
58
- def do_html4( date, idx, opt )
59
- subtitle = false
60
- r = @html.lstrip
61
- r.sub!( %r!<h3>(.+?)</h3>!m ) do
62
- subtitle = true
63
- "<h3><%= subtitle_proc( Time.at( #{date.to_i} ), #{$1.dump.gsub( /%/, '\\\\045' )} ) %></h3>"
48
+ def categories=(categories)
49
+ @subtitle = @subtitle ? (categories_to_string + @stripped_subtitle) : nil
50
+ @stripped_subtitle = strip_subtitle
64
51
  end
65
- r.sub!( %r!^<p>(.+?)</p>$!m ) do
66
- "<p><%= subtitle_proc( Time.at( #{date.to_i} ), #{$1.dump.gsub( /%/, '\\\\045' )} ) %></p>"
67
- end unless subtitle
68
- r.gsub( /<(\/)?tdiary-section>/, '<\\1p>' )
69
- end
70
52
 
71
- private
53
+ def to_src
54
+ r = ''
55
+ r << "! #{@subtitle}\n" if @subtitle
56
+ r << @body
57
+ end
72
58
 
73
- def valid_plugin_syntax?(code)
74
- lambda {
75
- begin
76
- $SAFE = 4
77
- rescue ArgumentError
78
- # $SAFE=4 was removed from Ruby 2.1.0.
79
- ensure
80
- eval( "BEGIN {return true}\n#{code}", nil, "(plugin)", 0 )
59
+ def do_html4( date, idx, opt )
60
+ subtitle = false
61
+ r = @html.lstrip
62
+ r.sub!( %r!<h3>(.+?)</h3>!m ) do
63
+ subtitle = true
64
+ "<h3><%= subtitle_proc( Time.at( #{date.to_i} ), #{$1.dump.gsub( /%/, '\\\\045' )} ) %></h3>"
81
65
  end
82
- }.call
83
- rescue SyntaxError
84
- lambda { eval('') }.call
85
- false
86
- end
87
-
88
- def to_html( string )
89
- html = HikiDoc::to_html( string,
90
- :level => 3,
91
- :empty_element_suffix => '>',
92
- :use_wiki_name => false,
93
- :allow_bracket_inline_image => false,
94
- :plugin_syntax => method(:valid_plugin_syntax?) ).strip
95
- html.gsub!( %r!<span class="plugin">\{\{(.+?)\}\}</span>!m ) do
96
- "<%=#{CGI.unescapeHTML($1)}\n%>"
66
+ r.sub!( %r!^<p>(.+?)</p>$!m ) do
67
+ "<p><%= subtitle_proc( Time.at( #{date.to_i} ), #{$1.dump.gsub( /%/, '\\\\045' )} ) %></p>"
68
+ end unless subtitle
69
+ r.gsub( /<(\/)?tdiary-section>/, '<\\1p>' )
97
70
  end
98
- html.gsub!( %r!<div class="plugin">\{\{(.+?)\}\}</div>!m ) do
99
- "<p><%=#{CGI.unescapeHTML($1)}\n%></p>"
71
+
72
+ private
73
+
74
+ def valid_plugin_syntax?(code)
75
+ lambda {
76
+ begin
77
+ $SAFE = 4
78
+ rescue ArgumentError
79
+ # $SAFE=4 was removed from Ruby 2.1.0.
80
+ ensure
81
+ eval( "BEGIN {return true}\n#{code}", nil, "(plugin)", 0 )
82
+ end
83
+ }.call
84
+ rescue SyntaxError
85
+ lambda { eval('') }.call
86
+ false
100
87
  end
101
- html.gsub!( %r!<a href="(.+?)">(.+?)</a>! ) do
102
- k, u = $2, $1
103
- if /^(\d{4}|\d{6}|\d{8}|\d{8}-\d+)[^\d]*?#?([pct]\d+)?$/ =~ u then
104
- %Q[<%=my '#{$1}#{$2}', '#{escape_quote k}' %>]
105
- elsif /:/ =~ u
106
- scheme, path = u.split( /:/, 2 )
107
- if /\A(?:http|https|ftp|mailto)\z/ =~ scheme
108
- u.sub!( /^\w+:/, '' ) if %r|://| !~ u and /^mailto:/ !~ u
109
- %Q[<a href="#{u}">#{k}</a>]
110
- elsif ( k == u )
111
- %Q[<%=kw '#{escape_quote u}'%>]
112
- else
88
+
89
+ def to_html( string )
90
+ html = HikiDoc::to_html( string,
91
+ :level => 3,
92
+ :empty_element_suffix => '>',
93
+ :use_wiki_name => false,
94
+ :allow_bracket_inline_image => false,
95
+ :plugin_syntax => method(:valid_plugin_syntax?) ).strip
96
+ html.gsub!( %r!<span class="plugin">\{\{(.+?)\}\}</span>!m ) do
97
+ "<%=#{CGI.unescapeHTML($1)}\n%>"
98
+ end
99
+ html.gsub!( %r!<div class="plugin">\{\{(.+?)\}\}</div>!m ) do
100
+ "<p><%=#{CGI.unescapeHTML($1)}\n%></p>"
101
+ end
102
+ html.gsub!( %r!<a href="(.+?)">(.+?)</a>! ) do
103
+ k, u = $2, $1
104
+ if /^(\d{4}|\d{6}|\d{8}|\d{8}-\d+)[^\d]*?#?([pct]\d+)?$/ =~ u then
105
+ %Q[<%=my '#{$1}#{$2}', '#{escape_quote k}' %>]
106
+ elsif /:/ =~ u
107
+ scheme, path = u.split( /:/, 2 )
108
+ if /\A(?:http|https|ftp|mailto)\z/ =~ scheme
109
+ u.sub!( /^\w+:/, '' ) if %r|://| !~ u and /^mailto:/ !~ u
110
+ %Q[<a href="#{u}">#{k}</a>]
111
+ elsif ( k == u )
112
+ %Q[<%=kw '#{escape_quote u}'%>]
113
+ else
114
+ %Q[<%=kw '#{escape_quote u}', '#{escape_quote k}'%>]
115
+ end
116
+ elsif k == u
113
117
  %Q[<%=kw '#{escape_quote u}', '#{escape_quote k}'%>]
118
+ else
119
+ %Q[<a href="#{u}">#{k}</a>]
114
120
  end
115
- elsif k == u
116
- %Q[<%=kw '#{escape_quote u}', '#{escape_quote k}'%>]
117
- else
118
- %Q[<a href="#{u}">#{k}</a>]
119
121
  end
122
+ html
120
123
  end
121
- html
122
- end
123
-
124
- def escape_quote( s )
125
- s.gsub( /'/, "\\\\'" )
126
- end
127
124
 
128
- def strip_headings( string )
129
- html = string
130
- html.sub!( /\A<h3>/, '' )
131
- html.sub!( %r|</h3>\z|, '' )
132
- html.empty? ? nil : html
133
- end
134
-
135
- def get_categories
136
- return [] unless @subtitle
137
- cat = /^(\[([^\[]+?)\])+/.match(@subtitle).to_a[0]
138
- return [] unless cat
139
- cat.scan(/\[(.*?)\]/).collect do |c|
140
- c[0].split(/,/)
141
- end.flatten
142
- end
125
+ def escape_quote( s )
126
+ s.gsub( /'/, "\\\\'" )
127
+ end
143
128
 
144
- def strip_subtitle
145
- return nil unless @subtitle
146
- r = @subtitle.sub(/^(\[[^\[]+?\])+\s*/,'')
147
- if r == ""
148
- nil
149
- else
150
- r
129
+ def strip_headings( string )
130
+ html = string
131
+ html.sub!( /\A<h3>/, '' )
132
+ html.sub!( %r|</h3>\z|, '' )
133
+ html.empty? ? nil : html
151
134
  end
152
- end
153
- end
154
135
 
155
- class WikiDiary
156
- include DiaryBase
157
- include CategorizableDiary
136
+ def get_categories
137
+ return [] unless @subtitle
138
+ cat = /^(\[([^\[]+?)\])+/.match(@subtitle).to_a[0]
139
+ return [] unless cat
140
+ cat.scan(/\[(.*?)\]/).collect do |c|
141
+ c[0].split(/,/)
142
+ end.flatten
143
+ end
158
144
 
159
- def initialize( date, title, body, modified = Time.now )
160
- init_diary
161
- replace( date, title, body )
162
- @last_modified = modified
145
+ def strip_subtitle
146
+ return nil unless @subtitle
147
+ r = @subtitle.sub(/^(\[[^\[]+?\])+\s*/,'')
148
+ if r == ""
149
+ nil
150
+ else
151
+ r
152
+ end
153
+ end
163
154
  end
164
155
 
165
- def style
166
- 'Wiki'
167
- end
156
+ class WikiDiary
157
+ include BaseDiary
158
+ include CategorizableDiary
168
159
 
169
- def append( body, author = nil )
170
- # body1 is a section starts without subtitle.
171
- # body2 are sections starts with subtitle.
172
- if /(.*?)(^![^!].*)/m =~ body
173
- body1 = $1
174
- body2 = $2
175
- elsif /^![^!]/ !~ body
176
- body1 = body
177
- body2 = ''
178
- else
179
- body1 = ''
180
- body2 = body
160
+ def initialize( date, title, body, modified = Time.now )
161
+ init_diary
162
+ replace( date, title, body )
163
+ @last_modified = modified
181
164
  end
182
165
 
183
- unless body1.empty?
184
- current_section = @sections.pop
185
- if current_section then
186
- body1 = "#{current_section.to_src.sub( /\n+\Z/, '' )}\n\n#{body1}"
187
- end
188
- @sections << WikiSection::new( body1, author )
166
+ def style
167
+ 'Wiki'
189
168
  end
190
- section = nil
191
- body2.each_line do |l|
192
- case l
193
- when /^\![^!]/
194
- @sections << WikiSection::new( section, author ) if section
195
- section = l
169
+
170
+ def append( body, author = nil )
171
+ # body1 is a section starts without subtitle.
172
+ # body2 are sections starts with subtitle.
173
+ if /(.*?)(^![^!].*)/m =~ body
174
+ body1 = $1
175
+ body2 = $2
176
+ elsif /^![^!]/ !~ body
177
+ body1 = body
178
+ body2 = ''
196
179
  else
197
- section = '' unless section
198
- section << l
180
+ body1 = ''
181
+ body2 = body
182
+ end
183
+
184
+ unless body1.empty?
185
+ current_section = @sections.pop
186
+ if current_section then
187
+ body1 = "#{current_section.to_src.sub( /\n+\Z/, '' )}\n\n#{body1}"
188
+ end
189
+ @sections << WikiSection::new( body1, author )
190
+ end
191
+ section = nil
192
+ body2.each_line do |l|
193
+ case l
194
+ when /^\![^!]/
195
+ @sections << WikiSection::new( section, author ) if section
196
+ section = l
197
+ else
198
+ section = '' unless section
199
+ section << l
200
+ end
199
201
  end
202
+ @sections << WikiSection::new( section, author ) if section
203
+ @last_modified = Time.now
204
+ self
200
205
  end
201
- @sections << WikiSection::new( section, author ) if section
202
- @last_modified = Time.now
203
- self
204
- end
205
206
 
206
- def add_section(subtitle, body)
207
- @sections << WikiSection::new("! #{subtitle}\n#{body}")
208
- @sections.size
207
+ def add_section(subtitle, body)
208
+ @sections << WikiSection::new("! #{subtitle}\n#{body}")
209
+ @sections.size
210
+ end
209
211
  end
210
212
  end
211
213
  end