Streamline readme.
This commit is contained in:
169
README.md
169
README.md
@@ -34,49 +34,8 @@ $ ./do update
|
|||||||
$ cp .env.sample .env
|
$ cp .env.sample .env
|
||||||
```
|
```
|
||||||
|
|
||||||
# Structure.
|
|
||||||
|
|
||||||
- Dependencies.
|
|
||||||
```sh
|
|
||||||
# PHP dependencies.
|
|
||||||
composer.json
|
|
||||||
# JS dependencies.
|
|
||||||
package.json
|
|
||||||
```
|
|
||||||
|
|
||||||
- /assets
|
|
||||||
CSS and JS.
|
|
||||||
|
|
||||||
- /lang
|
|
||||||
Language files.
|
|
||||||
|
|
||||||
- /lib
|
|
||||||
MailPoet classes. All classes are autoloaded, under the MailPoet namespace.
|
|
||||||
```php
|
|
||||||
// file: ./lib/models/subscriber.php
|
|
||||||
namespace \MailPoet\Models;
|
|
||||||
class Subscriber {}
|
|
||||||
```
|
|
||||||
```php
|
|
||||||
$subscriber = new \MailPoet\Models\Subscriber();
|
|
||||||
```
|
|
||||||
|
|
||||||
- /tests
|
|
||||||
Acceptance and spec tests.
|
|
||||||
|
|
||||||
- /mailpoet.php
|
|
||||||
Kickstart file.
|
|
||||||
|
|
||||||
# Tests.
|
# Tests.
|
||||||
|
|
||||||
- Before running tests, make sure you specify the following values in the .env file:
|
|
||||||
```sh
|
|
||||||
WP_TEST_URL="http://wordpress.dev"
|
|
||||||
WP_TEST_USER="admin"
|
|
||||||
WP_TEST_PASSWORD="password"
|
|
||||||
WP_TEST_PATH="/absolute/path/to/wordpress"
|
|
||||||
```
|
|
||||||
|
|
||||||
- Unit tests (using [verify](https://github.com/Codeception/Verify)):
|
- Unit tests (using [verify](https://github.com/Codeception/Verify)):
|
||||||
```sh
|
```sh
|
||||||
$ ./do test:unit
|
$ ./do test:unit
|
||||||
@@ -92,6 +51,11 @@ $ ./do test:acceptance
|
|||||||
$ ./do test:all
|
$ ./do test:all
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- Debug tests:
|
||||||
|
```sh
|
||||||
|
$ ./do test:debug
|
||||||
|
```
|
||||||
|
|
||||||
# Assets.
|
# Assets.
|
||||||
## CSS
|
## CSS
|
||||||
We are using [Stylus](https://learnboost.github.io/stylus/) (with the [Nib extension](http://tj.github.io/nib/)) as our CSS preprocessor.
|
We are using [Stylus](https://learnboost.github.io/stylus/) (with the [Nib extension](http://tj.github.io/nib/)) as our CSS preprocessor.
|
||||||
@@ -102,94 +66,30 @@ assets/css/src -> place your *.styl files here
|
|||||||
```
|
```
|
||||||
|
|
||||||
### Watch for changes and recompile
|
### Watch for changes and recompile
|
||||||
The following command will compile all specified *.styl files (in `Robofile.php`->`watch()`) into `assets/css`
|
|
||||||
```sh
|
```sh
|
||||||
$ ./do watch
|
$ ./do watch
|
||||||
```
|
```
|
||||||
|
|
||||||
### Add files to the watch command
|
|
||||||
```php
|
|
||||||
# Robofile.php
|
|
||||||
<?php
|
|
||||||
function watch() {
|
|
||||||
$files = array(
|
|
||||||
# global admin styles
|
|
||||||
'assets/css/src/admin.styl',
|
|
||||||
# rtl specific styles
|
|
||||||
'assets/css/src/rtl.styl',
|
|
||||||
# <-- add custom file (*.styl)
|
|
||||||
);
|
|
||||||
...
|
|
||||||
?>
|
|
||||||
```
|
|
||||||
## JS
|
## JS
|
||||||
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
|
Dependency example:
|
||||||
|
|
||||||
|
- add "handlebars" as a dependency in the `package.json` file
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"private": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"handlebars": "3.0.3",
|
"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
|
- Install dependencies.
|
||||||
```sh
|
```sh
|
||||||
# from the root of the project
|
$ ./do install
|
||||||
$ 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
|
|
||||||
|
|
||||||
# Views
|
- Symlink the dependency:
|
||||||
## Twig (`views/*.html`)
|
```sh
|
||||||
### Layout
|
$ ln -s ../../../node_modules/handlebars/dist/handlebars.min.js assets/js/lib/handlebars.min.js
|
||||||
```html
|
|
||||||
<!-- system notices -->
|
|
||||||
<!-- main container -->
|
|
||||||
<div class="wrap">
|
|
||||||
<!-- notices -->
|
|
||||||
<!-- title block -->
|
|
||||||
<% block title %><% endblock %>
|
|
||||||
<!-- content block -->
|
|
||||||
<% block content %><% endblock %>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- stylesheets -->
|
|
||||||
<%= stylesheet(
|
|
||||||
'admin.css'
|
|
||||||
)%>
|
|
||||||
|
|
||||||
<!-- rtl specific stylesheet -->
|
|
||||||
<% if is_rtl %>
|
|
||||||
<%= stylesheet('rtl.css') %>
|
|
||||||
<% endif %>
|
|
||||||
|
|
||||||
<!-- javascripts -->
|
|
||||||
<%= javascript(
|
|
||||||
'ajax.js',
|
|
||||||
'notice.js',
|
|
||||||
'modal.js',
|
|
||||||
'lib/handlebars.min.js',
|
|
||||||
'handlebars_helpers.js'
|
|
||||||
)%>
|
|
||||||
|
|
||||||
<!-- handlebars templates -->
|
|
||||||
<% block templates %><% endblock %>
|
|
||||||
```
|
|
||||||
### Page
|
|
||||||
```html
|
|
||||||
<% extends 'layout.html' %>
|
|
||||||
|
|
||||||
<% block title %>
|
|
||||||
<h2 class="title"><%= form.form_name %></h2>
|
|
||||||
<% endblock %>
|
|
||||||
|
|
||||||
<% block content %>
|
|
||||||
<p><%= __('Hello World!') %></p>
|
|
||||||
<% endblock %>
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Handlebars (`views/*.hbs`)
|
## Handlebars (`views/*.hbs`)
|
||||||
@@ -218,46 +118,20 @@ If you specify an `alias`, you will be able to reference it using `{{> alias }}`
|
|||||||
<% endblock %>
|
<% endblock %>
|
||||||
```
|
```
|
||||||
|
|
||||||
# Internationalization (i18n)
|
# i18n
|
||||||
## i18n in PHP
|
- Use the regular WordPress functions in PHP and Twig:
|
||||||
* use the regular WordPress functions (`__()`, `_e()`, `_n()`,...).
|
|
||||||
```php
|
```php
|
||||||
<?php
|
__()
|
||||||
echo __('my translatable string');
|
_n()
|
||||||
// or
|
|
||||||
_e('my translatable string');
|
|
||||||
|
|
||||||
// pluralize
|
|
||||||
printf(
|
|
||||||
_n('We deleted %d spam message.',
|
|
||||||
'We deleted %d spam messages.',
|
|
||||||
$count,
|
|
||||||
'my-text-domain'
|
|
||||||
),
|
|
||||||
$count
|
|
||||||
);
|
|
||||||
?>
|
|
||||||
```
|
```
|
||||||
Reference: [i18n for WordPress Developers](https://codex.wordpress.org/I18n_for_WordPress_Developers)
|
|
||||||
|
|
||||||
## i18n in Twig
|
|
||||||
* `__(string)`: returns a string
|
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<p>
|
<p>
|
||||||
<%= __('Click %shere%s!') | format('<a href="#">', '</a>') | raw %>
|
<%= __('Click %shere%s!') | format('<a href="#">', '</a>') | raw %>
|
||||||
</p>
|
</p>
|
||||||
```
|
```
|
||||||
**/!\\** Notice that we use the `raw` filter so that the HTML remains unfiltered.
|
|
||||||
|
|
||||||
Here's the output:
|
|
||||||
```html
|
|
||||||
<p>
|
|
||||||
Click <a href="#">here</a>
|
|
||||||
</p>
|
|
||||||
```
|
|
||||||
|
|
||||||
* `_n('singular', 'plural', value)`: returns a pluralized string
|
|
||||||
```html
|
```html
|
||||||
<p>
|
<p>
|
||||||
<%= _n('deleted %d message', 'deleted %d messages', count) | format(count) %>
|
<%= _n('deleted %d message', 'deleted %d messages', count) | format(count) %>
|
||||||
@@ -266,7 +140,6 @@ Here's the output:
|
|||||||
</p>
|
</p>
|
||||||
```
|
```
|
||||||
|
|
||||||
## i18n in Handlebars
|
- Handlebars.
|
||||||
In order to use i18n functions, your Handlebars template needs to be loaded from Twig (`views/*.html`).
|
|
||||||
|
|
||||||
Then you can use the Twig functions in your template.
|
You can use Twig i18n functions in Handlebars, just load your template from a Twig view.
|
||||||
|
Reference in New Issue
Block a user