Skip to content

Commit

Permalink
Merge pull request #89 from skyverge/4.0-beta
Browse files Browse the repository at this point in the history
Howdy 4.0.0
  • Loading branch information
maxrice committed Jul 28, 2015
2 parents 2998f33 + f8593a8 commit 95bf7c6
Show file tree
Hide file tree
Showing 29 changed files with 813 additions and 732 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/.settings
/.project
*.zip
.sass-cache*

# NPM packages used by Grunt.js
/node_modules

# NPM debug log
npm-debug.log
60 changes: 60 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* jshint node:true */
module.exports = function( grunt ) {
'use strict';

// load all grunt tasks matching the `grunt-*` pattern
require( 'load-grunt-tasks' )( grunt );

// Show elapsed time
require( 'time-grunt' )( grunt );

var _ = require( 'underscore' );
var path = require( 'path' );

// Set plugin slug option
//grunt.option( 'plugin-slug', path.basename( process.cwd() ) );

var gruntConfig = {};

// options
gruntConfig.options = {};

// Set folder templates
gruntConfig.dirs = {
css: 'assets/css',
js: 'assets/js',
images: 'assets/images',
fonts: 'assets/fonts',
build: 'build'
};

function loadConfig( filepath ) {
var object = {};
var key;

filepath = path.normalize( path.resolve( process.cwd(), filepath ) + '/' )

var files = grunt.file.glob.sync( '*', { cwd: filepath } );

files.forEach( function( option ) {
key = option.replace(/\.js$/,'');
object = _.extend( object, require( filepath + option )( grunt ) );
});

return object;
};

// load task configs
gruntConfig = _.extend( gruntConfig, loadConfig( './grunt/configs/' ) );

// Init Grunt
grunt.initConfig( gruntConfig );

// Register Tasks
grunt.registerTask( 'default', [
'coffee',
'uglify',
'sass',
'clean'
] );
};
21 changes: 21 additions & 0 deletions grunt/configs/clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* jshint node:true */
module.exports = function( grunt ) {
'use strict';

var util = grunt.option( 'util' );
var _ = require( 'underscore' );
var config = {};

// Delete source map from the CoffeeScript compilation
config.clean = {
options: {
force: true
},
clean: [
// Delete map files
'woocommerce/payment-gateway/assets/js/frontend/*.min.js.map'
]
};

return config;
};
33 changes: 33 additions & 0 deletions grunt/configs/coffee.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* jshint node:true */
module.exports = function( grunt ) {
'use strict';

var config = {};

// Compile CoffeeScript
config.coffee = {
compile: {
options: {
sourceMap: true
},
files: [
{
expand: true,
cwd: 'woocommerce/payment-gateway/assets/js/admin/',
dest: 'woocommerce/payment-gateway/assets/js/admin/',
src: '*.coffee',
ext: '.min.js'
},
{
expand: true,
cwd: 'woocommerce/payment-gateway/assets/js/frontend/',
dest: 'woocommerce/payment-gateway/assets/js/frontend/',
src: '*.coffee',
ext: '.min.js'
}
]
}
};

return config;
};
34 changes: 34 additions & 0 deletions grunt/configs/sass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* jshint node:true */
module.exports = function( grunt ) {
'use strict';

var config = {};

// Compile all .scss files.
config.sass = {
compile: {
options: {
style: 'compressed',
sourcemap: true
},
files: [
{
expand: true,
cwd: 'woocommerce/payment-gateway/assets/css/admin/',
dest: 'woocommerce/payment-gateway/assets/css/admin/',
src: ['*.scss', '!_*.scss'],
ext: '.min.css'
},
{
expand: true,
cwd: 'woocommerce/payment-gateway/assets/css/frontend/',
dest: 'woocommerce/payment-gateway/assets/css/frontend/',
src: ['*.scss', '!_*.scss'],
ext: '.min.css'
}
]
}
};

return config;
};
23 changes: 23 additions & 0 deletions grunt/configs/uglify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* jshint node:true */
module.exports = function( grunt ) {
'use strict';
var config = {};

// Add Uglify task with legacy rules
config.uglify = {
uglify: {
options : {
sourceMap: true,
sourceMapIncludeSources: true,
sourceMapIn: 'woocommerce/payment-gateway/assets/js/frontend/sv-wc-payment-gateway-frontend.min.js.map', // input sourcemap from CoffeeScript compilation
sourceMapName: 'woocommerce/payment-gateway/assets/js/frontend/sv-wc-payment-gateway-frontend.min.map'
},
files : [{
src: [ 'woocommerce/payment-gateway/assets/js/frontend/sv-wc-payment-gateway-frontend.min.js' ], // uglify JS from CoffeeScript compilation
dest: 'woocommerce/payment-gateway/assets/js/frontend/sv-wc-payment-gateway-frontend.min.js'
}]
}
}

return config;
};
29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "wc-plugin-framework",
"version": "4.0.0",
"author": "SkyVerge Team",
"homepage": "http://www.skyverge.com",
"repository": {
"type": "git",
"url": "https://github.com/skyverge/wc-plugin-framework.git"
},
"bugs": {
"url": "https://github.com/skyverge/wc-plugin-framework/issues"
},
"engines": {
"node": ">= 0.10.0"
},
"devDependencies": {
"grunt": "~0.4.5",
"grunt-newer": "~1.1.1",
"grunt-notify": "~0.4.1",
"grunt-contrib-clean": "~0.6.0",
"grunt-contrib-coffee": "~0.13.0",
"grunt-contrib-uglify": "~0.9.1",
"grunt-contrib-sass": "~0.9.2",
"load-grunt-tasks": "~3.2.0",
"time-grunt": "~1.2.1",
"underscore": "~1.8.3",
"underscore.string": "~3.1.1"
}
}
7 changes: 2 additions & 5 deletions woocommerce/api/class-sv-wc-api-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ abstract class SV_WC_API_Base {
/**
* Perform the request and return the parsed response
*
* TODO: during next backwards-incompatible framework update, the try/catch
* block should catch SV_WC_Plugin_Exception for maximum flexibility
*
* @since 2.2.0
* @param object $request class instance which implements \SV_WC_API_Request
* @throws Exception
Expand Down Expand Up @@ -110,7 +107,7 @@ protected function perform_request( $request ) {
// parse & validate response
$response = $this->handle_response( $response );

} catch ( SV_WC_API_Exception $e ) {
} catch ( SV_WC_Plugin_Exception $e ) {

// alert other actors that a request has been made
$this->broadcast_request();
Expand All @@ -133,7 +130,7 @@ protected function perform_request( $request ) {
* @return array|WP_Error
*/
protected function do_remote_request( $request_uri, $request_args ) {
return wp_remote_request( $request_uri, $request_args );
return wp_safe_remote_request( $request_uri, $request_args );
}


Expand Down
10 changes: 5 additions & 5 deletions woocommerce/api/class-sv-wc-api-json-response.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* Useful for API's that return application/json responses
*
* @since 3.1.2-1
* @since 4.0.0
* @see SV_WC_API_Response
*/
class SV_WC_API_JSON_Response implements SV_WC_API_Response {
Expand All @@ -48,7 +48,7 @@ class SV_WC_API_JSON_Response implements SV_WC_API_Response {
/**
* Build a response object from the raw response JSON
*
* @since 3.1.2-1
* @since 4.0.0
* @param string $raw_response_json the raw response JSON
*/
public function __construct( $raw_response_json ) {
Expand All @@ -60,7 +60,7 @@ public function __construct( $raw_response_json ) {
/**
* Magic accessor for response data attributes
*
* @since 3.1.2-1
* @since 4.0.0
* @param string $name the attribute name to get
* @return mixed the attribute value
*/
Expand All @@ -74,7 +74,7 @@ public function __get( $name ) {
/**
* Returns the string representation of this response
*
* @since 3.1.2-1
* @since 4.0.0
* @see SV_WC_API_Response::to_string()
* @return string the raw response
*/
Expand All @@ -88,7 +88,7 @@ public function to_string() {
* Returns the string representation of this response with any and all
* sensitive elements masked or removed
*
* @since 3.1.2-1
* @since 4.0.0
* @see SV_WC_API_Response::to_string_safe()
* @return string response safe for logging/displaying
*/
Expand Down
35 changes: 27 additions & 8 deletions woocommerce/api/class-sv-wc-api-rest-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/**
* Base REST API Request class
*
* @since 3.1.2-1
* @since 4.0.0
*/
class SV_WC_API_REST_Request implements SV_WC_API_Request {

Expand All @@ -48,7 +48,7 @@ class SV_WC_API_REST_Request implements SV_WC_API_Request {
/**
* Construct REST request object
*
* @since 3.1.2-1
* @since 4.0.0
* @param string $method the request method, one of HEAD, GET, PUT, PATCH, POST, DELETE
* @param string $path optional request path
* @param array $params optional associative array of request parameters
Expand All @@ -66,7 +66,7 @@ public function __construct( $method, $path = '', $params = array() ) {
/**
* Returns the method for this request: one of HEAD, GET, PUT, PATCH, POST, DELETE
*
* @since 3.1.2-1
* @since 4.0.0
* @see SV_WC_API_Request::get_method()
* @return string the request method
*/
Expand All @@ -78,7 +78,7 @@ public function get_method() {
/**
* Returns the request path
*
* @since 3.1.2-1
* @since 4.0.0
* @see SV_WC_API_Request::get_path()
* @return string the request path
*/
Expand All @@ -90,35 +90,54 @@ public function get_path() {
/**
* Returns the request params, if any
*
* @since 3.1.2-1
* @since 4.0.0
* @return array the request params
*/
public function get_params() {
return $this->params;
}


/**
* Returns the request params, url encoded
*
* @since 4.0.0
* @see SV_WC_API_REST_Request::get_params()
* @return array the request params, url encoded
*/
public function get_encoded_params() {

$encoded_params = array();
foreach ( $this->get_params() as $key => $value ) {
$encoded_params[ $key ] = urlencode( $value );
}

return $encoded_params;
}


/** API Helper Methods ******************************************************/


/**
* Returns the string representation of this request
*
* @since 3.1.2-1
* @since 4.0.0
* @see SV_WC_API_Request::to_string()
* @return string request
*/
public function to_string() {

// URL encode params
return build_query( $this->get_params() );
return build_query( $this->get_encoded_params() );
}


/**
* Returns the string representation of this request with any and all
* sensitive elements masked or removed
*
* @since 3.1.2-1
* @since 4.0.0
* @see SV_WC_API_Request::to_string_safe()
* @return string the request, safe for logging/displaying
*/
Expand Down
Loading

0 comments on commit 95bf7c6

Please sign in to comment.