Renderer

Renders documentations from result of collector

See Also:

(defined in /src/render.coffee:12)
class Renderer

Parameters

(None)
(defined in /src/render.coffee:15)
constructor: (@result, @options) ->
  theme = 'default'
  @resources_dir = resolve __dirname, '../themes', theme, 'resources'
  @templates_dir = resolve __dirname, '../themes', theme, 'templates'

Parameters

NameTypeDescription
sourceString
targetString
callbackFunction()

Returns

(Nothing)
(defined in /src/render.coffee:90)
_copyResources: (source, target, callback) ->
  try
    files = fs.readdirSync target
  catch
    files = []
  for file in files
    if file[0] isnt '.'
      fs.rmrfSync resolve target, file
  try fs.mkdirSync target
  fs.copyRecursive source, target, ->
    callback()

Parameters

(None)

Returns

(Nothing)
(defined in /src/render.coffee:228)
_groupByNamespaces: (items) ->
  if items.length is 0
    return []
  current_group = []
  grouped_items = [current_group]
  current_namespace = items[0].namespace
  items.forEach (item) ->
    if current_namespace isnt item.namespace
      current_group = []
      grouped_items.push current_group
      current_namespace = item.namespace
    current_group.push item
  return grouped_items

Parameters

(None)

Returns

(Nothing)
(defined in /src/render.coffee:164)
_renderClasses: ->
  return if @result.classes.length is 0
  try fs.mkdirSync "#{@options.output_dir}/classes"
  pug_options =
    rel_path: '../'
    type: 'classes'
  @_renderOne pug_options, 'class-toc', 'classes/index'
  @result.classes.forEach (klass) =>
    pug_options =
      rel_path: '../'
      name: klass.ctx.name
      klass: klass
      properties: klass.properties
      type: 'classes'
      _makeTypeLink: (path, type) =>
        @_makeTypeLink path, type, "(in #{klass.full_path})"
    @_renderOne pug_options, 'class', klass.filename

Parameters

(None)

Returns

(Nothing)
(defined in /src/render.coffee:202)
_renderFeatures: ->
  return if @result.features.length is 0
  try fs.mkdirSync "#{@options.output_dir}/features"
  @result.features.forEach (feature) =>
    pug_options =
      rel_path: '../'
      name: feature.name
      feature: feature
      type: 'features'
    @_renderOne pug_options, 'feature', feature.filename

Parameters

(None)

Returns

(Nothing)
(defined in /src/render.coffee:215)
_renderFiles: ->
  return if @result.files.length is 0
  try fs.mkdirSync "#{@options.output_dir}/files"
  @result.files.forEach (file) =>
    pug_options =
      rel_path: '../'
      name: file.name
      file: file
      type: 'files'
    @_renderOne pug_options, 'file', file.filename

Parameters

(None)

Returns

(Nothing)
(defined in /src/render.coffee:131)
_renderGuides: ->
  return if @result.guides.length is 0
  try fs.mkdirSync "#{@options.output_dir}/guides"
  @result.guides.forEach (guide) =>
    pug_options =
      rel_path: '../'
      name: guide.name
      content: guide.content
      type: 'guides'
    @_renderOne pug_options, 'extra', guide.filename

Parameters

(None)

Returns

(Nothing)
(defined in /src/render.coffee:184)
_renderModules: ->
  return if @result.modules.length is 0
  try fs.mkdirSync "#{@options.output_dir}/modules"
  pug_options =
    rel_path: '../'
    type: 'modules'
  @_renderOne pug_options, 'module-toc', 'modules/index'
  @result.modules.forEach (module) =>
    pug_options =
      rel_path: '../'
      name: module.ctx.name
      module_data: module
      properties: module.properties
      type: 'modules'
    @_renderOne pug_options, 'module', module.filename

Parameters

(None)

Returns

(Nothing)
(defined in /src/render.coffee:104)
_renderOne: (pug_options, template, output) ->
  pug_options.result = @result
  pug_options.makeTypeLink = @_makeTypeLink.bind(@) if not pug_options.makeTypeLink
  pug_options.makeSeeLink = @_makeSeeLink.bind(@)
  pug_options.convertLink = @_convertLink.bind(@)
  pug_options.github = @options.github
  pug_options.cache = true
  pug_options.self = true
  pug.renderFile "#{@templates_dir}/#{template}.pug", pug_options, (error, result) =>
    return console.error error.stack if error
    output_file = "#{@options.output_dir}/#{output}.html"
    fs.writeFile output_file, result, (error) =>
      return console.error 'failed to create '+output_file if error
      console.log output_file + ' is created' if not @options.quiet

Parameters

(None)

Returns

(Nothing)
(defined in /src/render.coffee:144)
_renderPages: ->
  if @result.pages.length > 0
    pug_options =
      rel_path: './'
      name: 'Pages'
      type: 'pages'
    @_renderOne pug_options, 'pages', 'pages'

Parameters

(None)

Returns

(Nothing)
(defined in /src/render.coffee:154)
_renderRESTApis: ->
  if @result.restapis.length > 0
    pug_options =
      rel_path: './'
      name: 'REST APIs'
      type: 'restapis'
    @_renderOne pug_options, 'restapis', 'restapis'

Parameters

(None)

Returns

(Nothing)
(defined in /src/render.coffee:121)
_renderReadme: ->
  pug_options =
    rel_path: './'
    name: 'README'
    content: @result.readme
    type: 'home'
  @_renderOne pug_options, 'extra', 'index'

Parameters

(None)

Returns

(Nothing)
(defined in /src/render.coffee:244)
run: ->
  @result.ns_pages = @_groupByNamespaces @result.pages
  @result.ns_restapis = @_groupByNamespaces @result.restapis
  @result.ns_classes = @_groupByNamespaces @result.classes
  @result.ns_modules = @_groupByNamespaces @result.modules
  @result.ns_features = @_groupByNamespaces @result.features
  @result.ns_files = @_groupByNamespaces @result.files

  @_copyResources @resources_dir, @options.output_dir, =>
    @_renderReadme()
    @_renderGuides()
    @_renderPages()
    @_renderRESTApis()
    @_renderClasses()
    @_renderModules()
    @_renderFeatures()
    @_renderFiles()
Fork me on GitHub