Modules

From TheWebMind.org Docs

Jump to: navigation, search

Contents

Concept

The engine of theWebMind 2.0 does not generate code, itself. It's responsable for the comprehension of the problem transponding it to the machine understandment. To generate the code, files and directories of your project, you got to choose a module. This modules allow you to choose different patterns of code to be generated... different frameworks as well. And why not, even different languages. The choosen module will deal with theWebMind to have access to the inteligence already translated by Mind2.0 and to generate its codes followint its patterns. Once we have the current project already saved and runned, theWebmind already understood it and is showing you its output due to have your confirmation, if it is all correct as it understood. Then, using the Generate tool, we choose the module we want theWebMind to create the files and code. Modules are developed and runned in PHP, but the code and files it generates are written by the module itself. We can have a module in php which create .jsp or .py files, for example. The modueles structure supports a configuration file. After choosing the module we want to use to generate the project, its configuration page will be displayed. Once we generated the project, we can see the generated files accessing "View>Temp Project Files". When the project is stable and we know it can be joined to the main project of the group of developers, we can use the Commit tool. With this tool, all these files will be accessible from other developers and will be in the main structure of your project, in case it's been developed in a group of developers. Anytime we can use the UpDate tool to have access to the code generated from ther developers working in the same project. We can see the structure and files generated to the project, in the main structure using the menu "View>Current Project Files". Before commiting, the generated files and codes are visible only to the developer who created them, not to the group.

Adding new modules

To install new modules, you can access the [[1]] portal, where you will find a bunch of modules developed by contributors all arount the world. You can be one of them Creating new modules

Note: To run theWebMind, you will NOT need anything else but PHP. Even though, some modules may require some library to 
work, such as MCrypt, PDO or GD.
Please, verify the module documentation.
Note: The page to download modules is still under construction

Creating new modules

The contribution developers have done with theWebMind is the main point to make it grow stronger and trustful. We tried to keep the way to create modules in the easiest way as possible. Follow the basic instructions.

Structure

Main directory: it holds the name of the module. All the files must be in this directory. The required files are: ->conf.xml ->info.xml ->nomeDoMódulo.php ->data: files and structure the mudule might need

conf.xml

Here, the pattern to create your conf.xml file

<?xml version="1.0" encoding="UTF-8"?>
<root>
   <scripts>
       <js src="my_js2.js" />
   </scripts>
   <styles>
       <css src="my_style.css" />
   </styles>
   <config src="page.php" />
</root>

Into the scripts tree, we can put a list of "js" elements whose "src" attributes point to javascript files inside the data directory of the module. They will be automaticaly loaded. The same with styles and "css" elements. The config element uses the src attribute to identify where, also inside the data directory, is the file to be loaded and to have the scripts and styles added. This file is the last step of the "Generating" tool and its inputs will be also submited to the module by POST.

info.xml

<?xml version="1.0" encoding="iso-8859-1"?>
<root>
	<name value="Module2" />
	<fullName value="Second Module"/>
	<language value="PHP" />
	<details>
		<detail name="Pattern" value="DAO" />
		<detail name="Pattern" value="MVC" />
		<detail name="Technology" value="Ajax" />
		<detail name="Requirement" value="GDLib" />
	</details>
	<version value="1.0" />
	<description value="Example" />
	<authors>
		<author value="Felipe Nascimento de Moura" email='felipe@thewebmind.org'/>
		<author value="Jaydson Nascimento Gomes" email='jaydson@thewebmind.org'/>
	</authors>
	<date value="09/09/2009" />
	<thumb value="print.jpg" />
	<license value="license.txt" />
</root>

Looking to this structure, we see it's quite intuitive. We use the encoding="iso-8859-1" to use any accent that could be used in names or description, for example.

