Skip to content

Commit

Permalink
Add autoloading and make branding consistent (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
kasparsd authored Aug 20, 2019
1 parent 5a4dcfd commit d841617
Show file tree
Hide file tree
Showing 28 changed files with 7,091 additions and 273 deletions.
16 changes: 0 additions & 16 deletions .distignore

This file was deleted.

11 changes: 11 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "plugin:@wordpress/eslint-plugin/es5",
"overrides": [
{
"files": [
"Gruntfile.js"
],
"extends": "plugin:@wordpress/eslint-plugin/recommended"
}
]
}
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
/node_modules
/vendor
/.vagrant
/composer.lock
/package-lock.json
/phpcs.xml
/phpunit.xml
.DS_Store
29 changes: 0 additions & 29 deletions .jshintrc

This file was deleted.

30 changes: 23 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
language: php
dist: xenial

language:
- php
- node_js

php:
- 7.2
- 5.6
- "7.3"
- "7.2"
- "5.6"

install:
- composer install
- npm install

script:
- composer lint
- composer test
- npm run lint
- npm run test
- npm run mess -- -- --ignore-violations-on-exit

after_script:
- vendor/bin/php-coveralls -v
- npm run coverage

branches:
only:
- master
- develop

notifications:
email: false

cache:
npm: true
directories:
- $HOME/.composer/cache
69 changes: 34 additions & 35 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
/* jshint es3: false, esversion: 5, node: true */
/* eslint-env node */

