Tw1ddle/geometrize-haxe

View on GitHub
dox/themes/samcodes/templates/macros.mtt

Summary

Maintainability
Test Coverage
<macro name="printTypeParams(params)">
    ::if params.length > 0::
        &lt;
        ::foreach param params::
            <span class="type">::param::</span>
            ::if !repeat.param.last::, ::end::
        ::end::
        &gt;
    ::end::
</macro>

<macro name="printPlatforms(platforms, useSeparator)">
    <p class="availability" ::cond (api.config.platforms.length>1)::>
        ::if (useSeparator)::<hr/>::end::
        <em>
        Available on 
        ::if platforms.length == api.config.platforms.length:: all platforms
        ::elseif platforms.length > 1:: ::platforms.join(", ")::
        ::else:: ::platforms.join("")::
        ::end::
        </em>
    </p>
</macro>

<macro name="printLinkedPath(path, params)">
    ::if api.isKnownType(path)::
        <a class="type" title="::api.getSentenceDesc(api.resolveType(path))::" ::attr href api.pathToUrl(path)::>::api.getPathName(path)::</a>
    ::else::
        <span class="type">::api.getPathName(path)::</span>
    ::end::
    ::if params.length > 0::
        &lt;
        ::foreach param params::
            $$printLinkedType(::param::)
            ::if !repeat.param.last::, ::end::
        ::end::
        &gt;
    ::end::
</macro>

<macro name="printLinkedType(ctype)">
    ::switch ctype::
    ::case::Unknown
    ::case::$$printLinkedPath(::args[0]::,::args[1]::)
    ::case::$$printLinkedPath(::args[0]::,::args[1]::)
    ::case::$$printLinkedPath(::args[0]::,::args[1]::)
    ::case::
        ::if args[0].length == 0::
            $$printLinkedPath(::"Void"::,::[]::)&nbsp;&#8209;&gt;&nbsp;
        ::else::
            ::foreach arg args[0]::
                $$printLinkedType(::arg.t::)&nbsp;&#8209;&gt;&nbsp;
            ::end::
        ::end::
        $$printLinkedType(::args[1]::)
    ::case::
    {
        ::foreach field args[0]::
            ::field.name:::$$printLinkedType(::field.type::)
            ::if !repeat.field.last::, ::end::
        ::end::
    }
    ::case::$$printLinkedPath(::"Dynamic"::,::null::)::if args[0] != null::&lt;$$printLinkedType(::args[0]::)&gt;::end::
    ::case::$$printLinkedPath(::args[0]::,::args[1]::)
    ::end::
</macro>

<macro name="printModule(module)">
    <p ::cond module != null && module != "StdTypes"::>
        <h4><small>import <a ::attr href api.pathToUrl(module)::>::module::</a></small></h4>
    </p>
</macro>

<macro name="printFieldSignature(field, isStatic, type)">
    <code>
    ::if !field.isPublic::
        <span class="label">private</span>
    ::end::

    ::if isStatic::
        <span class="label">static</span>
    ::end::

    ::set fieldInfo = api.getFieldInfo(field)::

    ::if fieldInfo.modifiers.isDynamic::
        <span class="label">dynamic</span> 
    ::end::

    ::if fieldInfo.modifiers.isInline::
        <span class="label">inline</span> 
    ::end::
    
    ::switch fieldInfo.kind::
        ::switch field.set::
        ::case 1::
            <span class="label">read only</span>
        ::end::
        ::switch field.get::
        ::case 1::
            <span class="label">write only</span>
        ::end::

    <a href="::api.pathToUrl(type.path)::#::field.name::"><span class="identifier">::field.name::</span></a>:$$printLinkedType(::field.type::)$$printInitExpr(::field.expr::)

    ::case 2::
        <a href="#::field.name::"><span class="identifier">::field.name::</span></a>
        $$printTypeParams(::field.params::) (
        ::foreach arg args[0]::
            <span style="white-space:nowrap">
                ::if arg.opt && (arg.value == null || arg.value == "null")::?::end::
                ::arg.name:::$$printLinkedType(::arg.t::)
                ::if arg.value != null && arg.value != "null":: = ::arg.value::::end::
                ::if !repeat.arg.last::,::end::
            </span>
            ::if !repeat.arg.last:: ::end::
        ::end::
        )
        ::if field.name != "new"::
            :$$printLinkedType(::args[1]::)
        ::end::
    ::end::
    </code>
</macro>

<macro name="printInitExpr(expr)">
    <span ::cond expr != null::>
         = ::expr::
    </span>
</macro>

