Class: TDiary::Style::TdiaryDiary
- Inherits:
-
Object
- Object
- TDiary::Style::TdiaryDiary
- Defined in:
- lib/tdiary/style/tdiary.rb
Instance Method Summary collapse
- #add_section(subtitle, body) ⇒ Object
- #append(body, author = nil) ⇒ Object
-
#initialize(date, title, body, modified = Time::now) ⇒ TdiaryDiary
constructor
A new instance of TdiaryDiary.
- #style ⇒ Object
- #to_chtml(opt) ⇒ Object
- #to_html4(opt) ⇒ Object
Constructor Details
#initialize(date, title, body, modified = Time::now) ⇒ TdiaryDiary
Returns a new instance of TdiaryDiary.
118 119 120 121 122 |
# File 'lib/tdiary/style/tdiary.rb', line 118 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
137 138 139 140 141 142 143 |
# File 'lib/tdiary/style/tdiary.rb', line 137 def add_section(subtitle, body) sec = TdiarySection::new("\n\n ") sec.subtitle = subtitle sec.body = body @sections << sec @sections.size end |
#append(body, author = nil) ⇒ Object
128 129 130 131 132 133 134 135 |
# File 'lib/tdiary/style/tdiary.rb', line 128 def append( body, = nil ) body.gsub( /\r/, '' ).split( /\n\n+/ ).each do |fragment| section = TdiarySection::new( fragment, ) @sections << section if section end @last_modified = Time::now self end |
#style ⇒ Object
124 125 126 |
# File 'lib/tdiary/style/tdiary.rb', line 124 def style 'tDiary' end |
#to_chtml(opt) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/tdiary/style/tdiary.rb', line 167 def to_chtml( opt ) r = '' each_section do |section| r << %Q[<%= section_enter_proc( Time::at( #{date.to_i} ) ) %>\n] if section.subtitle then r << %Q[<H3><%= subtitle_proc( Time::at( #{date.to_i} ), #{section.subtitle.dump.gsub( /%/, '\\\\045' )} ) %></H3>\n] end if /^</ =~ section.body then r << section.body elsif section.subtitle r << %Q[<P>#{section.body.lines.collect{|l|l.chomp.sub( /^[ ]/u, '' )}.join( "</P>\n<P>" )}</P>\n] else r << %Q[<P><%= subtitle_proc( Time::at( #{date.to_i} ), nil ) %>] r << %Q[#{section.body.lines.collect{|l|l.chomp.sub( /^[ ]/u, '' )}.join( "</P>\n<P>" )}</P>\n] end r << %Q[<%= section_leave_proc( Time::at( #{date.to_i} ) ) %>\n] end r end |
#to_html4(opt) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/tdiary/style/tdiary.rb', line 145 def to_html4( opt ) r = '' each_section do |section| r << %Q[<div class="section">\n] r << %Q[<%= section_enter_proc( Time::at( #{date.to_i} ) ) %>\n] if section.subtitle then r << %Q[<h3><%= subtitle_proc( Time::at( #{date.to_i} ), #{section.subtitle.dump.gsub( /%/, '\\\\045' )} ) %></h3>\n] end if /^</ =~ section.body then r << %Q[#{section.body}] elsif section.subtitle r << %Q[<p>#{section.body.lines.collect{|l|l.chomp.sub( /^[ ]/u, '')}.join( "</p>\n<p>" )}</p>\n] else r << %Q[<p><%= subtitle_proc( Time::at( #{date.to_i} ), nil ) %>] r << %Q[#{section.body.lines.collect{|l|l.chomp.sub( /^[ ]/u, '' )}.join( "</p>\n<p>" )}</p>] end r << %Q[<%= section_leave_proc( Time::at( #{date.to_i} ) ) %>\n] r << %Q[</div>] end r end |