module.exports = function( grunt ) {

// Load all Grunt plugins.
require( 'load-grunt-tasks' )( grunt );

// TODO: Move to own Grunt plugin.
grunt.registerTask( 'readmeMdToTxt', 'Log some stuff.', function() {

var formatReadme = function( content ) {
var replaceRules = {
const formatReadme = ( content ) => {
const replaceRules = {
'#': '=== $1 ===',
'##': '== $1 ==',
'#{3,}': '= $1 =',
};

// Replace Markdown headings with WP.org style headings
Object.keys( replaceRules ).forEach( function( pattern ) {
var patternRegExp = [ '^', pattern, '\\s(.+)$' ].join('');
const patternRegExp = [ '^', pattern, '\\s(.+)$' ].join( '' );

content = content.replace(
new RegExp( patternRegExp, 'gm' ),
Expand All @@ -28,39 +26,39 @@ module.exports = function( grunt ) {
return content;
};

var replaceVars = function( content, vars ) {
var handlebars = require( 'handlebars' );
var template = handlebars.compile( content );
const replaceVars = ( content, vars ) => {
const handlebars = require( 'handlebars' );
const template = handlebars.compile( content );

return template( vars );
};

var getPluginVersion = function( pluginFile ) {
var pluginSource = grunt.file.read( pluginFile );
var pattern = new RegExp( 'Version:\\s*(.+)$', 'mi' );
var match = pluginSource.match( pattern );
const getPluginVersion = ( pluginFile ) => {
const pluginSource = grunt.file.read( pluginFile );
const pattern = new RegExp( 'Version:\\s*(.+)$', 'mi' );
const match = pluginSource.match( pattern );

if ( match.length ) {
return match[1];
return match[ 1 ];
}

return null;
};

var path = require('path');
var pkgConfig = grunt.config.get( 'pkg' );
const path = require( 'path' );
const pkgConfig = grunt.config.get( 'pkg' );

var options = this.options( {
const options = this.options( {
src: 'readme.md',
dest: 'readme.txt',
} );

var srcFile = grunt.file.read( options.src );
var destDir = path.dirname( options.dest );
const srcFile = grunt.file.read( options.src );
const destDir = path.dirname( options.dest );

// Extract the version from the main plugin file.
if ( 'undefined' === typeof pkgConfig.version ) {
var pluginVersion = getPluginVersion( 'widget-context.php' );
const pluginVersion = getPluginVersion( 'widget-context.php' );

if ( ! pluginVersion ) {
grunt.warn( 'Failed to parse the plugin version in the plugin file.' );
Expand All @@ -70,7 +68,7 @@ module.exports = function( grunt ) {
}

// Replace all variables.
var readmeTxt = replaceVars( srcFile, pkgConfig );
const readmeTxt = replaceVars( srcFile, pkgConfig );

// Ensure we have the destination directory.
if ( destDir ) {
Expand All @@ -79,14 +77,6 @@ module.exports = function( grunt ) {

// Write the readme.txt.
grunt.file.write( options.dest, formatReadme( readmeTxt ) );

});

var ignoreParse = require( 'parse-gitignore' );

// Get a list of all the files and directories to exclude from the distribution.
var distignore = ignoreParse( '.distignore', {
invert: true,
} );

grunt.initConfig( {
Expand All @@ -107,10 +97,20 @@ module.exports = function( grunt ) {

copy: {
dist: {
src: [ '**' ].concat( distignore ),
src: [
'src/**',
'vendor/**',
'assets/css/**',
'assets/js/**',
'widget-context.php',
'LICENSE',
'composer.json',
'composer.lock',
'screenshot-*.png',
],
dest: '<%= dist_dir %>',
expand: true,
}
},
},

wp_deploy: {
Expand All @@ -124,13 +124,13 @@ module.exports = function( grunt ) {
options: {
deploy_tag: true,
deploy_trunk: true,
}
},
},
trunk: {
options: {
deploy_tag: false,
}
}
},
},
},
} );

Expand All @@ -155,5 +155,4 @@ module.exports = function( grunt ) {
'wp_deploy:trunk',
]
);

};
21 changes: 0 additions & 21 deletions Homestead.yaml

This file was deleted.

27 changes: 7 additions & 20 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
require 'yaml'
# Local dev environment https://github.com/wpsh/wpsh-local

confDir = File.expand_path("vendor/laravel/homestead", File.dirname(__FILE__))
homesteadYamlPath = File.expand_path("Homestead.yaml", File.dirname(__FILE__))
load File.join(
File.dirname(__FILE__),
"vendor/wpsh/local/Vagrantfile"
)

require File.expand_path(confDir + '/scripts/homestead.rb')

Vagrant.require_version '>= 1.9.0'

Vagrant.configure("2") do |config|
settings = YAML::load(File.read(homesteadYamlPath))

Homestead.configure(config, settings)

# Download and setup our WP site; wp-cli provided out of the box.
config.vm.provision "shell",
inline: "wp config create",
privileged: false

if defined? VagrantPlugins::HostsUpdater
config.hostsupdater.aliases = settings['sites'].map { |site| site['map'] }
end
Vagrant.configure(2) do |config|
config.vm.hostname = "widgetcontext"
end
37 changes: 14 additions & 23 deletions assets/js/widget-context.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
jQuery(document).ready(function($) {

function show_hide_controls( widget_id ) {

var condition = $( '#widget-context-' + widget_id + ' .wc-field-select-condition select' ).val();

$( '#widget-context-' + widget_id ).toggleClass( 'context-global', ( condition == 'show' || condition == 'hide' ) );
/* global jQuery, document */
jQuery( document ).ready( function( $ ) {
function showHideControls( widgetId ) {
var condition = $( '#widget-context-' + widgetId + ' .wc-field-select-condition select' ).val();

$( '#widget-context-' + widgetId ).toggleClass( 'context-global', ( condition === 'show' || condition === 'hide' ) );
}

$('.widget-context-inside').each(function() {

show_hide_controls( $(this).data('widget-id') );

});
$( '.widget-context-inside' ).each( function() {
showHideControls( $( this ).data( 'widget-id' ) );
} );

$('#widgets-right, #widgets-left, #customize-theme-controls').on( 'change', '.wc-field-select-condition select', function(){

show_hide_controls( $(this).parent().data('widget-id') );

});
$( '#widgets-right, #widgets-left, #customize-theme-controls' ).on( 'change', '.wc-field-select-condition select', function() {
showHideControls( $( this ).parent().data( 'widget-id' ) );
} );

$( document ).on( 'widget-updated widget-added', function( e, widget ) {

show_hide_controls( widget.find('input[name="widget-id"]').val() );

});

});
showHideControls( widget.find( 'input[name="widget-id"]' ).val() );
} );
} );
Loading

0 comments on commit d841617

Please sign in to comment.