Skip to content

Commit

Permalink
Merge pull request #446 from ccrma/ckdoc-sort-option
Browse files Browse the repository at this point in the history
add option to disable alphabetical sorting of ckdoc
  • Loading branch information
gewang authored Jun 20, 2024
2 parents 310f328 + 6877d5f commit 15e3343
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
49 changes: 40 additions & 9 deletions src/core/ulib_doc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ CK_DLL_CTRL( CKDoc_examplesRoot_set );
CK_DLL_CGET( CKDoc_examplesRoot_get );
CK_DLL_CTRL( CKDoc_outputFormat_set );
CK_DLL_CGET( CKDoc_outputFormat_get );
CK_DLL_MFUN( CKDoc_sort_set );
CK_DLL_MFUN( CKDoc_sort_get );
CK_DLL_MFUN( CKDoc_genIndex );
CK_DLL_MFUN( CKDoc_genCSS );
CK_DLL_MFUN( CKDoc_genGroups );
Expand Down Expand Up @@ -172,6 +174,17 @@ DLL_QUERY ckdoc_query( Chuck_DL_Query * QUERY )
func->doc = "Set which output format is selected; see CKDoc.HTML, CKDoc.TEXT, CKDoc.MARKDOWN, CKDoc.JSON.";
if( !type_engine_import_mfun( env, func ) ) goto error;

// CKDoc toggle sort | 1.5.2.5 (@kellyyyyyyyyyyyyyyyy @azaday)
func = make_new_mfun( "int", "sort", CKDoc_sort_set );
func->add_arg( "int", "toggle" );
func->doc = "Enable or disable alphabetical sorting of functions and variables.";
if( !type_engine_import_mfun( env, func ) ) goto error;

// CKDoc get sort status | 1.5.2.5 (@kellyyyyyyyyyyyyyyyy @azaday)
func = make_new_mfun( "int", "sort", CKDoc_sort_get );
func->doc = "Get the current status of alphabetical sorting.";
if( !type_engine_import_mfun( env, func ) ) goto error;

// genIndex
func = make_new_mfun( "string", "genIndex", CKDoc_genIndex );
func->add_arg( "string", "indexTitle" );
Expand Down Expand Up @@ -811,6 +824,8 @@ CKDoc::CKDoc( Chuck_VM * vm )
// reset
m_format = FORMAT_NONE;
m_output = NULL;
// enable alphabetical sorting by default
m_sort_entries = true;

// default
setOutputFormat( FORMAT_HTML );
Expand Down Expand Up @@ -1025,7 +1040,7 @@ t_CKBOOL CKDoc::setOutputFormat( t_CKINT which )
// name: getOutputFormat()
// desc: get output format
//-----------------------------------------------------------------------------
t_CKINT CKDoc::getOutpuFormat() const
t_CKINT CKDoc::getOutputFormat() const
{
return m_format;
}
Expand Down Expand Up @@ -1316,12 +1331,15 @@ string CKDoc::genType( Chuck_Type * type, t_CKBOOL clearOutput )
}
}

// sort
sort( svars.begin(), svars.end(), ck_comp_value );
sort( mvars.begin(), mvars.end(), ck_comp_value );
sort( sfuncs.begin(), sfuncs.end(), ck_comp_func );
sort( mfuncs.begin(), mfuncs.end(), ck_comp_func );
sort( ctors.begin(), ctors.end(), ck_comp_func_args );
// sort | 1.5.2.5 (@kellyyyyyyyyyyyyyyyy @azaday) added check
if( m_sort_entries )
{
sort( svars.begin(), svars.end(), ck_comp_value );
sort( mvars.begin(), mvars.end(), ck_comp_value );
sort( sfuncs.begin(), sfuncs.end(), ck_comp_func );
sort( mfuncs.begin(), mfuncs.end(), ck_comp_func );
sort( ctors.begin(), ctors.end(), ck_comp_func_args );
}

// whether to potentially insert a default constructor | 1.5.2.0
t_CKBOOL insertDefaultCtor = type_engine_has_implicit_def_ctor( type );
Expand Down Expand Up @@ -1731,14 +1749,27 @@ CK_DLL_CTRL( CKDoc_outputFormat_set )
// attempt to set
ckdoc->setOutputFormat( format );
// return (could be different than requested)
RETURN->v_int = ckdoc->getOutpuFormat();
RETURN->v_int = ckdoc->getOutputFormat();
}

CK_DLL_CGET( CKDoc_outputFormat_get )
{
CKDoc * ckdoc = (CKDoc *)OBJ_MEMBER_UINT(SELF, CKDoc_offset_data);
// return
RETURN->v_int = ckdoc->getOutpuFormat();
RETURN->v_int = ckdoc->getOutputFormat();
}

CK_DLL_MFUN( CKDoc_sort_set )
{
CKDoc * ckdoc = (CKDoc *)OBJ_MEMBER_UINT(SELF, CKDoc_offset_data);
ckdoc->m_sort_entries = GET_NEXT_INT(ARGS);
RETURN->v_int = ckdoc->m_sort_entries;
}

CK_DLL_MFUN( CKDoc_sort_get )
{
CKDoc * ckdoc = (CKDoc *)OBJ_MEMBER_UINT(SELF, CKDoc_offset_data);
RETURN->v_int = ckdoc->m_sort_entries;
}

CK_DLL_MFUN( CKDoc_genIndex )
Expand Down
6 changes: 5 additions & 1 deletion src/core/ulib_doc.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class CKDoc
// set output format: CKDoc.HTML, CKDoc.TEXT, CKDoc.MARKDOWN, CKDoc.JSON
t_CKBOOL setOutputFormat( t_CKINT which );
// get output format
t_CKINT getOutpuFormat() const;
t_CKINT getOutputFormat() const;
// set base examples root path
void setExamplesRoot( const std::string & path );
// get base examples root path
Expand All @@ -189,6 +189,10 @@ class CKDoc
// generate documentation for a single Type
std::string genType( Chuck_Type * type, t_CKBOOL clearOutput = TRUE );

public:
// sort functions and variables | 1.5.2.5 (@kellyyyyyyyyyyyyyyyy @azaday) added
t_CKBOOL m_sort_entries;

public:
// enumeration for output format types
static const t_CKINT FORMAT_NONE; // no output format
Expand Down

0 comments on commit 15e3343

Please sign in to comment.