Class: TDiary::Style::RDSection
- Inherits:
-
Object
- Object
- TDiary::Style::RDSection
- Includes:
- RD
- Defined in:
- lib/tdiary/style/rd.rb
Constant Summary
Constants included from RD
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#body_to_html ⇒ Object
readonly
Returns the value of attribute body_to_html.
-
#categories ⇒ Object
Returns the value of attribute categories.
-
#stripped_subtitle ⇒ Object
readonly
Returns the value of attribute stripped_subtitle.
-
#stripped_subtitle_to_html ⇒ Object
readonly
Returns the value of attribute stripped_subtitle_to_html.
-
#subtitle ⇒ Object
Returns the value of attribute subtitle.
-
#subtitle_to_html ⇒ Object
readonly
Returns the value of attribute subtitle_to_html.
Instance Method Summary collapse
- #body ⇒ Object
- #body=(str) ⇒ Object
- #html(date, idx, opt, mode = :HTML) ⇒ Object
-
#initialize(fragment, author = nil) ⇒ RDSection
constructor
A new instance of RDSection.
- #to_src ⇒ Object
Constructor Details
#initialize(fragment, author = nil) ⇒ RDSection
Returns a new instance of RDSection.
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/tdiary/style/rd.rb', line 197 def initialize( fragment, = nil ) @author = if /\A=(?!=)/ =~ fragment then @subtitle, @body = fragment.split( /\n/, 2 ) @subtitle.sub!( /^\=\s*/, '' ) else @subtitle = nil @body = fragment.dup end @body = @body || '' @body.sub!( /[\n\r]+\Z/, '' ) @body << "\n\n" @categories = get_categories @stripped_subtitle = strip_subtitle @subtitle_to_html = manufacture(@subtitle, true) @stripped_subtitle_to_html = manufacture(@stripped_subtitle, true) @body_to_html = manufacture(@body, false) end |
Instance Attribute Details
#author ⇒ Object (readonly)
Returns the value of attribute author.
194 195 196 |
# File 'lib/tdiary/style/rd.rb', line 194 def @author end |
#body_to_html ⇒ Object (readonly)
Returns the value of attribute body_to_html.
195 196 197 |
# File 'lib/tdiary/style/rd.rb', line 195 def body_to_html @body_to_html end |
#categories ⇒ Object
Returns the value of attribute categories.
194 195 196 |
# File 'lib/tdiary/style/rd.rb', line 194 def categories @categories end |
#stripped_subtitle ⇒ Object (readonly)
Returns the value of attribute stripped_subtitle.
194 195 196 |
# File 'lib/tdiary/style/rd.rb', line 194 def stripped_subtitle @stripped_subtitle end |
#stripped_subtitle_to_html ⇒ Object (readonly)
Returns the value of attribute stripped_subtitle_to_html.
195 196 197 |
# File 'lib/tdiary/style/rd.rb', line 195 def stripped_subtitle_to_html @stripped_subtitle_to_html end |
#subtitle ⇒ Object
Returns the value of attribute subtitle.
194 195 196 |
# File 'lib/tdiary/style/rd.rb', line 194 def subtitle @subtitle end |
#subtitle_to_html ⇒ Object (readonly)
Returns the value of attribute subtitle_to_html.
195 196 197 |
# File 'lib/tdiary/style/rd.rb', line 195 def subtitle_to_html @subtitle_to_html end |
Instance Method Details
#body ⇒ Object
232 233 234 |
# File 'lib/tdiary/style/rd.rb', line 232 def body @body.dup end |
#body=(str) ⇒ Object
228 229 230 |
# File 'lib/tdiary/style/rd.rb', line 228 def body=(str) @body = str end |
#html(date, idx, opt, mode = :HTML) ⇒ Object
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/tdiary/style/rd.rb', line 253 def html( date, idx, opt, mode = :HTML) if mode == :CHTML visitor = RD2tDiaryCHTMLVistor.new( date, idx, opt, @author) section_open = "<%=section_enter_proc( Time::at( #{date.to_i} ))%>\n" section_close = "<%=section_leave_proc( Time::at( #{date.to_i} ))%>\n" else visitor = RD2tDiaryVisitor.new( date, idx, opt, @author ) section_open = %Q[<div class="section">\n<%=section_enter_proc( Time::at( #{date.to_i} ))%>\n] section_close = "<%=section_leave_proc( Time::at( #{date.to_i} ))%>\n</div>\n" end src = to_src.split(/^/) src.unshift("=begin\n").push("=end\n") tree = RDTree.new( src, nil, nil) begin tree.parse rescue ParseError raise SyntaxError, $!. end r = "#{section_open}#{visitor.visit( tree )}#{section_close}" end |
#to_src ⇒ Object
247 248 249 250 251 |
# File 'lib/tdiary/style/rd.rb', line 247 def to_src r = '' r << "= #{@subtitle}\n" if @subtitle r << @body end |