2017 © Pedro Peláez
 

wordpress-plugin components

Component manager

image

digitalunited/components

Component manager

  • Thursday, October 26, 2017
  • by digitalunited
  • Repository
  • 1 Watchers
  • 5 Stars
  • 7,025 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 40 Versions
  • 4 % Grown

The README.md

Components

Installation

  1. Install via composer
  2. Activate plugin
  3. Configure grunt

Usage

A component folder should be placed in the theme-directory following this structure:, (*1)

└── components
    ├── SomeComponent
    │   ├── assets
    |   |   └── some-jpgs-or-whatever.jpg
    │   ├── component.php
    │   ├── one-or-more-less-files.less
    │   ├── one-or-more-coffee-files.coffee
    │   ├── view.php
    │   └── _somePartialView.view.php
    └── SomeOtherComponent
        ├── component.php
        ├── one-or-more-less-files.less
        ├── one-or-more-coffee-files.coffee
        └── view.php

Every component will have their short-code registered and vc_mapping set up., (*2)

component.php

A VCComponent have the following structure:, (*3)

namespace Component;

class Text extends \DigitalUnited\Components\VcComponent
{
    // This is a VC-mapping array
    // https://wpbakery.atlassian.net/wiki/pages/viewpage.action?pageId=524332

    protected function getComponentConfig()
    {
        return [
            'name' => __('Text', 'components'),
            'description' => __('Standard textmodul', 'components'),
            'params' => [
                [
                    "type" => "textfield",
                    "holder" => "div",
                    "class" => "",
                    "heading" => __( "Headline", "components" ),
                    "param_name" => "headline",
                    "value" => "",
                    "description" => ""
                ],
                [
                    "type" => "textarea_html",
                    "holder" => "div",
                    "class" => "",
                    "heading" => __( "Content", "components" ),
                    "param_name" => "content",
                    "value" => "",
                    "description" => ""
                ],
            ]
        ];
    }

    // If you want to you can have diferent views for deferent cases.
    // If you do you can override the following method.
    //
    // If view is not specified they will be rendered in the following
    // order: [view].view.php, view.php
    //
    // default is __DIR__.'/view.php'
    protected function getViewFileName() {
        return parent::getViewFileName();
    }

    // Before the parameters of the components is sent to rendering
    // you may modify their values here
    protected function sanetizeDataForRendering($data)
    {
        return $data;
    }

    // If you want to change what kind of element is rendered
    // You could override this method
    protected function getWrapperElementType()
    {
        return 'div';
    }

    // Add classes to the wrapping element. Should be an array
    // If a param named view exists it will be added automaticly
    protected function getExtraWrapperClasses()
    {
        return $this->param('headline') ? ['has-headline'] : ['no-headline'];
    }

    // Add attribute to the wrapper. if 'class' is specified it will be merged in
    // with classes from getExtraWrapperClasses
    protected function getWrapperAttributes()
    {
        return ['href' => 'myhref foobar', 'role' => 'button'];
    }

    // May be used to implement logic such as post-type registering or whatever
    public function main()
    {
    }
}
?>

A Standard component have the following structure:, (*4)

namespace Component;

class Sidebar extends \DigitalUnited\Components\Component
{
    // Return key value pair with the accepted parameters for this
    // view file
    protected function getDefaultParams() {
        return [
            'param1' => 'default value1',
            'param2' => '',
            'view' => 'default',
        ];
    }

    //Same as a VcComponent
    protected function getViewFileName() { ... }
    protected function sanetizeDataForRendering($data) { ... }
    public function main() { ... }
}
?>

View

In the views, all values returned from "sanetizeDataForRendering" will be accessible., (*5)

eg. ['foo' => 'bar'] will be available like, (*6)

<?= $foo // outputs 'bar' ?>

You may also use the component class, referenced as $component. eg:, (*7)

<?= $component->myFancyPublicFunction() ?>

You may use separate view files depending on the $view-param, if "view" param is specified, $view.view.php will be rendered. Default: view.php, (*8)

It is possible to split a view file into partials:, (*9)

<?= $component->renderPartial('_listItem') // renders _listItem.view.php ?>

Performance

When a slow registration of a component is detected the plugin will show an admin notice. Slow registration could be caused by by 2 reasons: - Dynamic population of params - Execution of tasks in the components main method., (*10)

If the problem is due to Dynamic population of params there is an easy solution. Just add the following code as an early abort in the function that generates the dynamic params:, (*11)

if (!$this->shouldGenerateParams()) {
    return [];
}

It the code above doesn't help the problem probably is that code is executed in the components main function., (*12)

Less and coffe, assets

Could be handled with with Grunt/gulp or whatever. See https://github.com/digitalunited/roots for example, (*13)

The Versions

26/10 2017

dev-master

9999999-dev https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

26/10 2017

v0.2.2

0.2.2.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

26/09 2017

v0.2.1

0.2.1.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

22/09 2017

0.2.0

0.2.0.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

02/06 2017

0.1.28

0.1.28.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

16/03 2017

0.1.27

0.1.27.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

20/10 2016

0.1.26

0.1.26.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

28/09 2016

0.1.25

0.1.25.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

02/05 2016

0.1.24

0.1.24.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

27/04 2016

0.1.23

0.1.23.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

27/04 2016

0.1.22

0.1.22.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

25/01 2016

0.1.21

0.1.21.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

20/01 2016

0.1.20

0.1.20.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

17/12 2015

0.1.19

0.1.19.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

15/12 2015

0.1.18

0.1.18.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

26/10 2015

0.1.17

0.1.17.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

30/09 2015

0.1.16

0.1.16.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

21/05 2015

0.1.15

0.1.15.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

07/05 2015

0.1.14

0.1.14.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

21/04 2015

0.1.13

0.1.13.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

13/04 2015

0.1.12

0.1.12.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

08/04 2015

0.1.11

0.1.11.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

17/02 2015

0.1.10

0.1.10.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

17/02 2015

0.1.9

0.1.9.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

16/02 2015

0.1.8

0.1.8.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

15/02 2015

0.1.7

0.1.7.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

15/02 2015

0.1.6

0.1.6.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

11/02 2015

0.1.5

0.1.5.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

11/02 2015

0.1.4

0.1.4.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

11/02 2015

0.1.3

0.1.3.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

11/02 2015

0.1.2

0.1.2.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

11/02 2015

0.1.1

0.1.1.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

11/02 2015

0.1.0

0.1.0.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

10/02 2015

0.0.7

0.0.7.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

10/02 2015

0.0.6

0.0.6.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

10/02 2015

0.0.5

0.0.5.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

04/02 2015

0.0.4

0.0.4.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

04/02 2015

0.0.3

0.0.3.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

03/02 2015

0.0.2

0.0.2.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress

03/02 2015

0.0.1

0.0.1.0 https://github.com/digitalunited/components

Component manager

  Sources   Download

MIT

The Requires

 

plugin wordpress