Class: TDiary::Style::WikiDiary
- Inherits:
-
Object
- Object
- TDiary::Style::WikiDiary
- Defined in:
- lib/tdiary/style/wiki.rb
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.
151 152 153 154 155 |
# File 'lib/tdiary/style/wiki.rb', line 151 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
198 199 200 201 |
# File 'lib/tdiary/style/wiki.rb', line 198 def add_section(subtitle, body) @sections << WikiSection::new("! #{subtitle}\n#{body}") @sections.size end |
#append(body, author = nil) ⇒ Object
161 162 163 164 165 166 167 168 169 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 |
# File 'lib/tdiary/style/wiki.rb', line 161 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
157 158 159 |
# File 'lib/tdiary/style/wiki.rb', line 157 def style 'Wiki' end |