Class: TDiary::Style::WikiDiary
Instance Method Summary collapse
- #add_section(subtitle, body) ⇒ Object
- #append(body, author = nil) ⇒ Object
-
#initialize(date, title, body, modified = Time.now) ⇒ WikiDiary
constructor
A new instance of WikiDiary.
- #style ⇒ Object
Constructor Details
#initialize(date, title, body, modified = Time.now) ⇒ WikiDiary
Returns a new instance of WikiDiary.
160 161 162 163 164 |
# File 'lib/tdiary/style/wiki.rb', line 160 def initialize( date, title, body, modified = Time.now ) init_diary replace( date, title, body ) @last_modified = modified end |
Instance Method Details
#add_section(subtitle, body) ⇒ Object
207 208 209 210 |
# File 'lib/tdiary/style/wiki.rb', line 207 def add_section(subtitle, body) @sections << WikiSection::new("! #{subtitle}\n#{body}") @sections.size end |
#append(body, author = nil) ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/tdiary/style/wiki.rb', line 170 def append( body, = nil ) # body1 is a section starts without subtitle. # body2 are sections starts with subtitle. if /(.*?)(^![^!].*)/m =~ body body1 = $1 body2 = $2 elsif /^![^!]/ !~ body body1 = body body2 = '' else body1 = '' body2 = body end unless body1.empty? current_section = @sections.pop if current_section then body1 = "#{current_section.to_src.sub( /\n+\Z/, '' )}\n\n#{body1}" end @sections << WikiSection::new( body1, ) end section = nil body2.each_line do |l| case l when /^\![^!]/ @sections << WikiSection::new( section, ) if section section = l else section = '' unless section section << l end end @sections << WikiSection::new( section, ) if section @last_modified = Time.now self end |
#style ⇒ Object
166 167 168 |
# File 'lib/tdiary/style/wiki.rb', line 166 def style 'Wiki' end |