Class: Muwu::RenderConcat

Inherits:
Object
  • Object
show all
Defined in:
lib/muwu/render_concat/render_concat.rb

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ RenderConcat

Returns a new instance of RenderConcat.



5
6
7
8
9
10
# File 'lib/muwu/render_concat/render_concat.rb', line 5

def initialize(project)
  @output_path = project.working_directory
  @output_filename = project.html_basename + '.md'
  @project = project
  @manifest = project.manifest
end

Instance Method Details

#renderObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/muwu/render_concat/render_concat.rb', line 16

def render
  destination = File.join(@output_path, @output_filename)
  File.open(destination, 'w') do |f|
    @manifest.text_blocks.each do |text|
      text.sections.each do |text_item|
        render_text_item(f, text_item)
      end
    end
  end
end

#render_text_item(f, text_item) ⇒ Object



28
29
30
31
32
# File 'lib/muwu/render_concat/render_concat.rb', line 28

def render_text_item(f, text_item)
  render_text_item_head(f, text_item)
  render_text_item_source(f, text_item)
  render_text_item_sections(f, text_item)
end

#render_text_item_head(f, text_item) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/muwu/render_concat/render_concat.rb', line 35

def render_text_item_head(f, text_item)
  f.puts '# ' + text_item.numbering.join('.')
  if heading_origin_is_basename_or_outline(text_item)
    f.puts '# ' + text_item.heading
    f.puts "\n"
  end
end

#render_text_item_sections(f, text_item) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/muwu/render_concat/render_concat.rb', line 44

def render_text_item_sections(f, text_item)
  if text_item.does_have_child_sections
    text_item.sections.each do |ti|
      render_text_item(f, ti)
    end
    render_text_item_spacer(f, text_item)
  end
end

#render_text_item_source(f, text_item) ⇒ Object



54
55
56
57
58
59
# File 'lib/muwu/render_concat/render_concat.rb', line 54

def render_text_item_source(f, text_item)
  if text_item.source_file_does_exist
    f.puts text_item.source.strip
  end
  render_text_item_spacer(f, text_item)
end

#render_text_item_spacer(f, text_item) ⇒ Object



62
63
64
# File 'lib/muwu/render_concat/render_concat.rb', line 62

def render_text_item_spacer(f, text_item)
  f.puts "\n\n\n\n"
end