Module: ODDB::View::ChapterMethods

Included in:
Chapter, ChapterEditor
Defined in:
src/view/chapter.rb

Constant Summary

PRE_STYLE =
'font-family: Courier New, monospace; font-size: 12px;'
PAR_STYLE =
'padding-bottom: 4px; white-space: normal; line-height: 1.4em;'
SUB_STYLE =
'font-style: italic'
TABLE_STYLE =
'border-collapse: collapse;'
TD_STYLE =
'padding: 4px; vertical-align: top;'

Instance Method Summary (collapse)

Instance Method Details

- (Object) formats(context, paragraph)



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'src/view/chapter.rb', line 19

def formats(context, paragraph)
  res = ''
  txt = u paragraph.text
  paragraph.formats.each { |format|
    tag = :span
    style = [] 
    attrs = {}
    if(format.italic?)
      style << 'font-style:italic;'
    end
    if(format.bold?)
      style << 'font-weight:bold;'
    end
    if(format.superscript?)
      tag = :sup
      style << 'line-height: 0em;'
      if(paragraph.preformatted?)
        style << 'font-size: 12px;'
      end
    end
    if(format.subscript?)
      tag = :sub
      style << 'line-height: 0em'
    end
    escape_method = (format.symbol?) ? :escape_symbols : :escape
    str = self.send(escape_method, txt[format.range]) 
    if(style.empty? && tag == :span)
      res << str
    else
      attrs.store('style', style.join(' '))
      res << context.send(tag, attrs) { 
        str
      }
    end
  }
  if(paragraph.preformatted?)
    context.pre({ 'style' => self.class::PRE_STYLE }) { res }
  else
    ## this must be an inline element, to enable starting 
    ## paragraphs on the same line as the section-subheading
    context.span({ 'style' => self.class::PAR_STYLE }) { 
      res.gsub("\n", context.br) } << context.br
  end
end

- (Object) heading(context)



63
64
65
# File 'src/view/chapter.rb', line 63

def heading(context)
  context.h3 { self.escape(@value.heading) }
end

- (Object) paragraphs(context, paragraphs)



82
83
84
85
86
87
88
89
90
91
92
93
# File 'src/view/chapter.rb', line 82

def paragraphs(context, paragraphs)
  attr = { 'style' => self.class::PAR_STYLE }
  paragraphs.collect { |paragraph|
    if(paragraph.is_a? Text::ImageLink)
      context.p(attr) { context.img(paragraph.attributes) }
    elsif(paragraph.is_a? Text::Table)
      table(context, paragraph)
    else
      formats(context, paragraph)
    end
  }.join
end

- (Object) sections(context, sections)



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'src/view/chapter.rb', line 66

def sections(context, sections)
  section_attr = { 'style' => @lookandfeel.section_style }
  subhead_attr = { 'style' => self.class::SUB_STYLE }
  sections.collect { |section|
    context.p(section_attr) { 
      head = context.span(subhead_attr) {
        self.escape(section.subheading) }
      if(/\n\s*$/u.match(section.subheading))
        head << context.br
      elsif(!section.subheading.strip.empty?)
        head << "&nbsp;"
      end
      head << paragraphs(context, section.paragraphs)
    } 
  }.join
end

- (Object) table(context, table)



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'src/view/chapter.rb', line 94

def table(context, table)
  context.table('class' => "chapter") {
    table.rows.collect { |row|
      context.tr {
        row.collect { |cell|
          context.td('colspan' => cell.col_span) { 
            formats(context, cell)
          }
        }.join
      }
    }.join
  }
end