Class: Adocsite::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/adocsite/engine.rb

Constant Summary collapse

'.html'
OUTPUT_DOCUMENT_EXTENSION =
'.html'
LOCATION_PAGE =
''
LOCATION_ARTICLE =
''
LOCATION_CATEGORY =
''

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEngine

Returns a new instance of Engine.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/adocsite/engine.rb', line 26

def initialize
  # Internal stuff
  @page_context = Array.new
  @request_processing_queue = Hash.new

  # This is hashmap of Category objects.
  @categories = Hash.new

  @content_loader = ContentLoader.new
  @content_loader.load_assets

  @templates = Templates.new
  @templates.load_assets

  build_categories

  @site = Site.new(self)
  @site.prepare_output
  @site.copy_content
end

Instance Attribute Details

#categoriesObject (readonly)

Returns the value of attribute categories.



25
26
27
# File 'lib/adocsite/engine.rb', line 25

def categories
  @categories
end

#content_loaderObject (readonly)

Returns the value of attribute content_loader.



25
26
27
# File 'lib/adocsite/engine.rb', line 25

def content_loader
  @content_loader
end

#templatesObject (readonly)

Returns the value of attribute templates.



25
26
27
# File 'lib/adocsite/engine.rb', line 25

def templates
  @templates
end

Instance Method Details

#build(layout = "default") ⇒ Object



113
114
115
116
117
# File 'lib/adocsite/engine.rb', line 113

def build(layout = "default")
  home = Request.new
  add_to_processing_queue(home)
  process_requests(layout)
end

#get_next_from_processing_queueObject



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/adocsite/engine.rb', line 77

def get_next_from_processing_queue
  if @request_processing_queue.empty?
    nil
  else
  # Find first element that is not yet processed
    idx = @request_processing_queue.values.index {|request_processing| !request_processing.rendered}
    if idx
    @request_processing_queue.values[idx]
    else
      nil
    end
  end
end


119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/adocsite/engine.rb', line 119

def sitenav(request)
  # remember to actually generate this document later
  add_to_processing_queue(request)

  # now just create link text and return it to caller
  site_root = Adocsite::config[:SITE_URL]
  if request.type == "home"
    path = '/'
  elsif request.type == "page"
    path = LOCATION_PAGE + request.name + LINK_DOCUMENT_EXTENSION
  elsif request.type == "article"
    path = LOCATION_ARTICLE + request.name + LINK_DOCUMENT_EXTENSION
  elsif request.type == "category"
    path = LOCATION_CATEGORY + request.name + LINK_DOCUMENT_EXTENSION
  else
    path = ''
  end
  if site_root.empty?
  path
  else
    URI::HTTP.build({:host => site_root, :path => path})
  end
end