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
@@ -10,182 +10,184 @@
|
|
10
10
|
# You can redistribute it and/or modify it under GPL2.
|
11
11
|
#
|
12
12
|
module TDiary
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
if
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
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
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
62
|
-
|
63
|
-
if @stripped_subtitle then
|
64
|
-
s += "[#{@author}]" if @author
|
51
|
+
def categories=(categories)
|
52
|
+
@categories = categories
|
65
53
|
cat_str = ""
|
66
|
-
|
67
|
-
|
54
|
+
categories.each {|cat|
|
55
|
+
cat_str << "[#{cat}]"
|
68
56
|
}
|
69
57
|
cat_str << " " unless cat_str.empty?
|
70
|
-
|
71
|
-
|
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
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
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
|
-
|
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
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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
|
-
|
103
|
-
|
104
|
-
|
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
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
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
|
-
|
119
|
-
|
120
|
-
|
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
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
113
|
+
def strip_subtitle
|
114
|
+
return nil unless @subtitle
|
115
|
+
@subtitle.sub( /^(\[(.*?)\])+\s*/, '' )
|
116
|
+
end
|
126
117
|
end
|
127
118
|
|
128
|
-
|
129
|
-
|
130
|
-
|
119
|
+
class TdiaryDiary
|
120
|
+
include BaseDiary
|
121
|
+
include CategorizableDiary
|
131
122
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
@
|
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
|
-
|
142
|
-
|
143
|
-
|
144
|
-
sec.body = body
|
145
|
-
@sections << sec
|
146
|
-
@sections.size
|
147
|
-
end
|
129
|
+
def style
|
130
|
+
'tDiary'
|
131
|
+
end
|
148
132
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
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
|
-
|
158
|
-
|
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
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
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
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
r << %Q[#{
|
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
|
189
|
+
r
|
187
190
|
end
|
188
|
-
r
|
189
191
|
end
|
190
192
|
end
|
191
193
|
end
|
data/tdiary/style/wiki_style.rb
CHANGED
@@ -13,199 +13,201 @@
|
|
13
13
|
require 'hikidoc'
|
14
14
|
|
15
15
|
module TDiary
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
43
|
+
def subtitle=(subtitle)
|
44
|
+
@subtitle = subtitle ? (categories_to_string + subtitle) : nil
|
45
|
+
@stripped_subtitle = strip_subtitle
|
46
|
+
end
|
57
47
|
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
-
|
53
|
+
def to_src
|
54
|
+
r = ''
|
55
|
+
r << "! #{@subtitle}\n" if @subtitle
|
56
|
+
r << @body
|
57
|
+
end
|
72
58
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
# $
|
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
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
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
|
-
|
99
|
-
|
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
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
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
|
-
|
129
|
-
|
130
|
-
|
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
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
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
|
-
|
156
|
-
|
157
|
-
|
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
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
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
|
-
|
166
|
-
|
167
|
-
|
156
|
+
class WikiDiary
|
157
|
+
include BaseDiary
|
158
|
+
include CategorizableDiary
|
168
159
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
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
|
-
|
184
|
-
|
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
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
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
|
-
|
198
|
-
|
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
|
-
|
207
|
-
|
208
|
-
|
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
|