Class: Emmett::DocumentManager

Inherits:
Object
  • Object
show all
Defined in:
lib/emmett/document_manager.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ DocumentManager

Returns a new instance of DocumentManager.



13
14
15
# File 'lib/emmett/document_manager.rb', line 13

def initialize(configuration)
  @configuration = configuration
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



11
12
13
# File 'lib/emmett/document_manager.rb', line 11

def configuration
  @configuration
end

Class Method Details

.render!(*args) ⇒ Object



7
8
9
# File 'lib/emmett/document_manager.rb', line 7

def self.render!(*args)
  new(*args).render!
end

Instance Method Details

#all_urlsObject



67
68
69
70
71
72
73
74
75
76
# File 'lib/emmett/document_manager.rb', line 67

def all_urls
  out = inner_documents.inject({}) do |acc, current|
    acc[current.title] = current.http_requests.inject({}) do |ia, req|
      ia[req.section] ||= []
      ia[req.section] << req.request_line
      ia
    end
    acc
  end
end

#index_documentObject



17
18
19
# File 'lib/emmett/document_manager.rb', line 17

def index_document
  @index_document ||= render_path(configuration.index_page, :index)
end

#inner_documentsObject



21
22
23
24
25
26
27
# File 'lib/emmett/document_manager.rb', line 21

def inner_documents
  @inner_documents ||= begin
    Dir[File.join(configuration.section_dir, "**/*.md")].map do |path|
      render_path path
    end
  end
end


29
30
31
32
33
34
35
36
37
38
39
# File 'lib/emmett/document_manager.rb', line 29

def inner_links
  @inner_links ||= inner_documents.map do |doc|
    {
      doc:      doc,
      title:    doc.title,
      short:    doc.short_name,
      link:     "./#{doc.short_name}.html",
      sections: doc.iterable_section_mapping
    }
  end.sort_by { |r| r[:title].downcase }
end

#render(renderer) ⇒ Object



51
52
53
54
# File 'lib/emmett/document_manager.rb', line 51

def render(renderer)
  render_index renderer
  render_documents renderer
end

#render!Object



56
57
58
59
60
61
62
63
64
65
# File 'lib/emmett/document_manager.rb', line 56

def render!
  Renderer.new(configuration).tap do |renderer|
    renderer.prepare_output
    renderer.global_context = {
      links:     inner_links,
      site_name: configuration.name
    }
    render renderer
  end
end

#render_documents(renderer) ⇒ Object



45
46
47
48
49
# File 'lib/emmett/document_manager.rb', line 45

def render_documents(renderer)
  inner_documents.each do |document|
    render_document renderer, :section, document
  end
end

#render_index(renderer) ⇒ Object



41
42
43
# File 'lib/emmett/document_manager.rb', line 41

def render_index(renderer)
  render_document renderer, :index, index_document
end