Merge branch 'master' of github.com:JoN1oP/namp2

This commit is contained in:
Jonathan Labreuille
2015-07-24 11:53:28 +02:00
14 changed files with 109 additions and 84 deletions

View File

@@ -1,30 +1,12 @@
# Contributing
## Coding guidelines
- Two spaces indentation, Ruby style.
- Two spaces indentation.
- CamelCase for classes.
- snake_case for methods & variables.
- camelCase for methods & variables.
- Max line length at 80 chars.
- Composition over Inheritance.
- ...
## Adding a JS dependency
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
- Classes can be no longer than 100 LOC.
- Methods can be no longer than 5 LOC.
- Pass no more than 4 parameters/hash keys into a method.
- Routes can instantiate only one object.

View File

@@ -89,3 +89,25 @@ $ ./do test:all
```sh
$ ./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

View File

@@ -1,9 +1,9 @@
.mailpoet_notice
position: relative
position: relative
.mailpoet_notice_close
.mailpoet_notice_close
position: absolute
right: 0.5em
top: 0.5em
color: #999
text-decoration: none
text-decoration: none

View File

@@ -1,6 +1,6 @@
jQuery(function($) {
// dom ready
$(function() {
// dom ready
$(function() {
});
});
});
});

View File

@@ -2,6 +2,7 @@
namespace MailPoet\Config;
use MailPoet\Models;
use MailPoet\Renderer;
use MailPoet\WP;
if (!defined('ABSPATH')) exit;
@@ -174,8 +175,11 @@ class Initializer {
}
public function admin_page() {
// set data
$subscriber = new Models\Subscriber();
$option = new WP\Option();
$option->set('option_name', 'option value');
$this->data = array(
'title' => __('Twig Sample page'),
'text' => 'Lorem ipsum dolor sit amet',
@@ -184,7 +188,8 @@ class Initializer {
array('name' => 'Joo', 'email' => 'jonathan@mailpoet.com'),
array('name' => 'Marco', 'email' => 'marco@mailpoet.com'),
),
'subscriber' => $subscriber->name
'subscriber' => $subscriber->name,
'option' => $option->get('option_name')
);
// Sample page using Twig
echo $this->renderer->render('index.html', $this->data);

18
lib/config/settings.php Normal file
View 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
View 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);
}
}

View File

@@ -10,7 +10,7 @@ class ActivationCest {
$I->click('Log In');
}
public function i_can_activate(AcceptanceTester $I) {
public function IcanActivate(AcceptanceTester $I) {
$I->amOnPage('/wp-admin/plugins.php');
$I->see('MailPoet');
$I->click('#mailpoet .deactivate a');

View File

@@ -6,7 +6,7 @@ class HomePageCest {
public function _before(AcceptanceTester $I) {
}
public function it_has_a_title(AcceptanceTester $I) {
public function IcanSeeATitle(AcceptanceTester $I) {
$I->amOnPage('/');
$I->see('Hello');
}

View File

@@ -1,52 +1,30 @@
<?php
use \UnitTester;
use \Codeception\Util\Stub;
use \MailPoet\Config\Settings;
class SettingsCest
{
public function _before() {
$this->settings = \MailPoet\Settings::getAll();
}
class SettingsCest {
public function it_has_defaults() {
$settings = \MailPoet\Settings::getDefaults();
expect($this->settings)->notEmpty();
}
public function _before() {
$stub_options = Stub::make('\MailPoet\WP\Option', [
'get' => 'value',
'set' => true
]);
$this->settings = new Settings();
$this->settings->options = $stub_options;
}
public function it_should_load_default_settings(UnitTester $I) {
$settings = \MailPoet\Settings::getAll();
$defaults = \MailPoet\Settings::getDefaults();
expect($settings)->equals($defaults);
}
public function itCanSaveSettings() {
$saved = $this->settings->save('key', 'value');
expect($saved)->equals(true);
}
public function it_should_update_settings() {
$new_settings = array('test_key' => true);
\MailPoet\Settings::save($new_settings);
public function itCanLoadSettings() {
$this->settings->save('key', 'value');
$value = $this->settings->load('key');
expect($value)->equals('value');
}
$settings = \MailPoet\Settings::getAll();
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());
}
public function _after() {
}
}
function get_option($value, $default) {
return $default;
}
function add_option() {
return true;
}
function update_option() {
return true;
}
function delete_option() {
return true;
}

View File

@@ -8,7 +8,7 @@ class SubscriberCest {
$this->subscriber = new Subscriber();
}
public function it_can_be_created() {
public function itCanBeCreated() {
expect($this->subscriber->name)->equals('Name');
}

View File

@@ -2,7 +2,7 @@
class UtilDKIMCest {
public function it_can_generate_keys() {
public function itCanGenerateKeys() {
$keys = \MailPoet\Util\DKIM::generateKeys();
$public_header = '-----BEGIN PUBLIC KEY-----';
$private_header = '-----BEGIN RSA PRIVATE KEY-----';

View File

@@ -6,7 +6,7 @@ class XlsxWriterCest {
public function _before() {
}
public function it_can_be_created() {
public function itCanBeCreated() {
$writer = new \MailPoet\Util\XLSXWriter();
}

View File

@@ -28,6 +28,9 @@
<h3>Autoloaded Subscriber</h3>
<p>{{ subscriber }}</p>
<h3>Test Option</h3>
<p>{{ option }}</p>
<!-- Notice -->
<h3>Notices</h3>
<p><a href="javascript:;" onclick="MailPoet.Notice.success('Test');">Trigger success</a></p>
@@ -60,4 +63,4 @@
});
</script>
{% endblock %}
{% endblock %}