Developers

Understanding the Template3d class

class template3d():

  • t3d = template3d()
    • The __init__ definition contains primary error checking and is ran any time the template3d() class is referenced. Therefore, the above statement will execute all error checking. Subsequent commands using the t3d object will not trigger the __init__ definition. A simple call to template3d() can also be used to return exceptions and messages.
  • template_3d.parse_templates()
    • The nuts and bolts of template3d. This definition will: parse a single template, optimize for the font-end engine, compile the javascript, and put the results into the TEMPLATE_DIRS directory.
  • template_3d.create_directories()
    • This function will parse the STANDARD_TEMPLATE_DIRS directory and match the TEMPLATE_DIRS to it. It is important to keep both of these directories in sync. Is is safe to include the [-d] argument into your template3d commands. It will not overwrite or replace any existing directories or contents.
  • template_3d.check_directories()
    • Only checks for non-matching directory structure in STANDARD_TEMPLATE_DIRS to the TEMPLATE_DIRS structure. This will not create any directories and outputs an error if inconsistencies are found. Returns true if directories are the same.
  • template_3d.toggle_engine([bool][bool])
    • Toggles the parse_template() definition to optimize templates in the front-end real time template loader and/or compilation with the Google closure tools. e.g. t3d.toggle_engine(False, True) will turn off the optimization and turn on closure compilation in the view or script. This is a direct override of the T3D_OPTIMIZE and T3D_COMPILE settings. Should be used in views.py or other scripts as a global template3d() class instance. e.g. t3d = template3d() at the top of the script.
  • template_3d.check_duplicates()
    • Due to the nature of template3d, duplicate template names are not supported anywhere in your STANDARD_TEMPLATE_DIRS directory. Template3d uses functions like select_template() which parse the TEMPLATE_DIRS directory and return the first template it finds. Therefore, the check_duplicates() definition will find any templates with the same name and return it as a warning.
  • template_3d.by_filename(filename_list)
    • Accepts a list of template names and sends them one by one to the parse_templates() definition for optimizing/compiling.
  • template_3d.create_all()
    • Will parse the STANDARD_TEMPLATE_DIRS directory for all files ending with .html and send them one by one to the parse_templates() definition for optimizing/compiling.
  • template_3d.list_settings()
    • Ad simple call to return all project settings and warnings together. Useful for debugging information.

      e.g. print '\n%s' % template_3d.list_settings()

  • template_3d.add_warning(["message'], ["lable"])
    • Adds a warning message to the warning_queue list. This is a list variable with class scope for persistence functionality. If second argument is omitted, the default label of “warning” will be used.
      e.g. template3d.add_warning('Hmmmm, this is kinda bad. File '+filename+' is missing.', 'BAD THING')

      template3d.add_warning('A simple warning to display')

  • template_3d.list_warnings()
    • Returns a new line formatted string from the class list template3d.warning_queue. The template_3d.warning_queue list can also be parsed.
      e.g. print template_3d.list_warnings()

      print template_3d.warning_queue[0]