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.



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

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



42
43
44
45
46
# File 'lib/typedown/section.rb', line 42

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

Instance Method Details

#bodyObject



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

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

#docObject



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

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

#dummy?Boolean

Returns:

  • (Boolean)


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

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

#subsectionsObject



38
39
40
# File 'lib/typedown/section.rb', line 38

def subsections
  @sections || []
end

#titleObject



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

def title
  @title || ""
end