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.
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/tdiary/style/rd.rb', line 181 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.
178 179 180 |
# File 'lib/tdiary/style/rd.rb', line 178 def @author end |
#body_to_html ⇒ Object (readonly)
Returns the value of attribute body_to_html.
179 180 181 |
# File 'lib/tdiary/style/rd.rb', line 179 def body_to_html @body_to_html end |
#categories ⇒ Object
Returns the value of attribute categories.
178 179 180 |
# File 'lib/tdiary/style/rd.rb', line 178 def categories @categories end |
#stripped_subtitle ⇒ Object (readonly)
Returns the value of attribute stripped_subtitle.
178 179 180 |
# File 'lib/tdiary/style/rd.rb', line 178 def stripped_subtitle @stripped_subtitle end |
#stripped_subtitle_to_html ⇒ Object (readonly)
Returns the value of attribute stripped_subtitle_to_html.
179 180 181 |
# File 'lib/tdiary/style/rd.rb', line 179 def stripped_subtitle_to_html @stripped_subtitle_to_html end |
#subtitle ⇒ Object
Returns the value of attribute subtitle.
178 179 180 |
# File 'lib/tdiary/style/rd.rb', line 178 def subtitle @subtitle end |
#subtitle_to_html ⇒ Object (readonly)
Returns the value of attribute subtitle_to_html.
179 180 181 |
# File 'lib/tdiary/style/rd.rb', line 179 def subtitle_to_html @subtitle_to_html end |
Instance Method Details
#body ⇒ Object
216 217 218 |
# File 'lib/tdiary/style/rd.rb', line 216 def body @body.dup end |
#body=(str) ⇒ Object
212 213 214 |
# File 'lib/tdiary/style/rd.rb', line 212 def body=(str) @body = str end |
#html(date, idx, opt, mode = :HTML) ⇒ Object
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/tdiary/style/rd.rb', line 237 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
231 232 233 234 235 |
# File 'lib/tdiary/style/rd.rb', line 231 def to_src r = '' r << "= #{@subtitle}\n" if @subtitle r << @body end |