class Index

Public Class Methods

new(parent) click to toggle source
# File lib/zarchitect/index.rb, line 3
def initialize(parent)
  @parent = parent
  @ptype = @parent.class.to_s
  # index owns paginator
  # owns the index files which share its paginator
  setup_paginator
  setup_html
end

Public Instance Methods

build_html() click to toggle source
# File lib/zarchitect/index.rb, line 12
def build_html
  @html.each do |h|
    h.compose 
  end
end
write_html() click to toggle source
# File lib/zarchitect/index.rb, line 18
def write_html
  @html.each do |h|
    GPI.print "Writing index HTML.", GPI::CLU.check_option('v')
    h.write
  end
end

Private Instance Methods

base_url() click to toggle source
# File lib/zarchitect/index.rb, line 97
def base_url
  case @ptype
  when "Section"
    if section.conf.index
      ""
    else
      "/#{section.key}"
    end
  when "Category"
    "/#{section.key}/#{@parent.key}"
  when "Tag"
    "/#{section.key}/#{@parent.category.key}/#{@parent.key}"
  end
end
category() click to toggle source
# File lib/zarchitect/index.rb, line 123
def category
  case @ptype
  when "Section"
    nil
  when "Category"
    @parent
  when "Tag"
    @parent.category
  end
end
layout() click to toggle source
# File lib/zarchitect/index.rb, line 149
def layout
  case @ptype
  when "Section"
    section.conf.index_layout
  when "Category"
    if section.conf.has_option?("category_index_layout")
      section.conf.category_index_layout
    else
      section.conf.index_layout
    end
  when "Tag"
    if section.conf.has_option?("tag_index_layout")
      section.conf.tag_index_layout
    else
      if section.conf.has_option?("category_index_layout")
        section.conf.category_index_layout
      else
        section.conf.index_layout
      end
    end
  end
end
meta_author() click to toggle source
# File lib/zarchitect/index.rb, line 212
def meta_author
  Zarchitect.conf.admin
end
meta_description() click to toggle source
# File lib/zarchitect/index.rb, line 216
def meta_description
  if category
    section.name + " " + category.name
  else
    section.name
  end
end
meta_keywords() click to toggle source
# File lib/zarchitect/index.rb, line 208
def meta_keywords
  Zarchitect.conf.site_keywords.clone
end
meta_title() click to toggle source

meta data

# File lib/zarchitect/index.rb, line 199
def meta_title
  if category
    Zarchitect.conf.site_name + Zarchitect.conf.title_sep + section.name +
      Zarchitect.conf.title_sep + category.name
  else
    Zarchitect.conf.site_name + Zarchitect.conf.title_sep + section.name
  end
end
posts() click to toggle source
# File lib/zarchitect/index.rb, line 145
def posts
  @parent.posts
end
section() click to toggle source
# File lib/zarchitect/index.rb, line 112
def section
  case @ptype
  when "Section"
    @parent
  when "Category"
    @parent.section
  when "Tag"
    @parent.category.section
  end
end
setup_html() click to toggle source
# File lib/zarchitect/index.rb, line 41
def setup_html
  @html = Array.new
  if @paginator.posts_per_page == 0
    html = HTML.new(File.join(Dir.getwd,HTMLDIR,base_url,"index.html"))
    html.set_templates(layout, view)
    html.set_data("section", section)
    html.set_data("category", category)
    html.set_data("tag", tag)
    html.set_data("posts", posts)
    html.set_data("index", true)
    html.set_meta("title", meta_title)
    html.set_meta("keywords", meta_keywords)
    html.set_meta("author", meta_author)
    html.set_meta("description", meta_description)
    @html.push html
    return
  end
  max = 0
  if section.conf.has_option?("maxpages")
    max = section.conf.maxpages
  end
  n = 1 # number of index.html files we need to create
  if @paginator.posts_per_page > 0
    if max > 0
      n = max
    else
      n = @paginator.page_number
    end
  end
  i = 0
  while i < n
    rposts = posts.slice(i * @paginator.posts_per_page,
                         @paginator.posts_per_page)
    if i == 0
      path = File.join(Dir.getwd,HTMLDIR,base_url, "index.html")
    else
      path = File.join(Dir.getwd,HTMLDIR,base_url, "index-#{i+1}.html")
    end
    html = HTML.new(path)
    html.set_templates(layout, view)
    html.set_data("section", section)
    html.set_data("category", category)
    html.set_data("tag", tag)
    html.set_data("posts", rposts)
    html.set_data("paginator", @paginator.clone)
    html.set_data("index", true)
    html.set_meta("title", meta_title)
    html.set_meta("keywords", meta_keywords)
    html.set_meta("author", meta_author)
    html.set_meta("description", meta_description)
    @html.push html
    i += 1
    @paginator.next
  end
end
setup_paginator() click to toggle source
# File lib/zarchitect/index.rb, line 27
def setup_paginator
  ppp = 0
  if section.conf.has_option? "paginate"
    ppp = section.conf.paginate # post per page
  end
  if ppp > 0 && section.conf.collection
    pbu = base_url # url used by pagination
    pnm = (posts.count.to_f / ppp.to_f).ceil # numbers of index pages
    @paginator = Paginator.new(pbu, pnm, ppp)
  else
    @paginator = Paginator.new(0,0,0) # no pagination for this index file
  end
end
tag() click to toggle source
# File lib/zarchitect/index.rb, line 134
def tag
  case @ptype
  when "Section",
    nil
  when "Category"
    nil
  when "Tag"
    @parent
  end
end
view() click to toggle source
# File lib/zarchitect/index.rb, line 172
def view
  case @ptype
  when "Section"
    section.conf.index_view
  when "Category"
    if section.conf.has_option?("category_index_view")
      section.conf.category_index_view
    else
      section.conf.index_view
    end
  when "Tag"
    if section.conf.has_option?("tag_index_view")
      section.conf.tag_index_view
    else
      if section.conf.has_option?("category_index_view")
        section.conf.category_index_view
      else
        section.conf.index_view
      end
    end
  end
end