Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
ENH: refs #982. CMake script for creating a new skeleton module
Browse files Browse the repository at this point in the history
This script will create a very minimal skeleton of a module.  The example
template can definitely be fleshed out and improved in the future to
contain more examples of common things people do in modules, e.g. loading
a dao using a model class, implementing a pdo function for searching
records by a certain field, etc.
  • Loading branch information
zachmullen committed Mar 20, 2013
1 parent f321118 commit d5dd11b
Show file tree
Hide file tree
Showing 15 changed files with 286 additions and 0 deletions.
35 changes: 35 additions & 0 deletions utils/NewModule.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This CMake script should be used to create a new Midas module. Requires CMake v2.8.3+
# Call as
# cmake -P NewModule.cmake modulename
# Where modulename is the name of your module. It should have no spaces in it.
#
if(NOT DEFINED CMAKE_ARGV3)
message(FATAL_ERROR "Must pass in module name as an argument: cmake -P NewModule.cmake mymodule")
endif()

set(moduleName "${CMAKE_ARGV3}")
set(templateRoot "${CMAKE_CURRENT_LIST_DIR}/moduleTemplate")
string(SUBSTRING "${moduleName}" 0 1 firstChar)
string(SUBSTRING "${moduleName}" 1 -1 restOfString)
string(TOUPPER ${firstChar} firstChar)
string(TOLOWER "${restOfString}" restOfString)
string(TOLOWER "${moduleName}" MN)
set(MN_CAP "${firstChar}${restOfString}")
set(moduleRoot "${CMAKE_CURRENT_LIST_DIR}/../modules/${MN}")

message("Creating skeleton module at ${moduleRoot}")
if(EXISTS "${moduleRoot}")
message(FATAL_ERROR "File or directory already exists: ${moduleRoot}")
endif()

file(MAKE_DIRECTORY "${moduleRoot}")
file(GLOB_RECURSE templateFiles RELATIVE "${templateRoot}" "${templateRoot}/*")
foreach(templateFile ${templateFiles})
set(fullPath "${templateRoot}/${templateFile}")
if(IS_DIRECTORY "${fullPath}")
file(MAKE_DIRECTORY "${moduleRoot}/${templateFile}")
else()
configure_file("${fullPath}" "${moduleRoot}/${templateFile}" @ONLY)
endif()
endforeach()
message("Done")
19 changes: 19 additions & 0 deletions utils/moduleTemplate/AppController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
69328 Lyon, FRANCE.
See Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/

/** App controller for the @MN@ module */
class @MN_CAP@_AppController extends MIDAS_GlobalModule
{
public $moduleName = '@MN@';
} //end class
?>
26 changes: 26 additions & 0 deletions utils/moduleTemplate/Notification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/** notification manager*/
class @MN_CAP@_Notification extends MIDAS_Notification
{
public $moduleName = '@MN@';

/** init notification process */
public function init()
{
$fc = Zend_Controller_Front::getInstance();
$this->moduleWebroot = $fc->getBaseUrl().'/modules/'.$this->moduleName;
$this->coreWebroot = $fc->getBaseUrl().'/core';

$this->addCallBack('CALLBACK_CORE_ITEM_DELETED', 'handleItemDeleted');
}

/**
* STUB: example of receiving a callback when an item is deleted
*/
public function handleItemDeleted($params)
{
$itemDao = $params['item'];
// TODO do something about this item dao
}
}
?>
2 changes: 2 additions & 0 deletions utils/moduleTemplate/configs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.local.ini
*.local.ini.old
11 changes: 11 additions & 0 deletions utils/moduleTemplate/configs/module.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[global]
; version of the module
version = 1.0.0
; full name of the module (displayed on admin page)
fullname = @MN_CAP@
; description (displayed on admin page)
description = "Enter your description here"
; Category (default is "Core")
category = Core
; Dependencies (comma separated list of other module dependencies
dependencies =
13 changes: 13 additions & 0 deletions utils/moduleTemplate/constant/module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
69328 Lyon, FRANCE.
See Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/

?>
39 changes: 39 additions & 0 deletions utils/moduleTemplate/controllers/ThingController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/** Controller template for the @MN@ module */
class @MN_CAP@_ThingController extends @MN_CAP@_AppController
{
public $_models = array();
public $_moduleModels = array();

// STUB
function getAction()
{
$id = $this->_getParam('id');
$this->view->id = $id;
}

// STUB
function createAction()
{
$this->disableLayout();
$this->disableView();
echo JsonComponent::encode(array('status' => 'ok', 'message' => 'Done'));
}

// STUB
function updateAction()
{
$this->disableLayout();
$this->disableView();
echo JsonComponent::encode(array('status' => 'ok', 'message' => 'Done'));
}

// STUB
function deleteAction()
{
$this->disableLayout();
$this->disableView();
echo JsonComponent::encode(array('status' => 'ok', 'message' => 'Done'));
}
}//end class
6 changes: 6 additions & 0 deletions utils/moduleTemplate/database/mysql/1.0.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

CREATE TABLE IF NOT EXISTS `@MN@_thing` (
`thing_id` bigint(20) NOT NULL AUTO_INCREMENT,
`creation_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`thing_id`),
);
5 changes: 5 additions & 0 deletions utils/moduleTemplate/database/pgsql/1.0.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

CREATE TABLE @MN@_thing (
thing_id serial PRIMARY KEY,
creation_date timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
);
8 changes: 8 additions & 0 deletions utils/moduleTemplate/models/AppDao.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

/** App dao for @MN@ module */
class @MN_CAP@_AppDao extends MIDAS_GlobalDao
{
public $_module = '@MN@';
} //end class
?>
18 changes: 18 additions & 0 deletions utils/moduleTemplate/models/AppModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
69328 Lyon, FRANCE.
See Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/

/** Base model class for the @MN@ module */
class @MN_CAP@_AppModel extends MIDASModel
{
public $moduleName = '@MN@';
}
?>
36 changes: 36 additions & 0 deletions utils/moduleTemplate/models/base/ThingModelBase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
All rights reserved.
More information http://www.kitware.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/
abstract class @MN_CAP@_ThingModelBase extends @MN_CAP@_AppModel
{
/** constructor */
public function __construct()
{
parent::__construct();
$this->_name = '@MN@_thing';
$this->_key = 'thing_id';

$this->_mainData = array(
'thing_id' => array('type' => MIDAS_DATA),
'creation_date' => array('type' => MIDAS_DATA)
);
$this->initialize();
}
}
?>
26 changes: 26 additions & 0 deletions utils/moduleTemplate/models/dao/ThingDao.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
All rights reserved.
More information http://www.kitware.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/
/** Dao for @MN@ thing */
class @MN_CAP@_ThingDao extends @MN_CAP@_AppDao
{
public $_model = 'Thing';
public $_module = '@MN@';
}
?>
26 changes: 26 additions & 0 deletions utils/moduleTemplate/models/pdo/ThingModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
All rights reserved.
More information http://www.kitware.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/
require_once BASE_PATH.'/modules/@MN@/models/base/ThingModelBase.php';

/** Thing model pdo implementation */
class @MN_CAP@_ThingModel extends @MN_CAP@_ThingModelBase
{
}
?>
16 changes: 16 additions & 0 deletions utils/moduleTemplate/views/thing/get.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
69328 Lyon, FRANCE.
See Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
?>

<div class="viewMain">
The id parameter passed in is: <?php echo $this->id ?>
</div>

0 comments on commit d5dd11b

Please sign in to comment.