class RDaux::Web::Site

Attributes

author[R]
description[R]
root[R]
title[R]

Public Class Methods

new(title, description, author, root) click to toggle source
# File lib/rdaux/web/site.rb, line 32
def initialize(title, description, author, root)
  @title       = title
  @description = description
  @author      = author
  @root        = root
end

Public Instance Methods

sections() click to toggle source
# File lib/rdaux/web/site.rb, line 39
def sections
  find_sections(@root)
end

Private Instance Methods

base_dirname(path) click to toggle source
# File lib/rdaux/web/site.rb, line 81
def base_dirname(path)
  path.basename.to_s.sub(/^[0-9]*[\_\-]?/, '')
end
base_filename(path) click to toggle source
# File lib/rdaux/web/site.rb, line 77
def base_filename(path)
  path.sub_ext('').basename.to_s.sub(/^[0-9]*[\_\-]?/, '')
end
basename_to_key(basename) click to toggle source
# File lib/rdaux/web/site.rb, line 73
def basename_to_key(basename)
  basename.split(/[\_\- ]/).map(&:downcase).join('-')
end
find_sections(root) click to toggle source
# File lib/rdaux/web/site.rb, line 45
def find_sections(root)
  root.children.inject({}) do |sections, path|
    unless path.symlink?
      if path.file? && path.extname == '.md'
        key = basename_to_key(base_filename(path))
        section = get_or_create_section(key, sections)

        section.contents = path
      elsif path.directory? && !path.basename.to_s.start_with?('.')
        key = basename_to_key(base_dirname(path))
        section = get_or_create_section(key, sections)

        section.sections = find_sections(path)
      end
    end

    sections
  end
end
get_or_create_section(key, sections) click to toggle source
# File lib/rdaux/web/site.rb, line 65
def get_or_create_section(key, sections)
  unless sections.has_key?(key)
    sections[key] = Section.new(key)
  end

  sections[key]
end