This repository has been archived by the owner on Sep 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
f321118
commit d5dd11b
Showing
15 changed files
with
286 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.local.ini | ||
*.local.ini.old |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
=========================================================================*/ | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@'; | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@'; | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |