Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I think these feature would be great for FORD. #274

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
61 changes: 53 additions & 8 deletions ford/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def stdout_redirector(stream):
'opl': '<a rel="license" href="http://opencontent.org/openpub/">Open Publication License</a>',
'pdl': '<a rel="license" href="http://www.openoffice.org/licenses/PDL.html">Public Documentation License</a>',
'bsd': '<a rel="license" href="http://www.freebsd.org/copyright/freebsd-doc-license.html">FreeBSD Documentation License</a>',
'mit': '<a rel="license" href="https://opensource.org/licenses/">MIT</a>',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

'': ''
}

Expand Down Expand Up @@ -150,25 +151,32 @@ def initialize():
'project','author','author_description','author_pic',
'summary','github','bitbucket','facebook','twitter',
'google_plus','linkedin','email','website','project_github',
'project_bitbucket','project_website','project_download',
'project_sourceforge','project_url','display','version',
'project_bitbucket','project_website','doc_asset_url','doc_license',
'project_download','project_sourceforge','project_url',
'display','version',
'year','docmark','predocmark','docmark_alt','predocmark_alt',
'media_dir','favicon','warn','extra_vartypes','page_dir',
'media_dir','favicon','warn','extra_vartypes',
'page_dir','page_dir_recursive', 'page_index', 'page_license',
'page_extension','privacy_policy_link','terms_of_service_link',
'incl_src',
'source','exclude_dir','macro','include','preprocess','quiet',
'search','lower','sort','extra_mods','dbg','graph',
'graph_maxdepth', 'graph_maxnodes',
'license','extra_filetypes','preprocessor','creation_date',
'print_creation_date','proc_internals','coloured_edges',
'graph_dir','gitter_sidecar','mathjax_config','parallel',
'revision', 'fixed_length_limit']
'revision', 'fixed_length_limit', 'html_minify',
'branding', 'branding_short', 'branding_url', 'breadcrumb_pre',
'copy_assets'
]
defaults = {'src_dir': ['./src'],
'extensions': ['f90','f95','f03','f08','f15'],
'fpp_extensions': ['F90','F95','F03','F08','F15','F','FOR'],
'fixed_extensions': ['f','for','F','FOR'],
'output_dir': './doc',
'project': 'Fortran Program',
'project_url': '',
'doc_asset_url': '',
'display': ['public','protected'],
'year': date.today().year,
'exclude': [],
Expand Down Expand Up @@ -197,12 +205,18 @@ def initialize():
'graph_maxdepth': '10000',
'graph_maxnodes': '1000000000',
'license': '',
'doc_license': '',
'extra_filetypes': [],
'creation_date': '%Y-%m-%dT%H:%M:%S.%f%z',
'print_creation_date': False,
'coloured_edges': 'false',
'parallel': ncpus,
'fixed_length_limit': 'true',
'page_index': 'index.md',
'page_license': 'LICENSE',
'page_extension': 'html',
'html_minify': 'false',
'copy_assets': 'true'
}
listopts = ['extensions','fpp_extensions','fixed_extensions','display',
'extra_vartypes','src_dir','exclude','exclude_dir',
Expand Down Expand Up @@ -322,11 +336,33 @@ def initialize():
proj_data['preprocessor'] = preprocessor

# Get correct license
# This add the ability to have custom license (custom|||license_name|||license_url)
# Project_license should be different then document license.
# Most of the code use license as code's license. Thus, 'license' is code's license,
# and doc_license is document's license or site's license. doc_license
# is more like a copyright link for the website.
if proj_data['license'].lower().startswith("custom"):
_t_proj_license = proj_data['license'].split("|||")
if len(_t_proj_license) == 3:
LICENSES[_t_proj_license[1].lower()] = '<a rel="license" href="'+_t_proj_license[2]+'">'+_t_proj_license[1]+"</a>"
proj_data['license'] = _t_proj_license[1]
try:
proj_data['license'] = LICENSES[proj_data['license'].lower()]
except KeyError:
print('Warning: license "{}" not recognized.'.format(proj_data['license']))
proj_data['license'] = ''
# doc_license
if proj_data['doc_license'].lower().startswith("custom"):
_t_proj_license = proj_data['doc_license'].split("|||")
if len(_t_proj_license) == 3:
LICENSES[_t_proj_license[1].lower()] = '<a rel="site_license" href="'+_t_proj_license[2]+'">'+_t_proj_license[1]+"</a>"
proj_data['doc_license'] = _t_proj_license[1]
try:
proj_data['doc_license'] = LICENSES[proj_data['doc_license'].lower()]
except KeyError:
print('Warning: license "{}" not recognized.'.format(proj_data['doc_license']))
proj_data['doc_license'] = ''
ford.sourceform.page_extension = proj_data['page_extension']
# Return project data, docs, and the Markdown reader
md.reset()
md.Meta = {}
Expand Down Expand Up @@ -358,14 +394,23 @@ def main(proj_data,proj_docs,md):
if proj_data['relative']: ford.sourceform.set_base_url('.')
if 'summary' in proj_data:
proj_data['summary'] = md.convert(proj_data['summary'])
proj_data['summary'] = ford.utils.sub_links(ford.utils.sub_macros(ford.utils.sub_notes(proj_data['summary']),proj_data['project_url']),project)
proj_data['summary'] = ford.utils.sub_links(ford.utils.sub_macros(ford.utils.sub_notes(proj_data['summary']),proj_data['project_url'],proj_data['page_extension']),project)
if 'author_description' in proj_data:
proj_data['author_description'] = md.convert(proj_data['author_description'])
proj_data['author_description'] = ford.utils.sub_links(ford.utils.sub_macros(ford.utils.sub_notes(proj_data['author_description']),proj_data['project_url']),project)
proj_docs_ = ford.utils.sub_links(ford.utils.sub_macros(ford.utils.sub_notes(proj_docs),proj_data['project_url']),project)
proj_data['author_description'] = ford.utils.sub_links(ford.utils.sub_macros(ford.utils.sub_notes(proj_data['author_description']),proj_data['project_url'],proj_data['page_extension']),project)
proj_docs_ = ford.utils.sub_links(ford.utils.sub_macros(ford.utils.sub_notes(proj_docs),proj_data['project_url'],proj_data['page_extension']),project)
# Process any pages
if 'page_dir' in proj_data:
page_tree = ford.pagetree.get_page_tree(os.path.normpath(proj_data['page_dir']),md)
if 'page_dir_recursive' in proj_data:
if proj_data['page_dir_recursive'].lower() == 'false':
proj_data['page_dir_recursive'] = False
else:
proj_data['page_dir_recursive'] = True
if proj_data['page_dir_recursive'].lower() != 'true':
print("Warning: page_dir_recursive can only be 'true' or 'false'.")
else:
proj_data['page_dir_recursive'] = True
page_tree = ford.pagetree.get_page_tree(os.path.normpath(proj_data['page_dir']),md,proj_data)
print()
else:
page_tree = None
Expand Down
59 changes: 37 additions & 22 deletions ford/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#

from __future__ import print_function
import htmlmin

import sys
import os
Expand All @@ -44,7 +45,21 @@
from ford.graphs import graphviz_installed

loc = os.path.dirname(__file__)
env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.join(loc, "templates")))
# Possible future expansion of templates with template_dir
template_dir = os.path.join(loc, "templates", "default")
# An assets dir is where all css/js/font etc is stored.
# Every support files that a template need should be in this directory.
# However, Tipuesearch and Mathjax could be different for each
# docs. Therefore Tipue and Mathjax should not be handled by
# the template.
# Everything in assets should be copy to out_dir/assets, except for
# favicon. User.css will go in out_dir/assets/ . Thus, template should
# avoid putting something similar at the root their assets.
#
# @todo Future pre code should be handled by the template, as jinja
# should be capable of such.
assets_dir = os.path.join(template_dir, "assets")
env = jinja2.Environment(loader=jinja2.FileSystemLoader(template_dir))
env.globals['path'] = os.path # this lets us call path.* in templates

