Class: TDiary::Style::GfmSection
- Inherits:
-
Object
- Object
- TDiary::Style::GfmSection
- Defined in:
- lib/tdiary/style/gfm.rb
Instance Method Summary collapse
- #categories=(categories) ⇒ Object
- #do_html4(date, idx, opt) ⇒ Object
-
#initialize(fragment, author = nil) ⇒ GfmSection
constructor
A new instance of GfmSection.
- #subtitle=(subtitle) ⇒ Object
- #to_src ⇒ Object
Constructor Details
#initialize(fragment, author = nil) ⇒ GfmSection
Returns a new instance of GfmSection.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/tdiary/style/gfm.rb', line 9 def initialize(fragment, = nil) @author = @subtitle, @body = fragment.split(/\n/, 2) @subtitle.sub!(/^\#\s*/,'') @body ||= '' @categories = get_categories @stripped_subtitle = strip_subtitle @subtitle_to_html = @subtitle ? to_html('# ' + @subtitle).gsub(/\A<h\d>|<\/h\d>\z/io, '') : nil @stripped_subtitle_to_html = @stripped_subtitle ? to_html('# ' + @stripped_subtitle).gsub(/\A<h\d>|<\/h\d>\z/io, '') : nil @body_to_html = to_html(@body) end |
Instance Method Details
#categories=(categories) ⇒ Object
28 29 30 31 |
# File 'lib/tdiary/style/gfm.rb', line 28 def categories=(categories) @subtitle = "#{categories_to_string} " + (strip_subtitle || '') @strip_subtitle = strip_subtitle end |
#do_html4(date, idx, opt) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/tdiary/style/gfm.rb', line 39 def do_html4(date, idx, opt) subtitle = to_html('# ' + @subtitle) subtitle.sub!( %r!<h3>(.+?)</h3>!m ) do "<h3><%= subtitle_proc( Time.at( #{date.to_i} ), #{$1.dump.gsub( /%/, '\\\\045' )} ) %></h3>" end if opt['multi_user'] and @author then subtitle.sub!(/<\/h3>/,%Q|[#{@author}]</h3>|) end r = subtitle r << @body_to_html end |
#subtitle=(subtitle) ⇒ Object
23 24 25 26 |
# File 'lib/tdiary/style/gfm.rb', line 23 def subtitle=(subtitle) @subtitle = (subtitle || '').sub(/^# /,"\##{categories_to_string} ") @strip_subtitle = strip_subtitle end |
#to_src ⇒ Object
33 34 35 36 37 |
# File 'lib/tdiary/style/gfm.rb', line 33 def to_src r = '' r << "\# #{@subtitle}\n" if @subtitle r << @body end |