name: the name of the module. MUST be exactly equal to the name of the directory and the name of the class.
fullname: allows you to set a full and more descriptive name to your module.
language: indentifies the language your module will generate. Mind wont treat it.
details: You can add the many details you want as long as you use the name and value attributes.
version: the current version of your module
description: you can add any extra information or detail in here.
authors: Use "author" elements to identify the authors with name and email.
date: here, you will put the creation date of your module. We advise the use of MM/YYY pattern
thumb: set here a thumbnail to your project, like a printscreen.
license: the license file, inside your "data" directory.
NOTE: Your module does not NEED to follow the Mind2.0 license. 

What means you can specify your own preffered license and even ask for money of rights for the module you created.

.PHP

The main file of the module. It MUST have the same name (yes, it's case sensitive) of the directory and the name informed in info.xml. To use as example, we will use the name NewModule. The class, in this file, has the same name. This class MUST implement the "module_interface" interface and extend the class "Module".

class NewModule extends Module implements module_interface
{}

The interface implements this structure:

public function getStructure():String;
public function onStart();
public function onFinish();
public function applyCRUD($entity);
public function callExtra();

The function getStructure returns the name of directory inside your "data" folder which Mind will use to COPY AND PAST to the generated project. You can use this structure directory to specify a fixed structure or to copy all the libraries or framework files the generated project will need. The function onStart will be called before the project is generated, after the copy of the needed files. At this moment, you can generate some extra files, such as documentation, log, etc., as you need.
The same way, the onFinish is called. You can use it to anything you believe should happen after the generation of files. At this time, all the files have already been created. applyCrud is the most important method to your module. This method receives all the inteligente theWebMind has acquired with all the entities, structures, and details. In this method, you should create the files each entity will need, or not, and set their content.

FrameWork

There is also a FrameWork that can be accessed streight from your moule to create files or to load contents easily. You can access it this way:

$this->fw->[method/attribute]

Please, notice that it is NOT needed to specify this variable, it is inherited. Here, its methods:

getContent($file) : returns the content of a valid file inside your data directory
mkFile($file, $conteudo): creates a file with that content. BUT, this method will create files inside
the project structure, instead of your data directory.

With time, we will provide new methods to make your job easier.

Native ZendModels

ZendModels is a PHP code generator based on Zend Framework.

- Goals
The main goal ZendModels has is focused to generate the basis of the structure following the MVC pattern with Zend Framework.

- What for
Together, theWebMind's platform and the ZendModels you can automate the process of the hardest part of your codding work.
With a few lines of WML code, ZendModels is able to generate the ideal MVC structure to you start developing the system.

- How to use
Generating a system into theWebMind using ZendModels is extremely easy.
After writing your WML code, just click the "Generate" button.
Then, in the first step, select the option about the database you want(or not) to generate, and in the second step, choose the ZendModels to load.
The third step references to the advanced options the choosen module has got, though ZendModels has no advanced options on its first version. With this done, you can simply copy the generated application to anywhere you might prefer or even access it directly in your profile's directory: restrict/users/<username>/root/temp/<applicationname>.

- How it works
TheWebMind interprets the WML code and passes the structure with all the inteligence it could understand about the system you coded to the choosen module.
ZendModels uses this structure to generate the MVC structure of files, based on ZendFramework adivese(and requirements).
The code generated by ZendModels is easy to understand and to read for developers used to work with OO and PHP.
Visit the repository to see its code: http://code.google.com/p/webmind/source/browse/trunk/restrict/modules/ZendModels/ZendModels.php

Many new features and (corrections) may be done.
Want to help?
Contact us by contact@thewebmind.org

- Dependences
ZendModels is native, when you doenload theWebMind it's alread there.
Even though, you will need the Zend Framework running in your localhost. We advise you to have the "library" directory in your localhost.
It will also need the "mod-rewrite" on in your server.

- Example

WML:
Each student has name:string(100). All the teacher have name:string(100). Teacher has many student. Also, student has many teacher.
Generated structure
 - applicaion
   - models
     Student.php
     Teacher.php
   - views
     - scripts
      - Student
      - Teacher
      - index
      index.phtml
      default.phtml
   - controllers
     IndexController.php
     StudentController.php
     TeacherController.php
Personal tools