Class: NoraMark::Html::ParagraphWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/nora_mark/html/paragraph_writer.rb

Instance Method Summary collapse

Constructor Details

#initialize(generator) ⇒ ParagraphWriter

Returns a new instance of ParagraphWriter.



6
7
8
9
10
11
12
13
14
15
16
17
18
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
# File 'lib/nora_mark/html/paragraph_writer.rb', line 6

def initialize(generator)
  @generator = generator
  @context = generator.context
  @writer_set = { use_paragraph_group: {
    Paragraph =>
    TagWriter.create('p', @generator, chop_last_space: true,
                                      node_preprocessor: proc do |node|
                                                           first = node.children[0]
                                                           if first.kind_of? Text
                                                             first.content.sub!(/^[[:space:]]+/, '')
                                                             add_class(node, 'noindent') if first.content =~ /^(「|『|()/ # TODO: should be plaggable
                                                           end
                                                           node
                                                         end),
    ParagraphGroup =>
    TagWriter.create("div", @generator,
                     node_preprocessor: proc do |node|
                       add_class node, 'pgroup'
                       node.no_tag = true unless @context.enable_pgroup
                       node
                     end)
  },
                  default: {
                    Paragraph =>
                  TagWriter.create(nil, @generator, chop_last_space: true,
                                                    node_preprocessor: proc do |node|
                                                                         node.no_tag = true
                                                                         node
                                                                       end),
                    ParagraphGroup =>
    TagWriter.create("p", @generator,
                     node_preprocessor: proc do |node|
                       node.children = node.children.inject([]) do |memo, n|
                         memo << inline('br', body_empty: true, line_no: memo.last.line_no) if !memo.last.nil? && memo.last.kind_of?(Paragraph) && n.kind_of?(Paragraph)
                         memo << n
                       end
                       node
                     end)
                  } }
end

Instance Method Details

#write(node) ⇒ Object



47
48
49
50
51
# File 'lib/nora_mark/html/paragraph_writer.rb', line 47

def write(node)
  writer_set = @writer_set[@context.paragraph_style]
  writer_set = @writer_set[:default] if writer_set.nil?
  writer_set[node.class].write(node)
end