Libraries: Master: Adding New Components: Unterschied zwischen den Versionen

Aus CodeCoupler Wiki
Zur Navigation springen Zur Suche springen
Tm (Diskussion | Beiträge)
Die Seite wurde neu angelegt: „To add new components you have to follow the following steps: First of all think about a key and a namespace for your component. * Root namespaces are at thi…“
 
Tm (Diskussion | Beiträge)
Keine Bearbeitungszusammenfassung
 
(3 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
To add new components you have to follow the following steps:
For now there is no setup logic to install new components, neither a package definition. So you have to do it manually. To add new components you have to follow the following simple steps:


First of all think about a key and a namespace for your component.
== Naming the Component ==


* Root namespaces are at this time:
First of all think about a key and a namespace for your component. Namespaces can be divided into further subnamespaces. Root namespaces are at this time:
** frameworks: Basic CSS and JS Libraries.
** polyfills: Components for legacy browser support.
** gui-libraries: Components displaying GUI-Widgets or animate GUI-Elements. This namespace will be further divided into logical groups like "sliders", "grids" etc.
* Namespaces can be divided into further subnamespaces. Every division in a namespace will be separated by a point.


Now create a new subdirectory hierarchy within the folder '''components''' according to your namespace hierarchy.
* frameworks: Basic CSS and JS Libraries.
* polyfills: Components for legacy browser support.
* gui-libraries: Components displaying GUI-Widgets or animate GUI-Elements. This namespace will be further divided into logical groups like "sliders", "grids" etc.


* Name the last folder like the key of your component you want add followed by a dash and a version number. Using a version number enable the system to use long term caching while updating correctly new versions of the component.
== Place Assets ==
* Within this folder you are free to place assets however you want. You can create subfolders or place all into the root of this folder. '''Put here only the minimum you need, and only minified versions of the library if possible.'''


Create a new subdirectory hierarchy within the folder '''codecoupler/views/components'''.
Create a new subdirectory hierarchy within the folder '''components/assets''' according to your namespace hierarchy.


* Name the last folder like the key of your component you want to add, without any version information.
Into this subfolder you are free to place assets however you want. You can create subfolders or place all into the root of this folder.
* Place in there four files including the HTML-code needed to for your component.
 
* You can use the folder '''codecoupler/views/components/_empty_template''' as template to copy from.
'''Remarks/Conventions:'''
* The files have the following meanings and have to be named as follows:
* Put here only the minimum you need, and only minified versions of the library if possible.
** '''head_init:''' HTML-Code to include into the start of the head.
 
** '''head_finish:''' HTML-Code to include before the end of the head.
== Create Views ==
** '''body_init:''' HTML-Code to include into the start of the body.
 
** '''body_finish:''' HTML-Code to include before the end of the body.
Create a new subdirectory hierarchy within the folder '''components/views''' according to your namespace hierarchy.
 
Place into this subfolder a maximum of four files including the HTML-code needed to for your component. You can use the folder '''components/views/_empty_template''' as template to copy from. The files have the following meanings and have to be named as follows:
 
* '''head_init:''' HTML-Code to include into the start of the head.
* '''head_finish:''' HTML-Code to include before the end of the head.
* '''body_init:''' HTML-Code to include into the start of the body.
* '''body_finish:''' HTML-Code to include before the end of the body.
 
You do not have to add one of these files if it has no content. Links to your assets have to be declared as follows:
 
<syntaxhighlight>
<link href="components/assets/PATH_TO_COMPONENT/YOUR_OWN_SUBPATHS/YOUR_ASSET_FILENAME" rel="stylesheet">
<script src="components/assets/PATH_TO_COMPONENT/YOUR_OWN_SUBPATHS/YOUR_ASSET_FILENAME"></script>
</syntaxhighlight>
 
'''Remarks/Conventions:'''
* The links to the javascript files of the component should be placed into '''body_finish'''. This should done to display the page faster to the user. Components using javascript using javascript libraries like jQuery can only be placed there, because jQuery will be loaded at the end of the body first.
* The links to the javascript files of the component should be placed into '''body_finish'''. This should done to display the page faster to the user. Components using javascript using javascript libraries like jQuery can only be placed there, because jQuery will be loaded at the end of the body first.


Add in the file '''application/config/components.php''' two configuration variables as follows:
== Setup Configuration ==
 
Create a new subdirectory hierarchy within the folder '''components/config''' according to your namespace hierarchy.
 
Place into this subfolder a file named '''setup.php'''. Add into this file two configuration variables as follows:
 
* '''$config['master_components_setup']['FQN_NAME_OF_YOUR_COMPONENT']['depends']'''<br>Set here a string or an array of strings, if your component depends other components. Otherwise set it to NULL. The strings are the names of the components your component depend on. Your component will loaded then after the components noted here and the depending components will be enabled automatically.
* '''$config['master_components_setup']['FQN_NAME_OF_YOUR_COMPONENT']['after']'''<br>Set here a string or an array of strings, if your component should be loaded after other components, if they are enabled. Otherwise set it to NULL. The strings are the names of the components your component should be loaded after.
 
Place into this subfolder a file named '''config.php'''. Add into this file one configuration variable as follows:
 
* '''$config['master_components']['FQN_NAME_OF_YOUR_COMPONENT']['config']'''<br>Set here an assoziative array of objects if you want to be your component customizable. Otherwise set it to NULL. You can access the values of the keys in your views created at the step before. Just reference to it like a normal variable (Example: The value of ''theme'' within the configuration-array ''array('theme'=>'dark')'' can be accessed with ''$theme'').


* '''$config['master_components_config']['NAME_OF_YOUR_COMPONENT']['depends']:''' Set here a string or an array of strings, if your component depends other components. Otherwise set it to NULL. The strings are the names of the components your component depend on. Your component will loaded then after the components noted here and the depending components will be enabled automatically.
The file '''config.php''' should be used by the developer to modify the configuration options. The file '''setup.php''' should not be modified if possible.
* '''$config['master_components_config']['NAME_OF_YOUR_COMPONENT']['after']:''' Set here a string or an array of strings, if your component should be loaded after other components, if they are enabled. Otherwise set it to NULL. The strings are the names of the components your component should be loaded after.


Add in the file '''application/config/master.php''' two configuration variables as follows:
Sometimes the file '''setup.php''' have to know what options was set in the '''config.php'''. For example if a component depends only on jquery if an option is set to TRUE. In this case you could use the following pattern:


* '''$config['master_components']['NAME_OF_YOUR_COMPONENT']['enabled']:''' Set this to TRUE, if you want to be your component enabled by default. Otherwise set it to FALSE.
<syntaxhighlight>
* '''$config['master_components']['NAME_OF_YOUR_COMPONENT']['config']:''' Set here an assoziative array of objects if you want to be your component customizable. Otherwise set it to NULL. You can access the values of the keys in your views created at the step before. Just reference to it like a normal variable (Example: The value of ''theme'' within the configuration-array ''array('theme'=>'dark')'' can be accessed with ''$theme'').
$CI =& get_instance();
$master_config=$CI->config->item('master_components');
$config['master_components_setup']['FQN_NAME_OF_YOUR_COMPONENT']['depends'] = (
$master_config['FQN_NAME_OF_YOUR_COMPONENT']['config']['SOME_OPTION']===TRUE ? 'frameworks.jquery' : NULL
    );
</syntaxhighlight>

Aktuelle Version vom 21. Juni 2015, 13:39 Uhr

For now there is no setup logic to install new components, neither a package definition. So you have to do it manually. To add new components you have to follow the following simple steps:

Naming the Component

First of all think about a key and a namespace for your component. Namespaces can be divided into further subnamespaces. Root namespaces are at this time:

  • frameworks: Basic CSS and JS Libraries.
  • polyfills: Components for legacy browser support.
  • gui-libraries: Components displaying GUI-Widgets or animate GUI-Elements. This namespace will be further divided into logical groups like "sliders", "grids" etc.

Place Assets

Create a new subdirectory hierarchy within the folder components/assets according to your namespace hierarchy.

Into this subfolder you are free to place assets however you want. You can create subfolders or place all into the root of this folder.

Remarks/Conventions:

  • Put here only the minimum you need, and only minified versions of the library if possible.

Create Views

Create a new subdirectory hierarchy within the folder components/views according to your namespace hierarchy.

Place into this subfolder a maximum of four files including the HTML-code needed to for your component. You can use the folder components/views/_empty_template as template to copy from. The files have the following meanings and have to be named as follows:

  • head_init: HTML-Code to include into the start of the head.
  • head_finish: HTML-Code to include before the end of the head.
  • body_init: HTML-Code to include into the start of the body.
  • body_finish: HTML-Code to include before the end of the body.

You do not have to add one of these files if it has no content. Links to your assets have to be declared as follows:

<link href="components/assets/PATH_TO_COMPONENT/YOUR_OWN_SUBPATHS/YOUR_ASSET_FILENAME" rel="stylesheet">
<script src="components/assets/PATH_TO_COMPONENT/YOUR_OWN_SUBPATHS/YOUR_ASSET_FILENAME"></script>

Remarks/Conventions:

  • The links to the javascript files of the component should be placed into body_finish. This should done to display the page faster to the user. Components using javascript using javascript libraries like jQuery can only be placed there, because jQuery will be loaded at the end of the body first.

Setup Configuration

Create a new subdirectory hierarchy within the folder components/config according to your namespace hierarchy.

Place into this subfolder a file named setup.php. Add into this file two configuration variables as follows:

  • $config['master_components_setup']['FQN_NAME_OF_YOUR_COMPONENT']['depends']
    Set here a string or an array of strings, if your component depends other components. Otherwise set it to NULL. The strings are the names of the components your component depend on. Your component will loaded then after the components noted here and the depending components will be enabled automatically.
  • $config['master_components_setup']['FQN_NAME_OF_YOUR_COMPONENT']['after']
    Set here a string or an array of strings, if your component should be loaded after other components, if they are enabled. Otherwise set it to NULL. The strings are the names of the components your component should be loaded after.

Place into this subfolder a file named config.php. Add into this file one configuration variable as follows:

  • $config['master_components']['FQN_NAME_OF_YOUR_COMPONENT']['config']
    Set here an assoziative array of objects if you want to be your component customizable. Otherwise set it to NULL. You can access the values of the keys in your views created at the step before. Just reference to it like a normal variable (Example: The value of theme within the configuration-array array('theme'=>'dark') can be accessed with $theme).

The file config.php should be used by the developer to modify the configuration options. The file setup.php should not be modified if possible.

Sometimes the file setup.php have to know what options was set in the config.php. For example if a component depends only on jquery if an option is set to TRUE. In this case you could use the following pattern:

$CI =& get_instance();
$master_config=$CI->config->item('master_components');
$config['master_components_setup']['FQN_NAME_OF_YOUR_COMPONENT']['depends'] = (
	$master_config['FQN_NAME_OF_YOUR_COMPONENT']['config']['SOME_OPTION']===TRUE ? 'frameworks.jquery' : NULL
    );