Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a bug that caused crashing in certain circumstances in the front-end #11

Merged
merged 1 commit into from
Nov 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [2.0.2] 2017-11-15

### Changed
- Fixed a bug that caused crashing in certain circumstances in the front-end
- Enhanced the documentation with better examples and fixed some typos

## [2.0.1] 2017-11-10

### Changed
- Made the enqueue call use the plugin version for the script version
- Changed the enqueue call to use the plugin version for the script version

## [2.0.0] 2017-10-20

Expand Down
27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ A DustPress plugin that provides a handy JavaScript library for using your DustP
- Plugin url: https://github.com/devgeniem/dustpress-debugger
- Tags: dustpress, wordpress, plugins, dustjs, dust.js
- Requires at least: 4.2.0
- Requires DustPress version: 1.6.10
- Tested up to: 4.7.2
- Requires DustPress version: 1.7.0
- Tested up to: 4.9.0
- License: GPL-3.0
- License URI: http://www.gnu.org/licenses/gpl-3.0.html

## Usage

You can call for SomeModel's method "SomeMethod" with the following call:
You can call for `SomeModel`'s method `SomeMethod` with following code:

```
dp("SomeModel/SomeMethod", {
tidy: true,
args: {
'foo': 'bar'
}
success: function( data ) {
// do what you want with the data
},
Expand All @@ -30,11 +33,13 @@ dp("SomeModel/SomeMethod", {

`tidy: true` parameter cleans up the data tree a bit for more usability. Feel free to try the queries with and without it to see the difference.

`args` parameter passes arguments to the PHP side. They can be accessed there with `$this->get_args();`.

If you want, you can even render HTML with Dust templates.

```
dp("SomeModel/SomeMethod", {
partial: "SomePartial",
dp( 'SomeModel/SomeMethod', {
partial: 'SomePartial',
success: function( data ) {
// do what you want with the data
},
Expand All @@ -43,12 +48,12 @@ dp("SomeModel/SomeMethod", {
}
});
```
This code takes the data of SomeMethod and renders it with SomePartial. Variable `data` then contains the ready html.
This code takes the data of `SomeMethod` and renders it with `SomePartial`. Variable `data` then contains the ready html.

You can also omit the method completely if you want to get the data of a complete model.

```
dp("SomeModel", {
dp( 'SomeModel', {
success: function( data ) {
// do what you want with the data
},
Expand All @@ -60,7 +65,7 @@ dp("SomeModel", {

If you want to call several functions but not all at once, you can do so by replacing the method's name on the call with a comma-separated list.
```
dp("SomeModel/SomeMethod,AnotherMethod", {
dp( 'SomeModel/SomeMethod,AnotherMethod', {
success: function( data ) {
// data.SomeMethod and data.AnotherMethod contain the return values
},
Expand Down Expand Up @@ -88,7 +93,7 @@ class SomeModel extends DustPressModel {
}
```

If you need to block visibility of public funcions, you can do this by examining the `DOING_AJAX` constant or calling the core function `is_dustpress_ajax`.
If you need to block visibility of public funcions, you can do this by examining the `DOING_AJAX` constant or calling the DustPress core function `is_dustpress_ajax`.

```
class SomeModel extends DustPressModel {
Expand All @@ -111,4 +116,6 @@ class SomeModel extends DustPressModel {
Recommended installation to WP project is through composer:
```
$ composer require devgeniem/dustpress-js
```
```

Obviously you can also download the ZIP file from GitHub and extract it into your plugins directory.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
}
],
"require": {
"devgeniem/dustpress": ">=0.4.0",
"php": ">=5.4",
"devgeniem/dustpress": ">=1.7.0",
"php": ">=7.0",
"composer/installers": "^1.0.12"
},
"keywords": [
Expand Down
24 changes: 13 additions & 11 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
* Plugin Name: DustPress.JS
* Plugin URI: https://github.com/devgeniem/dustpress-js
* Description: DustPress JavaScript library. Provides a front-end interface for interacting with the backend functions.
* Version: 2.0.1
* Version: 2.0.2
* Author: Geniem Oy / Miika Arponen & Ville Siltala
* Author URI: http://www.geniem.com
*/

class DustPressJs {

/**
Expand All @@ -24,17 +23,20 @@ public function __construct() {
}

/**
* This function enqueues front end scripts.
*
* @type function
* @date 17/12/2015
* @since 0.1.0
*
* @return boolean
*/
* This function enqueues front end scripts.
*
* @type function
* @date 17/12/2015
* @since 0.1.0
*
* @return void
*/
public function enqueue_scripts() {
wp_enqueue_script( 'jquery' );
$version = get_plugin_data( __FILE__ )['Version'];

$plugin_data = get_file_data( __FILE__, [ 'Version' => 'Version' ], 'plugin' );

$version = $plugin_data['Version'];
wp_enqueue_script( 'dustpress', trailingslashit( plugin_dir_url( __FILE__ ) ) . 'js/dustpress-min.js', array('jquery'), $version, false );
}
}
Expand Down