<commit_before>Resolver = require './resolver'
Template = require './template'

# Public: Renders a page for a class.
module.exports =
class ClassPage extends Template
  @render: (locals) ->
    new this(locals).render()

  constructor: (@object) ->
    locals = @object
    locals.classInfoSection = @classInfoSection()
    locals.descriptionSection = @descriptionSection()
    locals.sections = @sections()

    @title = @object.name

    super('class-page', locals)

  sections: ->
    (@section(section) for section in @object.sections).join('\n')

  section: (section) ->
    classProps = (prop for prop in @object.classProperties when prop.sectionName is section.name)
    section.classProperties = (@property(prop, type: 'static') for prop in classProps).join('\n')

    props = (prop for prop in @object.instanceProperties when prop.sectionName is section.name)
    section.properties = (@property(prop, type: 'instance') for prop in props).join('\n')

    classMethods = (method for method in @object.classMethods when method.sectionName is section.name)
    section.classMethods = (@method(method, type: 'static') for method in classMethods).join('\n')

    methods = (method for method in @object.instanceMethods when method.sectionName is section.name)
    section.methods = (@method(method, type: 'instance') for method in methods).join('\n')

    section.description = @markdownify(section.description)
    Template.render('section', section)

  method: (method, options) ->
    method.id = "#{options.type}-#{method.name}"
    method.type = options.type
    method.signature = "#{@signifier(options.type)}#{@signature(method)}"
    method.description = @resolveReferences(@markdownify(method.description))
    method.parameterBlock = if method.arguments then @parameterBlock(method) else ''
    method.returnValueBlock = if method.returnValues then @returnValueBlock(method) else ''
    Template.render('method', method)

  property: (property, options) ->
    property.id = "#{options.type}-#{property.name}"
    property.type = options.type
    property.signature = "#{@signifier(options.type)}#{property.name}"
    property.description = @resolveReferences(@markdownify(property.description))
    Template.render('property', property)

  signature: (method) ->
    parameters = if method.arguments then @parameters(method) else ''
    "#{method.name}(#{parameters})"

  signifier: (type) ->
    if type is 'static' then '.' else '::'

  classInfoSection: ->
    Template.render('class-info', @object)

  descriptionSection: ->
    if @object.description
      description = @resolveReferences(@markdownify(@object.description))
      Template.render('description-section', description: description)

  resolveReferences: (text) ->
    text.replace /\{\S*\}/g, (match) =>
      @resolveReference(match)

  resolveReference: (ref) ->
    result = Resolver.getInstance().resolve(ref)
    if typeof result is 'string'
      result
    else
      Template.render('reference', result)

  parameterBlock: (method) ->
    rows = (@parameterRow(parameter) for parameter in method.arguments)
    Template.render('parameter-block-table', rows: rows.join('\n'))

  parameterRow: (parameter) ->
    parameter.description = @markdownify(parameter.description, noParagraph: true)
    parameter.description = @resolveReferences(parameter.description)
    Template.render('parameter-block-row', parameter)

  returnValueBlock: (method) ->
    rows = (@returnValueRow(returnValue) for returnValue in method.returnValues)
    Template.render('return-value-block-table', rows: rows.join('\n'))

  returnValueRow: (returnValue) ->
    returnValue.description = @markdownify(returnValue.description, noParagraph: true)
    returnValue.description = @resolveReferences(returnValue.description)
    Template.render('return-value-block-row', returnValue)

  parameters: (method) ->
    names = (name for {name} in method.arguments)
    names.join(', ')<commit_msg>Move export declaration to the bottom<commit_after>Resolver = require './resolver'
Template = require './template'

# Public: Renders a page for a class.
class ClassPage extends Template
  @render: (locals) ->
    new this(locals).render()

  constructor: (@object) ->
    locals = @object
    locals.classInfoSection = @classInfoSection()
    locals.descriptionSection = @descriptionSection()
    locals.sections = @sections()

    @title = @object.name

    super('class-page', locals)

  sections: ->
    (@section(section) for section in @object.sections).join('\n')

  section: (section) ->
    classProps = (prop for prop in @object.classProperties when prop.sectionName is section.name)
    section.classProperties = (@property(prop, type: 'static') for prop in classProps).join('\n')

    props = (prop for prop in @object.instanceProperties when prop.sectionName is section.name)
    section.properties = (@property(prop, type: 'instance') for prop in props).join('\n')

    classMethods = (method for method in @object.classMethods when method.sectionName is section.name)
    section.classMethods = (@method(method, type: 'static') for method in classMethods).join('\n')

    methods = (method for method in @object.instanceMethods when method.sectionName is section.name)
    section.methods = (@method(method, type: 'instance') for method in methods).join('\n')

    section.description = @markdownify(section.description)
    Template.render('section', section)

  method: (method, options) ->
    method.id = "#{options.type}-#{method.name}"
    method.type = options.type
    method.signature = "#{@signifier(options.type)}#{@signature(method)}"
    method.description = @resolveReferences(@markdownify(method.description))
    method.parameterBlock = if method.arguments then @parameterBlock(method) else ''
    method.returnValueBlock = if method.returnValues then @returnValueBlock(method) else ''
    Template.render('method', method)

  property: (property, options) ->
    property.id = "#{options.type}-#{property.name}"
    property.type = options.type
    property.signature = "#{@signifier(options.type)}#{property.name}"
    property.description = @resolveReferences(@markdownify(property.description))
    Template.render('property', property)

  signature: (method) ->
    parameters = if method.arguments then @parameters(method) else ''
    "#{method.name}(#{parameters})"

  signifier: (type) ->
    if type is 'static' then '.' else '::'

  classInfoSection: ->
    Template.render('class-info', @object)

  descriptionSection: ->
    if @object.description
      description = @resolveReferences(@markdownify(@object.description))
      Template.render('description-section', description: description)

  resolveReferences: (text) ->
    text.replace /\{\S*\}/g, (match) =>
      @resolveReference(match)

  resolveReference: (ref) ->
    result = Resolver.getInstance().resolve(ref)
    if typeof result is 'string'
      result
    else
      Template.render('reference', result)

  parameterBlock: (method) ->
    rows = (@parameterRow(parameter) for parameter in method.arguments)
    Template.render('parameter-block-table', rows: rows.join('\n'))

  parameterRow: (parameter) ->
    parameter.description = @markdownify(parameter.description, noParagraph: true)
    parameter.description = @resolveReferences(parameter.description)
    Template.render('parameter-block-row', parameter)

  returnValueBlock: (method) ->
    rows = (@returnValueRow(returnValue) for returnValue in method.returnValues)
    Template.render('return-value-block-table', rows: rows.join('\n'))

  returnValueRow: (returnValue) ->
    returnValue.description = @markdownify(returnValue.description, noParagraph: true)
    returnValue.description = @resolveReferences(returnValue.description)
    Template.render('return-value-block-row', returnValue)

  parameters: (method) ->
    names = (name for {name} in method.arguments)
    names.join(', ')

module.exports = ClassPage
{'fraction_non_alphanumeric': 0.13888539438923134, 'fraction_numerical': 0.0, 'mean_word_length': 4.328418230563003, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1641239', 'n_tokens_mistral': 2193, 'n_tokens_neox': 2158, 'n_words': 518}