class Documentation(object):
Expand All @@ -70,6 +85,7 @@ def __init__(self,data,proj_docs,project,pagetree):
else:
graphparent = ''
print("Creating HTML documentation...")

try:
if data['incl_src'] == 'true':
for item in project.allfiles:
Expand Down Expand Up @@ -158,7 +174,7 @@ def __init__(self,data,proj_docs,project,pagetree):
self.tipue = ford.tipue_search.Tipue_Search_JSON_Generator(data['output_dir'],'')
else:
self.tipue = ford.tipue_search.Tipue_Search_JSON_Generator(data['output_dir'],data['project_url'])
self.tipue.create_node(self.index.html,'index.html', {'category': 'home'})
self.tipue.create_node(self.index.html,'index.' + self.data['page_extension'], {'category': 'home'})
jobs = len(self.docs) + len(self.pagetree)
progbar = tqdm(chain(iter(self.docs), iter(self.pagetree)),
total=jobs, unit='', file=sys.stdout)
Expand Down Expand Up @@ -186,9 +202,7 @@ def writeout(self):
os.mkdir(os.path.join(out_dir,'program'), 0o755)
os.mkdir(os.path.join(out_dir,'src'), 0o755)
os.mkdir(os.path.join(out_dir,'blockdata'), 0o755)
copytree(os.path.join(loc,'css'), os.path.join(out_dir,'css'))
copytree(os.path.join(loc,'fonts'), os.path.join(out_dir,'fonts'))
copytree(os.path.join(loc,'js'), os.path.join(out_dir,'js'))
copytree(os.path.join(assets_dir), os.path.join(out_dir,'assets'))
if self.data['graph'].lower() == 'true': self.graphs.output_graphs(self.njobs)
if self.data['search'].lower() == 'true':
copytree(os.path.join(loc,'tipuesearch'),os.path.join(out_dir,'tipuesearch'))
Expand All @@ -199,9 +213,9 @@ def writeout(self):
except:
print('Warning: error copying media directory {}'.format(self.data['media_dir']))
if 'css' in self.data:
shutil.copy(self.data['css'],os.path.join(out_dir,'css','user.css'))
shutil.copy(self.data['css'],os.path.join(out_dir,'assets','user.css'))
if self.data['favicon'] == 'default-icon':
shutil.copy(os.path.join(loc,'favicon.png'),os.path.join(out_dir,'favicon.png'))
shutil.copy(os.path.join(assets_dir,'favicon.png'),os.path.join(out_dir,'favicon.png'))
else:
shutil.copy(self.data['favicon'],os.path.join(out_dir,'favicon.png'))
if self.data['incl_src'] == 'true':
Expand Down Expand Up @@ -251,7 +265,8 @@ def html(self):

