Skip to content

Commit

Permalink
Metadata processing
Browse files Browse the repository at this point in the history
- Currently hide `@:impl` `@:value` `@:has_untyped`, `@:hlNative` with css
- Add deprecation message. Close #209
- Add "extends" for @:generic. #218 Doesnt help on the other case, since `GenericClass_String` (from example) is never registered as actual type.
  • Loading branch information
markknol committed Mar 7, 2018
1 parent d40b658 commit 6c36cce
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 11 deletions.
30 changes: 29 additions & 1 deletion test/TestClass.hx
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,38 @@ class TestFieldVisibility
private function functionPrivateShown() {}
}


@:deprecated("Use newer class")
@:generic
class TestMetaData
{
/**
Deprecated red color value
**/
@:metaWithParams("123", 123)
@:deprecated("Use `red` instead")
@:metaWithoutParams
public static var deprecatedRed = 0xFF0000;


/**
Cool red color value Dont use `deprecatedRed`, `TestMetaData.deprecatedRed`, `RED`, `TestMetaData.RED` or `Std.int` or `haxe.io.Eof.new`
**/
@:meta
@:to
public static var red = 12;
public static var RED = 12;

}


/**
This should not be visible on the index page.
**/
class Index
{

}
}

@:generic class GenericClass<T> {}
class ChildOfGeneric extends GenericClass<String> {}
23 changes: 21 additions & 2 deletions themes/default/resources/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ footer{
}

.availability {
color: #AB611A;
color: #e48931;
font-size: 90%;
}

Expand All @@ -115,10 +115,29 @@ h3 code {
margin-left: -10px;
}

h3 span.label {
h3 span.label, .label-meta {
margin-right: 5px;
}

.label.label-meta {
background:#5959AC;
}

/* hide useless meta */
.label-meta-impl, .label-meta-value, .label-meta-has_untyped, .label-meta-hlNative, .label-meta-access, .label-meta-allow, .label-meta-keep, .label-meta-dox, .label-meta-noCompletion {
display:none;
}

.label-meta.label-meta-from, .label-meta.label-meta-to {
background:#a93685;
}

.alert.alert-deprecated {
font-size: 90%;
margin-bottom: 10px;
padding: 4px 35px 4px 14px;
}

code {
font-family: Monaco,Menlo,Consolas,"Courier New",monospace;
font-weight: normal;
Expand Down
16 changes: 12 additions & 4 deletions themes/default/templates/class.mtt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@
::if type.superClass != null::
<h4>
::set inheritedFields = api.getInheritedFields(type)::
<small>extends ::foreach t inheritedFields.types::
$$printLinkedPath(::t.path::,::null::)::if ((inheritedFields.types.length!=1)&&(repeat.t.index<(inheritedFields.types.length-1))):: &rsaquo; ::end::
::end::
<small>extends
::if (inheritedFields.types.length>0)::
::foreach t inheritedFields.types::
$$printLinkedPath(::t.path::,::null::)::if ((inheritedFields.types.length!=1)&&(repeat.t.index<(inheritedFields.types.length-1))):: &rsaquo; ::end::
::end::
::else::
$$printLinkedPath(::type.superClass.path::,::null::)
::end::
</small>
</h4>
::end::
Expand All @@ -25,7 +30,7 @@
::end::
</small>
</h4>

$$printModule(::type.module::)

<h4 ::cond subClasses !=null::>
Expand All @@ -42,6 +47,9 @@
::use "related_types.mtt"::::end::
</small>
</h4>

$$printMeta(::type::)

$$printPlatforms(::type.platforms::,::true::)
</div>
<div class="body">
Expand Down
4 changes: 4 additions & 0 deletions themes/default/templates/class_field.mtt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
::end::

<a ::attr name field.name::></a>

<h3>
<p class="anchor">$$printFieldSignature(::field::,::isStatic::,::type::)</p>
::if field.overloads != null::
Expand All @@ -16,9 +17,12 @@
::end::
::end::
</h3>
$$printFieldDeprecation(::field::)

::if field.platforms.length != type.platforms.length && field.platforms.length > 0 && field.platforms.length < api.config.platforms.length::
$$printPlatforms(::field.platforms::,::false::)
::end::

::if field.doc != null::
<div class="doc">::raw field.doc::</div>
::end::
Expand Down
3 changes: 3 additions & 0 deletions themes/default/templates/enum_field.mtt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div class="field">

<h3>
<code>
<a name="::ctor.name::" href="#::ctor.name::">
Expand All @@ -9,6 +10,8 @@
::end::
</code>
</h3>
$$printFieldDeprecation(::ctor::)

<div class="doc" ::cond ctor.doc != null::>
::raw ctor.doc::
</div>
Expand Down
48 changes: 44 additions & 4 deletions themes/default/templates/macros.mtt
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,64 @@
</p>
</macro>

<macro name="printFieldDeprecation(field)">
::if (field.meta != null)::
::foreach meta field.meta::
::if (meta.name == ":deprecated")::
<div class="alert alert-warning alert-deprecated">
<strong>Deprecated:</strong>
::if (meta.params != null && meta.params.length > 0)::
::foreach param meta.params::
::param::
::if !repeat.param.last::, ::end::
::end::
::end::
</div>
::end::
::end::
::end::
</macro>

<macro name="printMeta(field)">
::if (field.meta != null)::
::foreach meta field.meta::
::if (meta.name != ":deprecated")::::if false::<!--skip deprecation meta, see printFieldDeprecation -->::end::
::set metaName = meta.name.substr(1)::
::set displayMetaName = "@" + meta.name::
<span class="label label-meta label-meta-::metaName::" title="::displayMetaName:: metadata">::displayMetaName::
::if (meta.params != null && meta.params.length > 0)::(
::foreach param meta.params::
$$printMetaParam(::param::)
::if !repeat.param.last::,::end::
::end::
)::end::</span>
::end::
::end::
::end::
</macro>

<macro name="printMetaParam(param)">::if (param.substr(0,9) == "<![CDATA[")::::param.substr(9,param.length-3-9)::::else::::param::::end::</macro>

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

$$printMeta(::field::)

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

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

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

::if fieldInfo.modifiers.isInline::
<span class="label">inline</span>
<span class="label label-inline">inline</span>
::end::

::switch fieldInfo.kind::
Expand Down

0 comments on commit 6c36cce

Please sign in to comment.