Class: TDiary::Style::WikiSection
Instance Method Summary collapse
- #categories=(categories) ⇒ Object
- #do_html4(date, idx, opt) ⇒ Object
-
#initialize(fragment, author = nil) ⇒ WikiSection
constructor
A new instance of WikiSection.
- #subtitle=(subtitle) ⇒ Object
- #to_src ⇒ Object
Constructor Details
#initialize(fragment, author = nil) ⇒ WikiSection
Returns a new instance of WikiSection.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/tdiary/style/wiki.rb', line 19 def initialize( fragment, = nil ) @author = if fragment[0] == ?! 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 = @subtitle ? to_html( "!#{@subtitle}" ) : '' @body_to_html = to_html( @body ) @html = @subtitle_to_html + "\n" + @body_to_html + "\n" @subtitle_to_html = strip_headings( @subtitle_to_html ) @body_to_html = strip_headings( @body_to_html ) @stripped_subtitle_to_html = @stripped_subtitle ? strip_headings( to_html( "!#{@stripped_subtitle}" ) ) : nil end |
Instance Method Details
#categories=(categories) ⇒ Object
47 48 49 50 |
# File 'lib/tdiary/style/wiki.rb', line 47 def categories=(categories) @subtitle = @subtitle ? (categories_to_string + @stripped_subtitle) : nil @stripped_subtitle = strip_subtitle end |
#do_html4(date, idx, opt) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/tdiary/style/wiki.rb', line 58 def do_html4( date, idx, opt ) subtitle = false r = @html.lstrip r.sub!( %r!<h3>(.+?)</h3>!m ) do subtitle = true "<h3><%= subtitle_proc( Time.at( #{date.to_i} ), #{$1.dump.gsub( /%/, '\\\\045' )} ) %></h3>" end r.sub!( %r!^<p>(.+?)</p>$!m ) do "<p><%= subtitle_proc( Time.at( #{date.to_i} ), #{$1.dump.gsub( /%/, '\\\\045' )} ) %></p>" end unless subtitle r.gsub( /<(\/)?tdiary-section>/, '<\\1p>' ) end |
#subtitle=(subtitle) ⇒ Object
42 43 44 45 |
# File 'lib/tdiary/style/wiki.rb', line 42 def subtitle=(subtitle) @subtitle = subtitle ? (categories_to_string + subtitle) : nil @stripped_subtitle = strip_subtitle end |
#to_src ⇒ Object
52 53 54 55 56 |
# File 'lib/tdiary/style/wiki.rb', line 52 def to_src r = '' r << "! #{@subtitle}\n" if @subtitle r << @body end |