Class: TDiary::Style::WikiSection

Inherits:
Object
  • Object
show all
Defined in:
lib/tdiary/style/wiki.rb

Instance Method Summary collapse

Constructor Details

#initialize(fragment, author = nil) ⇒ WikiSection

Returns a new instance of WikiSection.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/tdiary/style/wiki.rb', line 18

def initialize( fragment, author = nil )
  @author = 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



46
47
48
49
# File 'lib/tdiary/style/wiki.rb', line 46

def categories=(categories)
  @subtitle = @subtitle ? (categories_to_string + @stripped_subtitle) : nil
  @stripped_subtitle = strip_subtitle
end

#do_html4(date, idx, opt) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/tdiary/style/wiki.rb', line 57

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



41
42
43
44
# File 'lib/tdiary/style/wiki.rb', line 41

def subtitle=(subtitle)
  @subtitle = subtitle ? (categories_to_string + subtitle) : nil
  @stripped_subtitle = strip_subtitle
end

#to_srcObject



51
52
53
54
55
# File 'lib/tdiary/style/wiki.rb', line 51

def to_src
  r = ''
  r << "! #{@subtitle}\n" if @subtitle
  r << @body
end