Skip to content

Commit

Permalink
Implements strings.json string-loading strategy.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmcclure committed Jan 8, 2014
1 parent b26afee commit c0b0c51
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 57 deletions.
1 change: 1 addition & 0 deletions Gruntfile.js
Expand Up @@ -248,6 +248,7 @@ module.exports = function(grunt) {

// Run all tests.
grunt.registerTask('test', [
'compile:min',
'clean:fixtures',
'phpunit',
'jasmine'
Expand Down
38 changes: 17 additions & 21 deletions NeatlineWaypointsPlugin.php
Expand Up @@ -69,7 +69,6 @@ public function hookNeatlinePublicTemplates($args)
public function hookNeatlineEditorTemplates($args)
{
if ($args['exhibit']->hasWidget(self::ID)) {
echo get_view()->partial('waypoints/editor/strings.php');
echo get_view()->partial('waypoints/editor/form.php');
echo get_view()->partial('waypoints/editor/list.php');
}
Expand Down Expand Up @@ -112,9 +111,7 @@ public function hookNeatlineEditorStatic($args)
*/
public function filterNeatlineExhibitWidgets($widgets)
{
return array_merge($widgets, array(
self::NAME => self::ID
));
return array_merge($widgets, array(self::NAME => self::ID));
}


Expand All @@ -126,39 +123,38 @@ public function filterNeatlineExhibitWidgets($widgets)
*/
public function filterNeatlineRecordWidgets($widgets)
{
return array_merge($widgets, array(
self::NAME => self::ID
));
return array_merge($widgets, array(self::NAME => self::ID));
}


/**
* Register ordering API endpoint on `Neatline.g`.
* Register the exhibit widget tab.
*
* @param array $globals The array of global properties.
* @param array $args Array of arguments, with `exhibit`.
* @param array $tabs Tabs, <LABEL> => <ID>.
* @return array The modified array.
*/
public function filterNeatlineGlobals($globals, $args)
public function filterNeatlineExhibitTabs($tabs, $args)
{
return array_merge($globals, array('waypoints' => array(
'order_api' => url('neatline-waypoints')
)));
if ($args['exhibit']->hasWidget(self::ID)) {
$tabs[self::NAME] = 'waypoints';
}
return $tabs;
}


/**
* Register the exhibit widget tab.
* Register ordering API endpoint on `Neatline.g`.
*
* @param array $tabs Tabs, <LABEL> => <ID>.
* @param array $globals The array of global properties.
* @param array $args Array of arguments, with `exhibit`.
* @return array The modified array.
*/
public function filterNeatlineExhibitTabs($tabs, $args)
public function filterNeatlineGlobals($globals, $args)
{
if ($args['exhibit']->hasWidget(self::ID)) {
$tabs[self::NAME] = 'waypoints';
}
return $tabs;
return array_merge($globals, array('waypoints' => array(
'strings' => nl_getStrings(NL_WAYPOINTS_DIR.'/strings.json'),
'order_api' => url('neatline-waypoints')
)));
}


Expand Down
16 changes: 16 additions & 0 deletions strings.json
@@ -0,0 +1,16 @@
{

"order": {

"save": {
"success": "The waypoint order was saved successfully!",
"error": "There was an error - the waypoint order was not saved."
},

"placeholders": {
"empty": "No waypoints have been added yet!"
}

}

}
11 changes: 7 additions & 4 deletions tests/jasmine/tests/editor/Open.spec.js
Expand Up @@ -85,7 +85,11 @@ describe('Editor | Open Form', function() {
// be displayed under "Edit Waypoint Order."
// ----------------------------------------------------------------------

expect($(rows[0])).toHaveText(WP_STRINGS.order.placeholders.empty);
// Placeholder text.
var empty = Neatline.g.waypoints.strings.order.placeholders.empty;
expect($(rows[0])).toHaveText(empty);

// No waypoints listed.
expect(rows.length).toEqual(1);

});
Expand All @@ -106,9 +110,8 @@ describe('Editor | Open Form', function() {
// The row with the placeholder message should not be sortable.
// ----------------------------------------------------------------------

expect(
WP.v.editor.__ui.list.sortable('option', 'disabled')
).toBeTruthy();
var cantSort = WP.v.editor.__ui.list.sortable('option', 'disabled');
expect(cantSort).toBeTruthy();

});

Expand Down
4 changes: 2 additions & 2 deletions tests/jasmine/tests/editor/Save.spec.js
Expand Up @@ -83,7 +83,7 @@ describe('Editor | Save Order', function() {

// Should flash success.
expect(toastr.info).toHaveBeenCalledWith(
WP_STRINGS.order.save.success
Neatline.g.waypoints.strings.order.save.success
);

});
Expand All @@ -104,7 +104,7 @@ describe('Editor | Save Order', function() {

// Should flash error.
expect(toastr.error).toHaveBeenCalledWith(
WP_STRINGS.order.save.error
Neatline.g.waypoints.strings.order.save.error
);

});
Expand Down
4 changes: 2 additions & 2 deletions views/shared/javascripts/editor/waypoints.view.js
Expand Up @@ -142,7 +142,7 @@ Neatline.module('Editor.Exhibit.Waypoints', function(Waypoints) {

// Flash success message.
Neatline.execute('EDITOR:notifySuccess',
WP_STRINGS.order.save.success
Neatline.g.waypoints.strings.order.save.success
);

},
Expand All @@ -155,7 +155,7 @@ Neatline.module('Editor.Exhibit.Waypoints', function(Waypoints) {

// Flash error message.
Neatline.execute('EDITOR:notifyError',
WP_STRINGS.order.save.error
Neatline.g.waypoints.strings.order.save.error
);

}
Expand Down
2 changes: 1 addition & 1 deletion views/shared/javascripts/payloads/waypoints-editor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion views/shared/waypoints/editor/list.php
Expand Up @@ -16,7 +16,7 @@
<!-- Placeholder. -->
<% if (records.length == 0) { %>
<div class="alert alert-info">
<%= WP_STRINGS.order.placeholders.empty %>
<%= Neatline.g.waypoints.strings.order.placeholders.empty %>
</div>
<% } %>

Expand Down
26 changes: 0 additions & 26 deletions views/shared/waypoints/editor/strings.php

This file was deleted.

0 comments on commit c0b0c51

Please sign in to comment.