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

Commit d5dd11b

Browse files
committed
ENH: refs #982. CMake script for creating a new skeleton module
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.
1 parent f321118 commit d5dd11b

File tree

15 files changed

+286
-0
lines changed

15 files changed

+286
-0
lines changed

utils/NewModule.cmake

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# This CMake script should be used to create a new Midas module. Requires CMake v2.8.3+
2+
# Call as
3+
# cmake -P NewModule.cmake modulename
4+
# Where modulename is the name of your module. It should have no spaces in it.
5+
#
6+
if(NOT DEFINED CMAKE_ARGV3)
7+
message(FATAL_ERROR "Must pass in module name as an argument: cmake -P NewModule.cmake mymodule")
8+
endif()
9+
10+
set(moduleName "${CMAKE_ARGV3}")
11+
set(templateRoot "${CMAKE_CURRENT_LIST_DIR}/moduleTemplate")
12+
string(SUBSTRING "${moduleName}" 0 1 firstChar)
13+
string(SUBSTRING "${moduleName}" 1 -1 restOfString)
14+
string(TOUPPER ${firstChar} firstChar)
15+
string(TOLOWER "${restOfString}" restOfString)
16+
string(TOLOWER "${moduleName}" MN)
17+
set(MN_CAP "${firstChar}${restOfString}")
18+
set(moduleRoot "${CMAKE_CURRENT_LIST_DIR}/../modules/${MN}")
19+
20+
message("Creating skeleton module at ${moduleRoot}")
21+
if(EXISTS "${moduleRoot}")
22+
message(FATAL_ERROR "File or directory already exists: ${moduleRoot}")
23+
endif()
24+
25+
file(MAKE_DIRECTORY "${moduleRoot}")
26+
file(GLOB_RECURSE templateFiles RELATIVE "${templateRoot}" "${templateRoot}/*")
27+
foreach(templateFile ${templateFiles})
28+
set(fullPath "${templateRoot}/${templateFile}")
29+
if(IS_DIRECTORY "${fullPath}")
30+
file(MAKE_DIRECTORY "${moduleRoot}/${templateFile}")
31+
else()
32+
configure_file("${fullPath}" "${moduleRoot}/${templateFile}" @ONLY)
33+
endif()
34+
endforeach()
35+
message("Done")
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*=========================================================================
4+
MIDAS Server
5+
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
6+
69328 Lyon, FRANCE.
7+
8+
See Copyright.txt for details.
9+
This software is distributed WITHOUT ANY WARRANTY; without even
10+
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11+
PURPOSE. See the above copyright notices for more information.
12+
=========================================================================*/
13+
14+
/** App controller for the @MN@ module */
15+
class @MN_CAP@_AppController extends MIDAS_GlobalModule
16+
{
17+
public $moduleName = '@MN@';
18+
} //end class
19+
?>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/** notification manager*/
3+
class @MN_CAP@_Notification extends MIDAS_Notification
4+
{
5+
public $moduleName = '@MN@';
6+
7+
/** init notification process */
8+
public function init()
9+
{
10+
$fc = Zend_Controller_Front::getInstance();
11+
$this->moduleWebroot = $fc->getBaseUrl().'/modules/'.$this->moduleName;
12+
$this->coreWebroot = $fc->getBaseUrl().'/core';
13+
14+
$this->addCallBack('CALLBACK_CORE_ITEM_DELETED', 'handleItemDeleted');
15+
}
16+
17+
/**
18+
* STUB: example of receiving a callback when an item is deleted
19+
*/
20+
public function handleItemDeleted($params)
21+
{
22+
$itemDao = $params['item'];
23+
// TODO do something about this item dao
24+
}
25+
}
26+
?>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.local.ini
2+
*.local.ini.old
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[global]
2+
; version of the module
3+
version = 1.0.0
4+
; full name of the module (displayed on admin page)
5+
fullname = @MN_CAP@
6+
; description (displayed on admin page)
7+
description = "Enter your description here"
8+
; Category (default is "Core")
9+
category = Core
10+
; Dependencies (comma separated list of other module dependencies
11+
dependencies =
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
5+
69328 Lyon, FRANCE.
6+
7+
See Copyright.txt for details.
8+
This software is distributed WITHOUT ANY WARRANTY; without even
9+
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10+
PURPOSE. See the above copyright notices for more information.
11+
=========================================================================*/
12+
13+
?>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/** Controller template for the @MN@ module */
4+
class @MN_CAP@_ThingController extends @MN_CAP@_AppController
5+
{
6+
public $_models = array();
7+
public $_moduleModels = array();
8+
9+
// STUB
10+
function getAction()
11+
{
12+
$id = $this->_getParam('id');
13+
$this->view->id = $id;
14+
}
15+
16+
// STUB
17+
function createAction()
18+
{
19+
$this->disableLayout();
20+
$this->disableView();
21+
echo JsonComponent::encode(array('status' => 'ok', 'message' => 'Done'));
22+
}
23+
24+
// STUB
25+
function updateAction()
26+
{
27+
$this->disableLayout();
28+
$this->disableView();
29+
echo JsonComponent::encode(array('status' => 'ok', 'message' => 'Done'));
30+
}
31+
32+
// STUB
33+
function deleteAction()
34+
{
35+
$this->disableLayout();
36+
$this->disableView();
37+
echo JsonComponent::encode(array('status' => 'ok', 'message' => 'Done'));
38+
}
39+
}//end class
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
CREATE TABLE IF NOT EXISTS `@MN@_thing` (
3+
`thing_id` bigint(20) NOT NULL AUTO_INCREMENT,
4+
`creation_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
5+
PRIMARY KEY (`thing_id`),
6+
);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
CREATE TABLE @MN@_thing (
3+
thing_id serial PRIMARY KEY,
4+
creation_date timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
5+
);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
/** App dao for @MN@ module */
4+
class @MN_CAP@_AppDao extends MIDAS_GlobalDao
5+
{
6+
public $_module = '@MN@';
7+
} //end class
8+
?>

0 commit comments

Comments
 (0)