From 7e80f40706db9c03fafc6fdda66529759c8f1862 Mon Sep 17 00:00:00 2001 From: marco Date: Thu, 23 Jul 2015 12:28:20 +0200 Subject: [PATCH 01/12] WP Option class to set and get options. --- lib/config/initializer.php | 9 +++++++-- lib/wp/option.php | 12 ++++++++++++ views/index.html | 5 ++++- 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 lib/wp/option.php diff --git a/lib/config/initializer.php b/lib/config/initializer.php index d7628673f2..b877adec6a 100644 --- a/lib/config/initializer.php +++ b/lib/config/initializer.php @@ -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); diff --git a/lib/wp/option.php b/lib/wp/option.php new file mode 100644 index 0000000000..82de42384b --- /dev/null +++ b/lib/wp/option.php @@ -0,0 +1,12 @@ +Autoloaded Subscriber

{{ subscriber }}

+

Test Option

+

{{ option }}

+

Notices

Trigger success

@@ -60,4 +63,4 @@ }); -{% endblock %} \ No newline at end of file +{% endblock %} From 02a8e0883a74a210d7abb1bf9f715b444a2e0562 Mon Sep 17 00:00:00 2001 From: marco Date: Thu, 23 Jul 2015 12:31:17 +0200 Subject: [PATCH 02/12] Add option prefix. --- lib/wp/option.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/wp/option.php b/lib/wp/option.php index 82de42384b..ec37a2f4cb 100644 --- a/lib/wp/option.php +++ b/lib/wp/option.php @@ -2,11 +2,16 @@ namespace MailPoet\WP; class Option { + + function __construct() { + $this->prefix = 'mailpoet'; + } + function get($name) { - return get_option($name); + return get_option($this->prefix . $name); } function set($name, $value) { - return update_option($name, $value); + return update_option($this->prefix .$name, $value); } } From ad68ed4f05dfe4ccd74382de8d56b992110ad8f3 Mon Sep 17 00:00:00 2001 From: marco Date: Thu, 23 Jul 2015 12:56:28 +0200 Subject: [PATCH 03/12] Settings class and stubbed WP class in tests. --- lib/config/settings.php | 18 ++++++++++++++++++ tests/unit/SettingsCest.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 lib/config/settings.php create mode 100644 tests/unit/SettingsCest.php diff --git a/lib/config/settings.php b/lib/config/settings.php new file mode 100644 index 0000000000..fa5ec3aa57 --- /dev/null +++ b/lib/config/settings.php @@ -0,0 +1,18 @@ +options = new WP\Option(); + } + + function load($name) { + return $this->options->get($name); + } + + function save($name, $value) { + return $this->options->set($name, $value); + } +} diff --git a/tests/unit/SettingsCest.php b/tests/unit/SettingsCest.php new file mode 100644 index 0000000000..3b3a0a482f --- /dev/null +++ b/tests/unit/SettingsCest.php @@ -0,0 +1,30 @@ + 'value', + 'set' => true + ]); + $this->settings = new Settings(); + $this->settings->options = $stub_options; + } + + public function itCanSaveSettings() { + $saved = $this->settings->save('key', 'value'); + expect($saved)->equals(true); + } + + public function itCanLoadSettings() { + $this->settings->save('key', 'value'); + $value = $this->settings->load('key'); + expect($value)->equals('value'); + } + + public function _after() { + } +} From 342cb829be93de89fccdd3f1904a1ac5d0ef42a4 Mon Sep 17 00:00:00 2001 From: marco Date: Thu, 23 Jul 2015 13:46:23 +0200 Subject: [PATCH 04/12] Added class rules. --- CONTRIBUTING.md | 28 +++++----------------------- README.md | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b2757e57f7..3865b434eb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,28 +3,10 @@ - Two spaces indentation, Ruby style. - 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 \ No newline at end of file +- 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. Therefore, views can only know about one instance variable and views should only send messages to that object ($object->collaborator->value is not allowed). diff --git a/README.md b/README.md index e57115d66e..7b70e8f03d 100644 --- a/README.md +++ b/README.md @@ -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 From 5cebe1d1f9a2bae2dacfa6f6a73d7a53b9dbb0e7 Mon Sep 17 00:00:00 2001 From: marco Date: Thu, 23 Jul 2015 13:47:34 +0200 Subject: [PATCH 05/12] Refactoring contributing guidelines. --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3865b434eb..69ad4fa7d3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,7 +1,7 @@ # Contributing ## Coding guidelines -- Two spaces indentation, Ruby style. +- Two spaces indentation. - CamelCase for classes. - camelCase for methods & variables. - Max line length at 80 chars. @@ -9,4 +9,4 @@ - 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. Therefore, views can only know about one instance variable and views should only send messages to that object ($object->collaborator->value is not allowed). +- Routes can instantiate only one object. From 95ee1902c3f0ca6fcb8a55c502aab0743252799d Mon Sep 17 00:00:00 2001 From: marco Date: Thu, 23 Jul 2015 13:51:15 +0200 Subject: [PATCH 06/12] Fix indentation on styles. --- assets/css/src/notice.styl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/assets/css/src/notice.styl b/assets/css/src/notice.styl index 0da9eef1fb..1b8116621b 100644 --- a/assets/css/src/notice.styl +++ b/assets/css/src/notice.styl @@ -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 \ No newline at end of file + text-decoration: none From a14134eb352de60736f445db5fbd514b8bb4cbd8 Mon Sep 17 00:00:00 2001 From: marco Date: Thu, 23 Jul 2015 13:52:24 +0200 Subject: [PATCH 07/12] Fix indentation of JS files. --- assets/js/admin.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/assets/js/admin.js b/assets/js/admin.js index ac327ea796..dbf97720a3 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -1,6 +1,6 @@ jQuery(function($) { - // dom ready - $(function() { + // dom ready + $(function() { - }); -}); \ No newline at end of file + }); +}); From 93cb71468d4da5e27b46806213abc8ee9552dd16 Mon Sep 17 00:00:00 2001 From: marco Date: Thu, 23 Jul 2015 13:53:31 +0200 Subject: [PATCH 08/12] Fix camelCase for methods. --- tests/unit/DKIMCest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/DKIMCest.php b/tests/unit/DKIMCest.php index 0e11a96a00..d8c43cafc3 100644 --- a/tests/unit/DKIMCest.php +++ b/tests/unit/DKIMCest.php @@ -2,7 +2,7 @@ class DKIMCest { - 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-----'; From d92eb2b6e10e71f0e7bfe8a2822a940c87c8469c Mon Sep 17 00:00:00 2001 From: marco Date: Thu, 23 Jul 2015 13:54:06 +0200 Subject: [PATCH 09/12] Fix camelCase. --- tests/unit/SubscriberCest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/SubscriberCest.php b/tests/unit/SubscriberCest.php index 854c205eaa..69450260b0 100644 --- a/tests/unit/SubscriberCest.php +++ b/tests/unit/SubscriberCest.php @@ -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'); } From 1e7ae9d55d1a0da80375790bcb18b3be4110c82c Mon Sep 17 00:00:00 2001 From: marco Date: Thu, 23 Jul 2015 13:54:22 +0200 Subject: [PATCH 10/12] Fix camelCase. --- tests/unit/XlsxWriterCest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/XlsxWriterCest.php b/tests/unit/XlsxWriterCest.php index 7531bc1460..02416e02cf 100644 --- a/tests/unit/XlsxWriterCest.php +++ b/tests/unit/XlsxWriterCest.php @@ -6,7 +6,7 @@ class XlsxWriterCest { public function _before() { } - public function it_can_be_created() { + public function itCanBeCreated() { $writer = new \MailPoet\Util\XLSXWriter(); } From 98cfbf02b2e1514b9d6efe80565562105f76992f Mon Sep 17 00:00:00 2001 From: marco Date: Thu, 23 Jul 2015 13:55:49 +0200 Subject: [PATCH 11/12] Fix camelCase. --- tests/acceptance/ActivationCest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/acceptance/ActivationCest.php b/tests/acceptance/ActivationCest.php index cfa2f2fddb..77af61ea19 100644 --- a/tests/acceptance/ActivationCest.php +++ b/tests/acceptance/ActivationCest.php @@ -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'); From 100e785705969b043f6adf49efe146812232db4c Mon Sep 17 00:00:00 2001 From: marco Date: Thu, 23 Jul 2015 13:56:45 +0200 Subject: [PATCH 12/12] Fix camelCase. --- tests/acceptance/HomePageCest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/acceptance/HomePageCest.php b/tests/acceptance/HomePageCest.php index 4221a716c5..a548e52018 100644 --- a/tests/acceptance/HomePageCest.php +++ b/tests/acceptance/HomePageCest.php @@ -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'); }