Class: Typedown::Section

Inherits:
String
  • Object
show all
Defined in:
lib/typedown/section.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, body) ⇒ Section

Returns a new instance of Section.



4
5
6
7
8
9
10
11
# File 'lib/typedown/section.rb', line 4

def initialize title, body
  @title = (title || "").strip
  @body = ""
  @sections = []
  if body
    @body, @sections = sectionize(Shorthand.process(body))
  end
end

Class Method Details

.sectionize(body, title = nil) ⇒ Object



40
41
42
43
44
# File 'lib/typedown/section.rb', line 40

def self.sectionize body, title = nil
  s = nil
  s = Section.new title || "", body || ""
  s.dummy? ? s.subsections[0] : s
end

Instance Method Details

#bodyObject



21
22
23
24
25
26
27
28
# File 'lib/typedown/section.rb', line 21

def body
  b = Document.new(@body || "")
  b << "\n\n"
  subsections.each do |s|
    b << s.doc
  end
  b
end

#docObject



30
31
32
33
34
# File 'lib/typedown/section.rb', line 30

def doc
  d = Document.new "! #{title}\n\n"
  d << body.gsub(/^(!+ )/, '!\0')
  d
end

#dummy?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/typedown/section.rb', line 13

def dummy?
  subsections.length == 1 && (title.strip.empty? || title.tr("!","").strip == subsections[0].title.tr("!","").strip) && (!@body || @body.strip.empty?)
end

#subsectionsObject



36
37
38
# File 'lib/typedown/section.rb', line 36

def subsections
  @sections || []
end

#titleObject



17
18
19
# File 'lib/typedown/section.rb', line 17

def title
  @title || ""
end