<macro name="printClassBody(type)">
    ::set showSection = false::
    ::foreach field type.fields::
        ::if field.name == "new" && api.isMethod(field)::
            ::eval showSection = true::
        ::end::
    ::end::
    ::if showSection::
        <h3 class="section">Constructor</h3>
        <div class="fields">
            ::foreach field type.fields::
                ::set isStatic = false::
                ::if field.name == "new" && api.isMethod(field)::
                    ::use "class_field.mtt"::::end::
                ::end::
            ::end::
        </div>
    ::end::
    
    ::set showSection = false::
    ::foreach field type.fields::
        ::if !api.isMethod(field)::
            ::eval showSection = true::
        ::end::
    ::end::
    ::if showSection::
        <h3 class="section">Variables</h3>
        <div class="fields">
            ::foreach field type.fields::
                ::set isStatic = false::
                ::if !api.isMethod(field)::
                    ::use "class_field.mtt"::::end::
                ::end::
            ::end::
        </div>
    ::end::
    
    ::set showSection = false::
    ::foreach field type.fields::
        ::if field.name != "new" && api.isMethod(field)::
            ::eval showSection = true::
        ::end::
    ::end::
    ::if showSection::
        <h3 class="section">Methods</h3>
        <div class="fields">
            ::foreach field type.fields::
                ::set isStatic = false::
                ::if field.name != "new" && api.isMethod(field)::
                    ::use "class_field.mtt"::::end::
                ::end::
            ::end::
        </div>
    ::end::
    
    ::set showSection = false::
    ::foreach field type.statics::
        ::if !api.isMethod(field)::
            ::eval showSection = true::
        ::end::
    ::end::
    ::if showSection::
        <h3 class="section">Static variables</h3>
        <div class="fields">
            ::foreach field type.statics::
                ::set isStatic = true::
                ::if !api.isMethod(field)::
                    ::use "class_field.mtt"::::end::
                ::end::
            ::end::
        </div>
    ::end::
    
    ::set showSection = false::
    ::foreach field type.statics::
        ::if api.isMethod(field)::
            ::eval showSection = true::
        ::end::
    ::end::
    ::if showSection::
        <h3 class="section">Static methods</h3>
        <div class="fields">
            ::foreach field type.statics::
                ::set isStatic = true::
                ::if api.isMethod(field)::
                    ::use "class_field.mtt"::::end::
                ::end::
            ::end::
        </div>
    ::end::
</macro>

<macro name="printInheritedFields(type)">
::if type.superClass != null::
  ::set inheritedFields = api.getInheritedFields(type)::
    ::set hasFields = inheritedFields.fields.keys().hasNext()::
    ::set hasMethods = inheritedFields.methods.keys().hasNext()::
    
    <div class="inherited-fields well" ::cond hasFields || hasMethods::>
        <h3 class="section" ::cond hasFields::>Inherited Variables</h3>
        <div class="fields" ::cond hasFields::>
            ::set fields=inheritedFields.fields::
            ::foreach cl inheritedFields.types::
                <h4 ::cond fields.get(cl).length>0::><a href="#" class="expand-button"><i class="fa fa-arrow-circle-o-right"></i></a> Defined by $$printLinkedPath(::cl.path::,::null::)</h4>
                <div style="display:none">
                ::foreach field fields.get(cl)::
                    ::set isStatic = false::
                    ::set type=cl::
                    ::use "class_field.mtt"::::end::
                ::end::
                </div>
            ::end::
        </div>
        
        <h3 class="section" ::cond hasMethods::>Inherited Methods</h3>
        <div class="fields" ::cond hasMethods::>
            ::set fields=inheritedFields.methods::
            ::foreach cl inheritedFields.types::
                <h4 ::cond fields.get(cl).length>0::><a href="#" class="expand-button"><i class="fa fa-arrow-circle-o-right"></i></a> Defined by $$printLinkedPath(::cl.path::,::null::)</h4>
                <div style="display:none">
                ::foreach field fields.get(cl)::
                ::set isStatic = false::
                    ::if field.name != "new" ::
                        ::set type=cl::
                        ::use "class_field.mtt"::::end::
                    ::end::
                ::end::
                </div>
            ::end::
        </div>
    </div>
::end::
</macro>

<macro name="printPackage(type)">
    ::if type.path.indexOf(".") >= 0::
        ::set packagePath = type.path.split(".").slice(0, -1).join(".")::
        <h4><small>package <a ::attr href api.packageToUrl(packagePath)::>::packagePath::</a></small></h4>
    ::else::
        <h4><small><a href="./">no package</a></small></h4>
    ::end::
</macro>