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.



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

def initialize(configuration)
  @configuration = configuration
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



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

def configuration
  @configuration
end

Class Method Details

.render!(*args) ⇒ Object



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

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

Instance Method Details

#all_urlsObject



70
71
72
73
74
75
76
77
78
79
# File 'lib/emmett/document_manager.rb', line 70

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



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

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

#indexed_documentsObject



30
31
32
33
34
35
# File 'lib/emmett/document_manager.rb', line 30

def indexed_documents
  @indexed_documents ||= inner_documents.inject({}) do |acc, document|
    acc[document.short_name] = document
    acc
  end
end

#inner_documentsObject



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

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

#render(renderer) ⇒ Object



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

def render(renderer)
  process_sections
  render_index renderer
  render_documents renderer
end

#render!Object



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

def render!
  Renderer.new(configuration).tap do |renderer|
    renderer.prepare_output
    all_groups = sections.map(&:groups).flatten.sort_by(&:name).uniq
    renderer.global_context = {
      sections:  sections.map(&:to_hash),
      groups:    all_groups.map(&:to_hash),
      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

#sectionsObject



37
38
39
# File 'lib/emmett/document_manager.rb', line 37

def sections
  @sections ||= Hash.new.tap { |s| process_sections s }.values
end