diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b2757e57f7..69ad4fa7d3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 \ 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. 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 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 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 + }); +}); 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/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/lib/wp/option.php b/lib/wp/option.php new file mode 100644 index 0000000000..ec37a2f4cb --- /dev/null +++ b/lib/wp/option.php @@ -0,0 +1,17 @@ +prefix = 'mailpoet'; + } + + function get($name) { + return get_option($this->prefix . $name); + } + + function set($name, $value) { + return update_option($this->prefix .$name, $value); + } +} 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'); 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'); } diff --git a/tests/unit/SettingsCest.php b/tests/unit/SettingsCest.php index e54c15cc6b..3b3a0a482f 100644 --- a/tests/unit/SettingsCest.php +++ b/tests/unit/SettingsCest.php @@ -1,52 +1,30 @@ 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; -} \ No newline at end of file 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'); } diff --git a/tests/unit/UtilDKIMCest.php b/tests/unit/UtilDKIMCest.php index 1efff11adf..248e4f8917 100644 --- a/tests/unit/UtilDKIMCest.php +++ b/tests/unit/UtilDKIMCest.php @@ -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-----'; 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(); } diff --git a/views/index.html b/views/index.html index e974d5b030..fa606d9cc4 100644 --- a/views/index.html +++ b/views/index.html @@ -28,6 +28,9 @@

Autoloaded Subscriber

{{ subscriber }}

+

Test Option

+

{{ option }}

+

Notices

Trigger success

@@ -60,4 +63,4 @@ }); -{% endblock %} \ No newline at end of file +{% endblock %}