def writeout(self):
out = open(self.outfile,'wb')
out.write(self.html.encode('utf8'))
if self.data['html_minify'].lower() == 'true': out.write(htmlmin.minify(self.html.encode('utf8'), True))
else: out.write(self.html.encode('utf8'))
out.close()

def render(self, data, proj, obj):
Expand All @@ -267,7 +282,7 @@ def render(self, data, proj, obj):
class IndexPage(BasePage):
@property
def outfile(self):
return os.path.join(self.out_dir,'index.html')
return os.path.join(self.out_dir,'index.' + self.data['page_extension'])

def render(self,data,proj,obj):
if data['relative']:
Expand All @@ -281,7 +296,7 @@ def render(self,data,proj,obj):
class SearchPage(BasePage):
@property
def outfile(self):
return os.path.join(self.out_dir,'search.html')
return os.path.join(self.out_dir,'search.' + self.data['page_extension'])

def render(self,data,proj,obj):
if data['relative']:
Expand All @@ -295,7 +310,7 @@ def render(self,data,proj,obj):
class ProcList(BasePage):
@property
def outfile(self):
return os.path.join(self.out_dir,'lists','procedures.html')
return os.path.join(self.out_dir,'lists','procedures.' + self.data['page_extension'])

def render(self,data,proj,obj):
if data['relative']:
Expand All @@ -309,7 +324,7 @@ def render(self,data,proj,obj):
class FileList(BasePage):
@property
def outfile(self):
return os.path.join(self.out_dir,'lists','files.html')
return os.path.join(self.out_dir,'lists','files.' + self.data['page_extension'])

