Merge branch 'master' of github.com:JoN1oP/namp2
This commit is contained in:
@@ -1,30 +1,12 @@
|
|||||||
# Contributing
|
# Contributing
|
||||||
## Coding guidelines
|
## Coding guidelines
|
||||||
|
|
||||||
- Two spaces indentation, Ruby style.
|
- Two spaces indentation.
|
||||||
- CamelCase for classes.
|
- CamelCase for classes.
|
||||||
- snake_case for methods & variables.
|
- camelCase for methods & variables.
|
||||||
- Max line length at 80 chars.
|
- Max line length at 80 chars.
|
||||||
- Composition over Inheritance.
|
- Composition over Inheritance.
|
||||||
- ...
|
- Classes can be no longer than 100 LOC.
|
||||||
|
- Methods can be no longer than 5 LOC.
|
||||||
## Adding a JS dependency
|
- Pass no more than 4 parameters/hash keys into a method.
|
||||||
In order to use a JS library (let's take Handlebars as an example), you need to follow these steps:
|
- Routes can instantiate only one object.
|
||||||
|
|
||||||
* add "handlebars" as a dependency in the `package.json` file
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"private": true,
|
|
||||||
"dependencies": {
|
|
||||||
"handlebars": "3.0.3",
|
|
||||||
},
|
|
||||||
```
|
|
||||||
* run `./do install` (the handlebars module will be added into the node_modules folder)
|
|
||||||
* create a symlink to the file you want to use by running this command
|
|
||||||
```sh
|
|
||||||
# from the root of the project
|
|
||||||
$ cd assets/js/lib/
|
|
||||||
# /!\ use relative path to the node_modules folder
|
|
||||||
$ ln -nsf ../../../node_modules/handlebars/dist/handlebars.min.js handlebars.min.js
|
|
||||||
```
|
|
||||||
* make sure to push the symlink onto the repository
|
|
||||||
|
22
README.md
22
README.md
@@ -89,3 +89,25 @@ $ ./do test:all
|
|||||||
```sh
|
```sh
|
||||||
$ ./do watch
|
$ ./do watch
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# JS Dependencies.
|
||||||
|
|
||||||
|
In order to use a JS library (let's take Handlebars as an example), you need to follow these steps:
|
||||||
|
|
||||||
|
* add "handlebars" as a dependency in the `package.json` file
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"handlebars": "3.0.3",
|
||||||
|
},
|
||||||
|
```
|
||||||
|
* run `./do install` (the handlebars module will be added into the node_modules folder)
|
||||||
|
* create a symlink to the file you want to use by running this command
|
||||||
|
```sh
|
||||||
|
# from the root of the project
|
||||||
|
$ cd assets/js/lib/
|
||||||
|
# /!\ use relative path to the node_modules folder
|
||||||
|
$ ln -nsf ../../../node_modules/handlebars/dist/handlebars.min.js handlebars.min.js
|
||||||
|
```
|
||||||
|
* make sure to push the symlink onto the repository
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
.mailpoet_notice
|
.mailpoet_notice
|
||||||
position: relative
|
position: relative
|
||||||
|
|
||||||
.mailpoet_notice_close
|
.mailpoet_notice_close
|
||||||
position: absolute
|
position: absolute
|
||||||
right: 0.5em
|
right: 0.5em
|
||||||
top: 0.5em
|
top: 0.5em
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
jQuery(function($) {
|
jQuery(function($) {
|
||||||
// dom ready
|
// dom ready
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
@@ -2,6 +2,7 @@
|
|||||||
namespace MailPoet\Config;
|
namespace MailPoet\Config;
|
||||||
use MailPoet\Models;
|
use MailPoet\Models;
|
||||||
use MailPoet\Renderer;
|
use MailPoet\Renderer;
|
||||||
|
use MailPoet\WP;
|
||||||
|
|
||||||
if (!defined('ABSPATH')) exit;
|
if (!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
@@ -174,8 +175,11 @@ class Initializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function admin_page() {
|
public function admin_page() {
|
||||||
// set data
|
|
||||||
$subscriber = new Models\Subscriber();
|
$subscriber = new Models\Subscriber();
|
||||||
|
|
||||||
|
$option = new WP\Option();
|
||||||
|
$option->set('option_name', 'option value');
|
||||||
|
|
||||||
$this->data = array(
|
$this->data = array(
|
||||||
'title' => __('Twig Sample page'),
|
'title' => __('Twig Sample page'),
|
||||||
'text' => 'Lorem ipsum dolor sit amet',
|
'text' => 'Lorem ipsum dolor sit amet',
|
||||||
@@ -184,7 +188,8 @@ class Initializer {
|
|||||||
array('name' => 'Joo', 'email' => 'jonathan@mailpoet.com'),
|
array('name' => 'Joo', 'email' => 'jonathan@mailpoet.com'),
|
||||||
array('name' => 'Marco', 'email' => 'marco@mailpoet.com'),
|
array('name' => 'Marco', 'email' => 'marco@mailpoet.com'),
|
||||||
),
|
),
|
||||||
'subscriber' => $subscriber->name
|
'subscriber' => $subscriber->name,
|
||||||
|
'option' => $option->get('option_name')
|
||||||
);
|
);
|
||||||
// Sample page using Twig
|
// Sample page using Twig
|
||||||
echo $this->renderer->render('index.html', $this->data);
|
echo $this->renderer->render('index.html', $this->data);
|
||||||
|
18
lib/config/settings.php
Normal file
18
lib/config/settings.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
namespace MailPoet\Config;
|
||||||
|
use \MailPoet\WP;
|
||||||
|
|
||||||
|
class Settings {
|
||||||
|
|
||||||
|
function __construct() {
|
||||||
|
$this->options = new WP\Option();
|
||||||
|
}
|
||||||
|
|
||||||
|
function load($name) {
|
||||||
|
return $this->options->get($name);
|
||||||
|
}
|
||||||
|
|
||||||
|
function save($name, $value) {
|
||||||
|
return $this->options->set($name, $value);
|
||||||
|
}
|
||||||
|
}
|
17
lib/wp/option.php
Normal file
17
lib/wp/option.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
namespace MailPoet\WP;
|
||||||
|
|
||||||
|
class Option {
|
||||||
|
|
||||||
|
function __construct() {
|
||||||
|
$this->prefix = 'mailpoet';
|
||||||
|
}
|
||||||
|
|
||||||
|
function get($name) {
|
||||||
|
return get_option($this->prefix . $name);
|
||||||
|
}
|
||||||
|
|
||||||
|
function set($name, $value) {
|
||||||
|
return update_option($this->prefix .$name, $value);
|
||||||
|
}
|
||||||
|
}
|
@@ -10,7 +10,7 @@ class ActivationCest {
|
|||||||
$I->click('Log In');
|
$I->click('Log In');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function i_can_activate(AcceptanceTester $I) {
|
public function IcanActivate(AcceptanceTester $I) {
|
||||||
$I->amOnPage('/wp-admin/plugins.php');
|
$I->amOnPage('/wp-admin/plugins.php');
|
||||||
$I->see('MailPoet');
|
$I->see('MailPoet');
|
||||||
$I->click('#mailpoet .deactivate a');
|
$I->click('#mailpoet .deactivate a');
|
||||||
|
@@ -6,7 +6,7 @@ class HomePageCest {
|
|||||||
public function _before(AcceptanceTester $I) {
|
public function _before(AcceptanceTester $I) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function it_has_a_title(AcceptanceTester $I) {
|
public function IcanSeeATitle(AcceptanceTester $I) {
|
||||||
$I->amOnPage('/');
|
$I->amOnPage('/');
|
||||||
$I->see('Hello');
|
$I->see('Hello');
|
||||||
}
|
}
|
||||||
|
@@ -1,52 +1,30 @@
|
|||||||
<?php
|
<?php
|
||||||
|
use \UnitTester;
|
||||||
|
use \Codeception\Util\Stub;
|
||||||
|
use \MailPoet\Config\Settings;
|
||||||
|
|
||||||
class SettingsCest
|
class SettingsCest {
|
||||||
{
|
|
||||||
public function _before() {
|
|
||||||
$this->settings = \MailPoet\Settings::getAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function it_has_defaults() {
|
public function _before() {
|
||||||
$settings = \MailPoet\Settings::getDefaults();
|
$stub_options = Stub::make('\MailPoet\WP\Option', [
|
||||||
expect($this->settings)->notEmpty();
|
'get' => 'value',
|
||||||
}
|
'set' => true
|
||||||
|
]);
|
||||||
|
$this->settings = new Settings();
|
||||||
|
$this->settings->options = $stub_options;
|
||||||
|
}
|
||||||
|
|
||||||
public function it_should_load_default_settings(UnitTester $I) {
|
public function itCanSaveSettings() {
|
||||||
$settings = \MailPoet\Settings::getAll();
|
$saved = $this->settings->save('key', 'value');
|
||||||
$defaults = \MailPoet\Settings::getDefaults();
|
expect($saved)->equals(true);
|
||||||
expect($settings)->equals($defaults);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public function it_should_update_settings() {
|
public function itCanLoadSettings() {
|
||||||
$new_settings = array('test_key' => true);
|
$this->settings->save('key', 'value');
|
||||||
\MailPoet\Settings::save($new_settings);
|
$value = $this->settings->load('key');
|
||||||
|
expect($value)->equals('value');
|
||||||
|
}
|
||||||
|
|
||||||
$settings = \MailPoet\Settings::getAll();
|
public function _after() {
|
||||||
|
}
|
||||||
expect_that(isset($settings['test_key']) && $settings['test_key'] === true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function it_should_reset_settings() {
|
|
||||||
$settings = \MailPoet\Settings::getAll();
|
|
||||||
|
|
||||||
\MailPoet\Settings::clearAll();
|
|
||||||
|
|
||||||
$reset_settings = \MailPoet\Settings::getAll();
|
|
||||||
|
|
||||||
expect($settings)->notEmpty();
|
|
||||||
expect($reset_settings)->equals(\MailPoet\Settings::getDefaults());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_option($value, $default) {
|
|
||||||
return $default;
|
|
||||||
}
|
|
||||||
function add_option() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
function update_option() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
function delete_option() {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
@@ -8,7 +8,7 @@ class SubscriberCest {
|
|||||||
$this->subscriber = new Subscriber();
|
$this->subscriber = new Subscriber();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function it_can_be_created() {
|
public function itCanBeCreated() {
|
||||||
expect($this->subscriber->name)->equals('Name');
|
expect($this->subscriber->name)->equals('Name');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
class UtilDKIMCest {
|
class UtilDKIMCest {
|
||||||
|
|
||||||
public function it_can_generate_keys() {
|
public function itCanGenerateKeys() {
|
||||||
$keys = \MailPoet\Util\DKIM::generateKeys();
|
$keys = \MailPoet\Util\DKIM::generateKeys();
|
||||||
$public_header = '-----BEGIN PUBLIC KEY-----';
|
$public_header = '-----BEGIN PUBLIC KEY-----';
|
||||||
$private_header = '-----BEGIN RSA PRIVATE KEY-----';
|
$private_header = '-----BEGIN RSA PRIVATE KEY-----';
|
||||||
|
@@ -6,7 +6,7 @@ class XlsxWriterCest {
|
|||||||
public function _before() {
|
public function _before() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function it_can_be_created() {
|
public function itCanBeCreated() {
|
||||||
$writer = new \MailPoet\Util\XLSXWriter();
|
$writer = new \MailPoet\Util\XLSXWriter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -28,6 +28,9 @@
|
|||||||
<h3>Autoloaded Subscriber</h3>
|
<h3>Autoloaded Subscriber</h3>
|
||||||
<p>{{ subscriber }}</p>
|
<p>{{ subscriber }}</p>
|
||||||
|
|
||||||
|
<h3>Test Option</h3>
|
||||||
|
<p>{{ option }}</p>
|
||||||
|
|
||||||
<!-- Notice -->
|
<!-- Notice -->
|
||||||
<h3>Notices</h3>
|
<h3>Notices</h3>
|
||||||
<p><a href="javascript:;" onclick="MailPoet.Notice.success('Test');">Trigger success</a></p>
|
<p><a href="javascript:;" onclick="MailPoet.Notice.success('Test');">Trigger success</a></p>
|
||||||
|
Reference in New Issue
Block a user