fixed symlinks of select2 and added missing images + added i18n functions to twig templates (with auto text domain addition) + added rtl stylesheet (updated robofile to watch it separately from admin.styl so it can be included only if necessary

This commit is contained in:
Jonathan Labreuille
2015-07-30 21:25:39 +02:00
parent f9a2d0026c
commit 1ddd74e991
20 changed files with 239 additions and 129 deletions

View File

@ -16,7 +16,11 @@ class RoboFile extends \Robo\Tasks {
function watch() {
$command = array(
'./node_modules/stylus/bin/stylus -u',
'nib -w assets/css/src/admin.styl',
' nib -w'.
// global admin styles
' assets/css/src/admin.styl'.
// rtl specific styles
' assets/css/src/rtl.styl',
'-o assets/css/'
);
$this->_exec(join(' ', $command));

View File

@ -1 +0,0 @@
../../../node_modules/select2/select2.css

View File

@ -0,0 +1 @@
../../../../node_modules/select2/select2-spinner.gif

1
assets/css/lib/select2/select2.css vendored Symbolic link
View File

@ -0,0 +1 @@
../../../../node_modules/select2/select2.css

View File

@ -0,0 +1 @@
../../../../node_modules/select2/select2.png

View File

@ -0,0 +1 @@
../../../../node_modules/select2/select2x2.png

0
assets/css/rtl.css Normal file
View File

1
assets/css/src/rtl.styl Normal file
View File

@ -0,0 +1 @@
// place RTL specific code here

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
../../../node_modules/select2

1
assets/js/lib/select2.js Symbolic link
View File

@ -0,0 +1 @@
../../../node_modules/select2/select2.js

Binary file not shown.

View File

@ -4,11 +4,11 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: http://support.mailpoet.com/\n"
"POT-Creation-Date: 2015-07-29 16:59:53+00:00\n"
"POT-Creation-Date: 2015-07-30 14:08:29+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"PO-Revision-Date: 2015-07-29 19:01+0100\n"
"PO-Revision-Date: 2015-07-30 16:19+0100\n"
"Last-Translator: MailPoet i18n (https://www.transifex.com/organization/wysija)\n"
"Language-Team: MailPoet i18n <https://www.transifex.com/organization/wysija>\n"
"X-Generator: Poedit 1.7.4\n"
@ -20,6 +20,26 @@ msgstr ""
"Language: fr\n"
"X-Poedit-SearchPath-0: .\n"
#: lib/config/initializer.php:259
msgid "New form"
msgstr ""
#: lib/config/initializer.php:264
msgid "Check your inbox or spam folder now to confirm your subscription."
msgstr ""
#: lib/config/initializer.php:270 lib/config/initializer.php:275
msgid "Email"
msgstr ""
#: lib/config/initializer.php:280
msgid "Submit"
msgstr ""
#: lib/config/initializer.php:285
msgid "Subscribe!"
msgstr ""
#: lib/form/renderer.php:91
msgid "Year, month, day"
msgstr ""
@ -116,84 +136,80 @@ msgstr ""
msgid "Newsletter"
msgstr ""
#: views/form/editor.html:4 views/form/editor.html:26
#: views/form/editor.html:8
msgid "Edit name' "
msgstr ""
#: views/form/editor.html:23
msgid "Save"
msgstr ""
msgstr "Sauvegarder"
#: views/form/editor.html:5
msgid "Translatable string with a link %shere%s"
msgstr ""
#: views/form/editor.html:6
msgid "deleted one message"
msgid_plural "deleted %d messages"
msgstr[0] "supprimé un message"
msgstr[1] "supprimé %d messages"
#: views/form/editor.html:34
#: views/form/editor.html:31
msgid "Settings"
msgstr ""
msgstr "Réglages"
#: views/form/editor.html:42
#: views/form/editor.html:39
msgid "This form adds subscribers to these lists:"
msgstr ""
#: views/form/editor.html:44
#: views/form/editor.html:41
msgid "Choose a list"
msgstr ""
#: views/form/editor.html:57
#: views/form/editor.html:46
msgid "You have to select at least 1 list"
msgstr ""
#: views/form/editor.html:63
#: views/form/editor.html:52
msgid "After submit..."
msgstr ""
msgstr "Après l'inscription"
#: views/form/editor.html:54
msgid "Show message"
msgstr "Afficher le message"
#: views/form/editor.html:58
msgid "Go to page"
msgstr "Aller à la page"
#: views/form/editor.html:65
msgid "Show message"
msgstr ""
#: views/form/editor.html:69
msgid "Go to page"
msgstr ""
#: views/form/editor.html:76
msgid "Check your inbox now to confirm your subscription."
msgstr ""
#: views/form/editor.html:98
#: views/form/editor.html:85
msgid "Shortcodes"
msgstr ""
#: views/form/editor.html:103
msgid "You can easily add this form to your theme's in the"
#: views/form/editor.html:90
msgid "You can easily add this form to your theme's in the %sWidgets area%s"
msgstr ""
#: views/form/editor.html:103
msgid "Widgets areas"
#: views/form/editor.html:96
msgid "%sHTML%s"
msgstr ""
#: views/form/editor.html:126
msgid "[link_html]HTML[/link_html]"
msgstr ""
#: views/form/editor.html:138
#: views/form/editor.html:119
msgid "Fields"
msgstr ""
#: views/form/editor.html:144
#: views/form/editor.html:125
msgid "Add New Field"
msgstr ""
#: views/form/editor.html:153
#: views/form/editor.html:134
msgid "Styles"
msgstr ""
#: views/form/editor.html:157
#: views/form/editor.html:138
msgid "Preview"
msgstr ""
#: views/index.html:4
msgid "monvier"
#: views/index.html:5
msgid "Translatable string with a link %shere%s"
msgstr ""
#: views/index.html:6 views/index.html:7
msgid "deleted one message"
msgid_plural "deleted %d messages"
msgstr[0] ""
msgstr[1] ""

View File

@ -4,7 +4,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: http://support.mailpoet.com/\n"
"POT-Creation-Date: 2015-07-29 17:10:53+00:00\n"
"POT-Creation-Date: 2015-07-30 14:08:29+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
@ -26,6 +26,26 @@ msgstr ""
"X-Poedit-Bookmarks: \n"
"X-Textdomain-Support: yes\n"
#: lib/config/initializer.php:259
msgid "New form"
msgstr ""
#: lib/config/initializer.php:264
msgid "Check your inbox or spam folder now to confirm your subscription."
msgstr ""
#: lib/config/initializer.php:270 lib/config/initializer.php:275
msgid "Email"
msgstr ""
#: lib/config/initializer.php:280
msgid "Submit"
msgstr ""
#: lib/config/initializer.php:285
msgid "Subscribe!"
msgstr ""
#: lib/form/renderer.php:91
msgid "Year, month, day"
msgstr ""
@ -122,6 +142,10 @@ msgstr ""
msgid "Newsletter"
msgstr ""
#: views/form/editor.html:8
msgid "Edit name' "
msgstr ""
#: views/form/editor.html:23
msgid "Save"
msgstr ""
@ -138,55 +162,51 @@ msgstr ""
msgid "Choose a list"
msgstr ""
#: views/form/editor.html:54
#: views/form/editor.html:46
msgid "You have to select at least 1 list"
msgstr ""
#: views/form/editor.html:60
#: views/form/editor.html:52
msgid "After submit..."
msgstr ""
#: views/form/editor.html:62
#: views/form/editor.html:54
msgid "Show message"
msgstr ""
#: views/form/editor.html:66
#: views/form/editor.html:58
msgid "Go to page"
msgstr ""
#: views/form/editor.html:73
#: views/form/editor.html:65
msgid "Check your inbox now to confirm your subscription."
msgstr ""
#: views/form/editor.html:95
#: views/form/editor.html:85
msgid "Shortcodes"
msgstr ""
#: views/form/editor.html:100
msgid "You can easily add this form to your theme's in the"
#: views/form/editor.html:90
msgid "You can easily add this form to your theme's in the %sWidgets area%s"
msgstr ""
#: views/form/editor.html:100
msgid "Widgets areas"
#: views/form/editor.html:96
msgid "%sHTML%s"
msgstr ""
#: views/form/editor.html:123
msgid "[link_html]HTML[/link_html]"
msgstr ""
#: views/form/editor.html:135
#: views/form/editor.html:119
msgid "Fields"
msgstr ""
#: views/form/editor.html:141
#: views/form/editor.html:125
msgid "Add New Field"
msgstr ""
#: views/form/editor.html:150
#: views/form/editor.html:134
msgid "Styles"
msgstr ""
#: views/form/editor.html:154
#: views/form/editor.html:138
msgid "Preview"
msgstr ""

View File

@ -44,8 +44,8 @@ class Initializer {
)
);
// renderer: i18n
$this->renderer->addExtension(new Renderer\i18n());
// renderer: i18n (passing the text)
$this->renderer->addExtension(new Renderer\i18n($this->shortname));
// renderer: global variables
$this->renderer->addExtension(new Renderer\Assets(array(
'assets_url' => $this->assets_url,
@ -205,28 +205,22 @@ class Initializer {
false,
dirname(plugin_basename($this->file)) . '/lang/'
);
// set rtl flag
$this->renderer->addGlobal('is_rtl', is_rtl());
}
public function setup_textdomain() {
$domain = 'wysija-newsletters';
$locale = apply_filters(
'plugin_locale',
get_locale(),
$domain
$this->shortname
);
// $language_path = WP_LANG_DIR
// . '/'
// . $domain
// . '/'
// . $domain
// . '-'
// . $locale
// . '.mo';
$language_path = $this->languages_path.'/'.$domain.'-'.$locale.'.mo';
load_textdomain($domain, $language_path);
$language_path = $this->languages_path.'/'.$this->shortname.'-'.$locale.'.mo';
load_textdomain($this->shortname, $language_path);
load_plugin_textdomain(
$domain,
$this->shortname,
false,
dirname(plugin_basename($this->file)) . '/lang/'
);
@ -259,6 +253,40 @@ class Initializer {
}
public function admin_page_form() {
$this->data['form'] = array(
'form' => 1,
'form_name' => __("New form"),
'form_created_at' => time(),
'data' => array(
'settings' => array(
'on_success' => 'message',
'success_message' => __('Check your inbox or spam folder now to confirm your subscription.'),
'lists' => array(1, 2),
'lists_selected_by' => 'admin'
),
'body' => array(
array(
'name' => __('Email'),
'type' => 'input',
'field' => 'email',
'static' => true,
'params' => array(
'label' => __('Email'),
'required' => true
)
),
array(
'name' => __('Submit'),
'type' => 'submit',
'field' => 'submit',
'static' => true,
'params' => array(
'label' => __('Subscribe!')
)
)
)
)
);
echo $this->renderer->render('form/editor.html', $this->data);
}

View File

@ -3,7 +3,11 @@ namespace MailPoet\Renderer;
class i18n extends \Twig_Extension {
public function __construct() {
private $_text_domain;
public function __construct($text_domain) {
// set text domain
$this->_text_domain = $text_domain;
}
public function getName() {
@ -19,10 +23,31 @@ class i18n extends \Twig_Extension {
foreach($functions as $function) {
$twig_functions[] = new \Twig_SimpleFunction(
$function,
$function,
array($this, $function),
array('is_safe' => array('all'))
);
}
return $twig_functions;
}
public function __() {
$args = func_get_args();
return call_user_func_array('__', $this->setTextDomain($args));
}
public function _n() {
$args = func_get_args();
return call_user_func_array('_n', $this->setTextDomain($args));
}
private function setTextDomain($args = array()) {
// make sure that the last argument is our text domain
if($args[count($args) - 1] !== $this->_text_domain) {
// otherwise add it to the list of arguments
$args[] = $this->_text_domain;
}
return $args;
}
}

View File

@ -40,8 +40,10 @@ class FormRendererCest {
// tests
public function itCanRenderAForm(){
$html = \MailPoet\Form\Renderer::render($this->form_data);
expect($html)->contains('Email');
expect($html)->contains('Subscribe!');
// we need an email field
expect($html)->contains('name="email"');
// we need a submit button
expect($html)->contains('type="submit"');
}
public function itCanRenderAFormStyles(){

View File

@ -5,7 +5,7 @@
<span id="mailpoet_form_name">{{ form.form_name }}</span>
<input id="mailpoet_form_name_input" type="text" value="" style="display:none;" />
<span>
<a id="mailpoet_form_edit_name" class="button" href="javascript:;">{{ form_edit_name }}</a>
<a id="mailpoet_form_edit_name" class="button" href="javascript:;">{{ __('Edit name' ) }}</a>
</span>
{% endblock %}
@ -39,16 +39,7 @@
<strong>{{ __('This form adds subscribers to these lists:') }}</strong>
</p>
<select name="lists" data-placeholder="{{ __('Choose a list') }}" multiple>
<!-- $selected_lists = array($default_list['list']) }}
if(isset($form['data']['settings']['lists']) && !empty($form['data']['settings']['lists'])) {
$selected_lists = $form['data']['settings']['lists'];
}
foreach($lists as $list) {
$is_checked = (in_array($list['list'], $selected_lists)) ? 'selected="selected"' : '';
print '<option value="'.$list['list'].'" '.$is_checked.' />'.$list['list_name'].'</option>';
} -->
<option value="1" {% if 1 in form.data.settings.lists %}selected="selected"{% endif %}>My First list</option>
</select>
<!-- error if user tries to save and has not selected a list -->
<p class="mailpoet_error" data-error="admin_no_list">{{ __('You have to select at least 1 list') }}</p>
@ -67,14 +58,12 @@
</label>
</p>
<!-- default success message -->
{% if form.data.settings.succes_message %}
{% set success_message = form.data.settings.succes_message %}
{% if form.data.settings.success_message %}
{% set success_message = form.data.settings.success_message %}
{% else %}
{% set success_message = __('Check your inbox now to confirm your subscription.') %}
{% endif %}
<p id="mailpoet_on_success_message" class="mailpoet_on_success_option"><textarea name="success_message">{{ success_message }}</textarea></p>
<p id="mailpoet_on_success_page" class="mailpoet_on_success_option"><select name="success_page">
<!-- $pages = get_pages() }}
@ -90,38 +79,32 @@
</div>
<!-- Toolbar: Shortcodes / Export -->
<div class="mailpoet_toolbar_section closed">
<div class="mailpoet_toolbar_section">
<a href="javascript:;" class="mailpoet_toggle"><br /></a>
<h3>{{ __('Shortcodes') }}</h3>
<div>
<!-- Form export links -->
<p>
{{ __("You can easily add this form to your theme's in the") }}&nbsp;<a href="widgets.php" target="_blank">{{ __('Widgets areas') }}</a>
{{ __("You can easily add this form to your theme's in the %sWidgets area%s")
| format('<a href="widgets.php" target="_blank">', '</a>')
| raw
}}
</p>
<p><!-- echo str_replace(
array(
'[link_html]',
'[link_php]',
'[link_iframe]',
'[link_shortcode]',
'[/link_html]',
'[/link_php]',
'[/link_iframe]',
'[/link_shortcode]'
),
array(
<p>
{{ __('%sHTML%s, %sPHP%s, %siframe%s and %sshortcode%s versions are also available.', 'wysija-newsletters')
| format(
'<a href="javascript:;" class="mailpoet_form_export_toggle" data-type="html">',
'</a>',
'<a href="javascript:;" class="mailpoet_form_export_toggle" data-type="php">',
'</a>',
'<a href="javascript:;" class="mailpoet_form_export_toggle" data-type="iframe">',
'</a>',
'<a href="javascript:;" class="mailpoet_form_export_toggle" data-type="shortcode">',
'</a>',
'</a>',
'</a>',
'</a>'
),
__('[link_html]HTML[/link_html], [link_php]PHP[/link_php], [link_iframe]iframe[/link_iframe] and [link_shortcode]shortcode[/link_shortcode] versions are also available.')
) }} -->
)
| raw
}}
</p>
<!-- Form export -->
@ -164,7 +147,26 @@
{{ javascript(
'lib/prototype.min.js',
'lib/select2.js',
'lib/scriptaculous.min.js',
'form_editor.js'
)}}
{{ stylesheet(
'lib/select2/select2.css'
) }}
<script type="text/javascript">
jQuery(function($) {
$(function() {
// load form
WysijaForm.load({{ form | json_encode | raw }});
// initialize list selector
$('select[name="lists"]').select2({
width:'100%'
});
});
});
</script>
{% endblock %}

View File

@ -98,13 +98,13 @@
$('#modal_popup').on('click', function() {
MailPoet.Modal.popup({
title: "Testing <strong>1 2...</strong>",
template: "<h3>Hello World!</h3>"
template: "<h3>{{ __('Hello World!') }}</h3>"
});
});
$('#modal_panel').on('click', function() {
MailPoet.Modal.panel({
title: "Testing 1 2...",
template: "<h3>Hello World!</h3>",
template: "<h3>{{ __('Hello World!') }}</h3>",
width: "40%",
overlay: true
});

View File

@ -1,8 +1,13 @@
<!-- notices -->
<div id="mailpoet_notice_system" class="mailpoet_notice update-nag" style="display:none;"></div>
<div id="mailpoet_notice_error" class="mailpoet_notice error" style="display:none;"></div>
<div id="mailpoet_notice_success" class="mailpoet_notice updated" style="display:none;"></div>
<!-- main container -->
<div class="wrap">
<!-- title block -->
{% block title %}{% endblock %}
<!-- content block -->
{% block content %}{% endblock %}
</div>
@ -10,6 +15,10 @@
{{ stylesheet(
'admin.css'
)}}
<!-- rtl specific stylesheet -->
{% if is_rtl %}
{{ stylesheet('rtl.css') }}
{% endif %}
<!-- javascripts -->
{{ javascript(