#------------------------------------------------------------------------------#
# Copyright (c) 2014 Los Alamos National Security, LLC
# All rights reserved.
#------------------------------------------------------------------------------#

import sys
import string
from collections import OrderedDict

#------------------------------------------------------------------------------#
# Header comment
#------------------------------------------------------------------------------#

header = \
"""<!--
  Copyright (c) 2014 Los Alamos National Secutiry, LLC
  All rights reserved.

  This file was automatically generated by the documentation service
  in the cinch command-line tool.
-->
"""

#------------------------------------------------------------------------------#
# Section class
#------------------------------------------------------------------------------#

class Section():

  """
  """

  def __init__(self, title):

    """
    """

    self._title = title
    self._content = []

  # __init__

  def title(self):
    return self._title
  # title

  def append(self, content):

    """
    """

    self._content.append(content)

  # append

  def print_content(self):

    """
    """

    for line in self._content:
      sys.stdout.write(line)
    # for

  # print

  def str_content(self):
    # Don't use any seperator
    return string.join(self._content, '')
  # str_content

# class Section

#------------------------------------------------------------------------------#
# Document class
#------------------------------------------------------------------------------#

class Document():

  """
  """

  def __init__(self, title):

    """
    """

    self._title = title
    self._sections = OrderedDict()

    # Add header information
    self._sections['header'] = Section('Header')
    self._sections['header'].append(header)

  # __init__

  def title(self):
    return self._title
  # title

  def section(self, title):

    """
    """

    if not title in self._sections:
      self._sections[title] = Section(title)

    return self._sections[title]
  # section

  def sections(self):
    return self._sections
  # sections

  def add_section(self, title, obj=None):
    if obj:
      self._sections[title] = obj
    elif not title in self._sections:
      self._sections[title] = Section(title)
  # add_section      
    
  def delete_section(self, title):
    del self._sections[title]

  def print_content(self):
    for section in self._sections:
      self._sections[section].print_content()
  # print_content

  def write(self, output):
    with open(output, 'w+') as f:
      for section in self._sections:
        f.write(self._sections[section].str_content())
  # write

# class Document

#------------------------------------------------------------------------------#
# Formatting options for emacs and vim.
# vim: set tabstop=2 shiftwidth=2 expandtab :
#------------------------------------------------------------------------------#