def render(self,data,proj,obj):
if data['relative']:
Expand All @@ -323,7 +338,7 @@ def render(self,data,proj,obj):
class ModList(BasePage):
@property
def outfile(self):
return os.path.join(self.out_dir,'lists','modules.html')
return os.path.join(self.out_dir,'lists','modules.' + self.data['page_extension'])

def render(self,data,proj,obj):
if data['relative']:
Expand All @@ -337,7 +352,7 @@ def render(self,data,proj,obj):
class ProgList(BasePage):
@property
def outfile(self):
return os.path.join(self.out_dir,'lists','programs.html')
return os.path.join(self.out_dir,'lists','programs.' + self.data['page_extension'])

def render(self,data,proj,obj):
if data['relative']:
Expand All @@ -351,7 +366,7 @@ def render(self,data,proj,obj):
class TypeList(BasePage):
@property
def outfile(self):
return os.path.join(self.out_dir,'lists','types.html')
return os.path.join(self.out_dir,'lists','types.' + self.data['page_extension'])

def render(self,data,proj,obj):
if data['relative']:
Expand All @@ -365,7 +380,7 @@ def render(self,data,proj,obj):
class AbsIntList(BasePage):
@property
def outfile(self):
return os.path.join(self.out_dir,'lists','absint.html')
return os.path.join(self.out_dir,'lists','absint.' + self.data['page_extension'])

def render(self,data,proj,obj):
if data['relative']:
Expand All @@ -379,7 +394,7 @@ def render(self,data,proj,obj):
class BlockList(BasePage):
@property
def outfile(self):
return os.path.join(self.out_dir,'lists','blockdata.html')
return os.path.join(self.out_dir,'lists','blockdata.' + self.data['page_extension'])

def render(self,data,proj,obj):
if data['relative']:
Expand All @@ -396,11 +411,11 @@ class DocPage(BasePage):
"""
@property
def loc(self):
return self.obj.get_dir() + '/' + self.obj.ident + '.html'
return self.obj.get_dir() + '/' + self.obj.ident + '.' + self.data['page_extension']

@property
def outfile(self):
return os.path.join(self.out_dir,self.obj.get_dir(),self.obj.ident+'.html')
return os.path.join(self.out_dir,self.obj.get_dir(),self.obj.ident+'.'+self.data['page_extension'])


class FilePage(DocPage):
Expand Down Expand Up @@ -482,11 +497,11 @@ def render(self,data,proj,obj):
class PagetreePage(BasePage):
@property
def loc(self):
return 'page/' + self.obj.location + '/' + self.obj.filename + '.html'
return 'page/' + self.obj.location + '/' + self.obj.filename + '.' + self.data['page_extension']

@property
def outfile(self):
return os.path.join(self.out_dir,'page',self.obj.location,self.obj.filename+'.html')
return os.path.join(self.out_dir,'page',self.obj.location,self.obj.filename+ '.' + self.data['page_extension'])

def render(self,data,proj,obj):
if data['relative']:
Expand All @@ -500,7 +515,7 @@ def render(self,data,proj,obj):
ford.pagetree.set_base_url(base_url)
data['project_url'] = base_url
template = env.get_template('info_page.html')
obj.contents = ford.utils.sub_links(ford.utils.sub_macros(ford.utils.sub_notes(obj.contents),data['project_url']),proj)
obj.contents = ford.utils.sub_links(ford.utils.sub_macros(ford.utils.sub_notes(obj.contents),data['project_url'], data['page_extension']),proj)
return template.render(data,page=obj,project=proj,topnode=obj.topnode)

def writeout(self):
Expand Down
Loading