class Adocsite::Engine
Constants
- LINK_DOCUMENT_EXTENSION
- LOCATION_ARTICLE
- LOCATION_CATEGORY
- LOCATION_PAGE
- OUTPUT_DOCUMENT_EXTENSION
Attributes
categories[R]
content_loader[R]
templates[R]
Public Class Methods
new()
click to toggle source
# 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
Public Instance Methods
build(layout = "default")
click to toggle source
# 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_queue()
click to toggle source
# 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
Private Instance Methods
add_to_processing_queue(request)
click to toggle source
# File lib/adocsite/engine.rb, line 68 def add_to_processing_queue(request) # Add request into processing queue if it is not already there rp_key = request_process_key(request) if @request_processing_queue[rp_key] == nil @request_processing_queue[rp_key] = RequestProcessing.new(request) end return rp_key end
build_categories()
click to toggle source
# File lib/adocsite/engine.rb, line 47 def build_categories # figure out categories and build hash of (category, articles) @categories = Hash.new @content_loader.articles.values.each {|article| article_title = article.title article.categories.each_index {|idx| cat = article.categories[idx] if @categories[cat] == nil @categories[cat] = Category.new(cat, [article]) else @categories[cat].articles.push(article) end } } end
process_requests(layout)
click to toggle source
# File lib/adocsite/engine.rb, line 91 def process_requests(layout) # Get request from queue # request_processing = get_next_from_processing_queue while request_processing = get_next_from_processing_queue a_request = request_processing.request puts "Processing - '" + a_request.name + "'..." # Process request, which means render and save output context = Context.new(self, a_request) # this converts request into html page # all the heavy lifting is hidden behind this call output = context.get_layout(layout) # save it, nah? @site.write(output, a_request.name + OUTPUT_DOCUMENT_EXTENSION) # Mark this one as done request_processing.rendered = true end end
request_process_key(request)
click to toggle source
# File lib/adocsite/engine.rb, line 64 def request_process_key(request) request.type + ':' + request.name end