@caweb/cli 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -27
- package/lib/admin.js +40 -0
- package/lib/caweb.js +1 -1
- package/lib/cli.js +24 -0
- package/lib/commands/blocks/create-block.js +110 -0
- package/lib/commands/blocks/update-block.js +66 -0
- package/lib/commands/destroy.js +5 -15
- package/lib/commands/index.js +5 -1
- package/lib/commands/start.js +5 -1
- package/lib/commands/tasks/update-plugins.js +1 -1
- package/lib/commands/test.js +4 -4
- package/lib/configs.js +32 -2
- package/lib/divi.js +1 -1
- package/lib/download-sources.js +1 -1
- package/lib/env.js +3 -11
- package/lib/options.js +1 -1
- package/lib/template/assets/css/popover.css +80 -0
- package/lib/template/assets/js/popover.js +30 -0
- package/lib/template/block/edit.js.mustache +48 -0
- package/lib/template/block/editor.scss.mustache +5 -0
- package/lib/template/block/index.js.mustache +40 -0
- package/lib/template/block/save.js.mustache +21 -0
- package/lib/template/block/style.scss.mustache +6 -0
- package/lib/template/index.cjs +48 -0
- package/lib/template/plugin/$slug.php.mustache +135 -0
- package/lib/template/plugin/core/cdec-api.php.mustache +44 -0
- package/lib/template/plugin/core/filters.php.mustache +111 -0
- package/lib/template/plugin/core/functions.php.mustache +25 -0
- package/lib/template/plugin/inc/renderer.php.mustache +25 -0
- package/lib/utils.js +150 -0
- package/lib/wordpress.js +1 -1
- package/package.json +3 -2
- package/lib/docker.js +0 -68
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
|
|
2
|
+
.popover-content {
|
|
3
|
+
position: absolute;
|
|
4
|
+
display: flex;
|
|
5
|
+
flex-direction: column-reverse;
|
|
6
|
+
row-gap: .5rem;
|
|
7
|
+
left: -10000px;
|
|
8
|
+
top: auto;
|
|
9
|
+
width: 1px;
|
|
10
|
+
height: 1px;
|
|
11
|
+
background-color: white;
|
|
12
|
+
padding: 1rem;
|
|
13
|
+
z-index: 100;
|
|
14
|
+
outline: 0;
|
|
15
|
+
border-radius: .5rem;
|
|
16
|
+
overflow: visible;
|
|
17
|
+
pointer-events: none;
|
|
18
|
+
--shadow-color: 220 3% 15%;
|
|
19
|
+
--shadow-strength: 1%;
|
|
20
|
+
box-shadow: 5px 7px 15px grey;
|
|
21
|
+
}
|
|
22
|
+
.popover-content:focus {
|
|
23
|
+
outline: 2px solid var(--highlight-color, #fec02f);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.popover-container {
|
|
27
|
+
position: relative;
|
|
28
|
+
width: fit-content;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.popover-content::before {
|
|
32
|
+
content: '';
|
|
33
|
+
position: absolute;
|
|
34
|
+
width: 1rem;
|
|
35
|
+
height: 1rem;
|
|
36
|
+
left: 0;
|
|
37
|
+
top: 50%;
|
|
38
|
+
background-color: white;
|
|
39
|
+
transform: translate(-50%, -50%) rotate(45deg);
|
|
40
|
+
}
|
|
41
|
+
.popover-revealed {
|
|
42
|
+
width: max-content;
|
|
43
|
+
height: max-content;
|
|
44
|
+
left: var(--x);
|
|
45
|
+
top: var(--y);
|
|
46
|
+
transform: translateY(-50%);
|
|
47
|
+
}
|
|
48
|
+
@media screen and (max-width: 950px) {
|
|
49
|
+
.popover-content::before {
|
|
50
|
+
content: none;
|
|
51
|
+
}
|
|
52
|
+
.popover-revealed {
|
|
53
|
+
left: calc(50% + var(--x-offset-m, 0%));
|
|
54
|
+
transform: translate(-50%, 0);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.popover-legend {
|
|
59
|
+
display: flex;
|
|
60
|
+
flex-direction: row;
|
|
61
|
+
gap: .75rem;
|
|
62
|
+
align-items: flex-start;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.popover-legend svg {
|
|
66
|
+
height: 1.5em;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.popover-revealed p {
|
|
70
|
+
font-weight: 400;
|
|
71
|
+
font-size: 1em;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.popover-header {
|
|
75
|
+
margin: 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.popover-stat {
|
|
79
|
+
margin: 0 0 .5rem 0;
|
|
80
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
jQuery( document ).ready( function ( $ ) { // eslint-disable-line
|
|
2
|
+
$( document ).on( 'mouseover', '.popover', function ( ele ) {
|
|
3
|
+
togglePopover( ele.currentTarget.id );
|
|
4
|
+
} );
|
|
5
|
+
|
|
6
|
+
$( document ).on( 'mouseout', '.popover', function ( ele ) {
|
|
7
|
+
togglePopover( ele.currentTarget.id, false );
|
|
8
|
+
} );
|
|
9
|
+
|
|
10
|
+
function togglePopover( id, popin = true ) {
|
|
11
|
+
if ( undefined !== id ) {
|
|
12
|
+
const current = $( '#' + id );
|
|
13
|
+
const popver = $( '#' + id + '-popover' );
|
|
14
|
+
|
|
15
|
+
if ( popin ) {
|
|
16
|
+
current.addClass( 'highlighted' );
|
|
17
|
+
|
|
18
|
+
if ( undefined !== popver ) {
|
|
19
|
+
$( popver ).addClass( 'popover-revealed' );
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
22
|
+
current.removeClass( 'highlighted' );
|
|
23
|
+
|
|
24
|
+
if ( undefined !== popver ) {
|
|
25
|
+
$( popver ).removeClass( 'popover-revealed' );
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
} );
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieves the translation of text.
|
|
3
|
+
*
|
|
4
|
+
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-i18n/
|
|
5
|
+
*/
|
|
6
|
+
import { __ } from '@wordpress/i18n';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* React hook that is used to mark the block wrapper element.
|
|
10
|
+
* It provides all the necessary props like the class name.
|
|
11
|
+
*
|
|
12
|
+
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/
|
|
13
|
+
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops
|
|
14
|
+
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#richtext
|
|
15
|
+
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#innerblocks
|
|
16
|
+
*/
|
|
17
|
+
import { useBlockProps, RichText, InnerBlocks } from '@wordpress/block-editor';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files.
|
|
21
|
+
* Those files can contain any CSS code that gets applied to the editor.
|
|
22
|
+
*
|
|
23
|
+
* @see https://www.npmjs.com/package/@wordpress/scripts#using-css
|
|
24
|
+
*/
|
|
25
|
+
import './editor.scss';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The edit function describes the structure of your block in the context of the
|
|
29
|
+
* editor. This represents what the editor will render when the block is used.
|
|
30
|
+
*
|
|
31
|
+
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#edit
|
|
32
|
+
*
|
|
33
|
+
* @return {WPElement} Element to render.
|
|
34
|
+
*/
|
|
35
|
+
export default function Edit(props) {
|
|
36
|
+
let {
|
|
37
|
+
setAttributes,
|
|
38
|
+
attributes: {}
|
|
39
|
+
} = props;
|
|
40
|
+
|
|
41
|
+
const blockProps = useBlockProps();
|
|
42
|
+
|
|
43
|
+
return(
|
|
44
|
+
<div {...blockProps}>
|
|
45
|
+
<p>Render Block Output</p>
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registers a new block provided a unique name and an object defining its behavior.
|
|
3
|
+
*
|
|
4
|
+
* @see https://developer.wordpress.org/block-editor/developers/block-api/#registering-a-block
|
|
5
|
+
*/
|
|
6
|
+
import { registerBlockType } from '@wordpress/blocks';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files.
|
|
10
|
+
* All files containing `style` keyword are bundled together. The code used
|
|
11
|
+
* gets applied both to the front of your site and to the editor. All other files
|
|
12
|
+
* get applied to the editor only.
|
|
13
|
+
*
|
|
14
|
+
* @see https://www.npmjs.com/package/@wordpress/scripts#using-css
|
|
15
|
+
*/
|
|
16
|
+
import './style.scss';
|
|
17
|
+
import './editor.scss';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Internal dependencies
|
|
21
|
+
*/
|
|
22
|
+
import Edit from './edit';
|
|
23
|
+
import save from './save';
|
|
24
|
+
import metadata from './block.json';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Every block starts by registering a new block type definition.
|
|
28
|
+
*
|
|
29
|
+
* @see https://developer.wordpress.org/block-editor/developers/block-api/#registering-a-block
|
|
30
|
+
*/
|
|
31
|
+
registerBlockType( metadata.name, {
|
|
32
|
+
/**
|
|
33
|
+
* @see ./edit.js
|
|
34
|
+
*/
|
|
35
|
+
edit: Edit,
|
|
36
|
+
/**
|
|
37
|
+
* @see ./save.js
|
|
38
|
+
*/
|
|
39
|
+
save,
|
|
40
|
+
} );
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React hook that is used to mark the block wrapper element.
|
|
3
|
+
* It provides all the necessary props like the class name.
|
|
4
|
+
*
|
|
5
|
+
* @see https://developer.wordpress.org/block-editor/packages/packages-block-editor/#useBlockProps
|
|
6
|
+
*/
|
|
7
|
+
import { InnerBlocks } from '@wordpress/block-editor';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The save function defines the way in which the different attributes should
|
|
11
|
+
* be combined into the final markup, which is then serialized by the block
|
|
12
|
+
* editor into `post_content`.
|
|
13
|
+
*
|
|
14
|
+
* @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#save
|
|
15
|
+
*
|
|
16
|
+
* @return {WPElement} Element to render.
|
|
17
|
+
*/
|
|
18
|
+
export default function save(props) {
|
|
19
|
+
return <InnerBlocks.Content />;
|
|
20
|
+
}
|
|
21
|
+
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
const { join } = require( 'path' );
|
|
5
|
+
const { capitalCase } = require( 'change-case' );
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
const blockSlug = process.argv[ 2 ];
|
|
11
|
+
const blockSlugTitle = capitalCase( blockSlug );
|
|
12
|
+
|
|
13
|
+
const customScripts = {};
|
|
14
|
+
|
|
15
|
+
const npmDependencies = [
|
|
16
|
+
'@wordpress/icons@9.22.0'
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
const npmDevDependencies = [];
|
|
20
|
+
|
|
21
|
+
// assetsPath: join( __dirname, 'assets' ),
|
|
22
|
+
module.exports = {
|
|
23
|
+
pluginTemplatesPath: join( __dirname, 'plugin' ),
|
|
24
|
+
blockTemplatesPath: join( __dirname, 'block' ),
|
|
25
|
+
defaultValues: {
|
|
26
|
+
pluginURI: `https://github.com/CAWebPublishing/${ blockSlug }`,
|
|
27
|
+
plugin: true,
|
|
28
|
+
description: `${ blockSlugTitle } Gutenberg Block`,
|
|
29
|
+
version: '1.2.0',
|
|
30
|
+
author: 'CAWebPublishing',
|
|
31
|
+
license: 'GPL-2.0-or-later',
|
|
32
|
+
licenseURI: 'https://www.gnu.org/licenses/gpl-2.0.html',
|
|
33
|
+
namespace: 'caweb',
|
|
34
|
+
category: 'cagov-design-system',
|
|
35
|
+
textdomain: 'cagov-design-system',
|
|
36
|
+
dashicon: 'format-aside',
|
|
37
|
+
supports: {
|
|
38
|
+
html: true,
|
|
39
|
+
},
|
|
40
|
+
attributes: {},
|
|
41
|
+
example: {
|
|
42
|
+
attributes: {}
|
|
43
|
+
},
|
|
44
|
+
customScripts: customScripts,
|
|
45
|
+
npmDependencies: npmDependencies,
|
|
46
|
+
npmDevDependencies: npmDevDependencies,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* Plugin Name: {{title}}
|
|
4
|
+
{{#pluginURI}}
|
|
5
|
+
* Plugin URI: {{{pluginURI}}}
|
|
6
|
+
{{/pluginURI}}
|
|
7
|
+
{{#description}}
|
|
8
|
+
* Description: {{description}}
|
|
9
|
+
{{/description}}
|
|
10
|
+
* Version: {{version}}
|
|
11
|
+
* Requires at least: 6.2
|
|
12
|
+
* Requires PHP: 8.1
|
|
13
|
+
{{#author}}
|
|
14
|
+
* Author: {{author}}
|
|
15
|
+
{{/author}}
|
|
16
|
+
{{#license}}
|
|
17
|
+
* License: {{license}}
|
|
18
|
+
{{/license}}
|
|
19
|
+
{{#licenseURI}}
|
|
20
|
+
* License URI: {{{licenseURI}}}
|
|
21
|
+
{{/licenseURI}}
|
|
22
|
+
* Text Domain: {{textdomain}}
|
|
23
|
+
{{#domainPath}}
|
|
24
|
+
* Domain Path: {{{domainPath}}}
|
|
25
|
+
{{/domainPath}}
|
|
26
|
+
{{#updateURI}}
|
|
27
|
+
* Update URI: {{{updateURI}}}
|
|
28
|
+
{{/updateURI}}
|
|
29
|
+
*
|
|
30
|
+
* @package cagov-design-system
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
if ( ! defined('{{slugPascalCase}}_URI') ){
|
|
34
|
+
$cagov_design_system_{{slugSnakeCase}}_doc_root = isset( $_SERVER['DOCUMENT_ROOT'] ) ? sanitize_text_field( wp_unslash( $_SERVER['DOCUMENT_ROOT'] ) ) : '';
|
|
35
|
+
define( '{{slugPascalCase}}_URI', esc_url( str_replace( $cagov_design_system_{{slugSnakeCase}}_doc_root, '', __DIR__ ) ) );
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if ( ! defined( 'CAGOV_DESIGN_SYSTEM_DEBUG' ) ) {
|
|
39
|
+
define( 'CAGOV_DESIGN_SYSTEM_DEBUG', false );
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Include {{title}} Core Functionality.
|
|
43
|
+
foreach ( glob( __DIR__ . '/core/*.php' ) as $file ) {
|
|
44
|
+
require_once $file;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Include {{title}} Functionality.
|
|
48
|
+
foreach ( glob( __DIR__ . '/inc/*.php' ) as $file ) {
|
|
49
|
+
require_once $file;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Plugin API/Action Reference
|
|
54
|
+
* Actions Run During a Typical Request
|
|
55
|
+
*
|
|
56
|
+
* @link https://codex.wordpress.org/Plugin_API/Action_Reference#Actions_Run_During_a_Typical_Request
|
|
57
|
+
*/
|
|
58
|
+
add_action( 'init', 'cagov_design_system_{{slugSnakeCase}}_init' );
|
|
59
|
+
add_action( 'wp_enqueue_scripts', 'cagov_design_system_{{slugSnakeCase}}_wp_enqueue_scripts' );
|
|
60
|
+
|
|
61
|
+
if ( ! function_exists( 'cagov_design_system_{{slugSnakeCase}}_init' ) ) {
|
|
62
|
+
/**
|
|
63
|
+
* {{title}} Initialization
|
|
64
|
+
*
|
|
65
|
+
* Fires after WordPress has finished loading but before any headers are sent.
|
|
66
|
+
* Include Gutenberg Block assets by getting the index file of each block build file.
|
|
67
|
+
*
|
|
68
|
+
* @link https://developer.wordpress.org/reference/hooks/init/
|
|
69
|
+
* @return void
|
|
70
|
+
*/
|
|
71
|
+
function cagov_design_system_{{slugSnakeCase}}_init() {
|
|
72
|
+
global $pagenow;
|
|
73
|
+
|
|
74
|
+
if ( ! function_exists( 'get_plugin_data' ) ) {
|
|
75
|
+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
$version = get_plugin_data( __FILE__ )['Version'];
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Enqueues the default ThickBox js and css. (if not on the login page or customizer page)
|
|
82
|
+
*
|
|
83
|
+
* @link https://developer.wordpress.org/reference/functions/add_thickbox/
|
|
84
|
+
*/
|
|
85
|
+
if ( ! in_array( $pagenow, array( 'wp-login.php', 'customize.php' ), true ) ) {
|
|
86
|
+
add_thickbox();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// if editing a page/post register compiled Gutenberg Block bundles.
|
|
90
|
+
if ( in_array( $pagenow, array( 'post.php', 'post-new.php' ), true ) ) {
|
|
91
|
+
|
|
92
|
+
wp_enqueue_style( 'cagov-design-system-{{slug}}', cagov_design_system_{{slugSnakeCase}}_get_min_file( '/css/{{slug}}.css' ), array(), $version );
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
$block_args = array(
|
|
96
|
+
'render_callback' => 'cagov_design_system_{{slugSnakeCase}}_block_renderer',
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Registers the block using the metadata loaded from the `block.json` file.
|
|
101
|
+
* Behind the scenes, it registers also all assets so they can be enqueued
|
|
102
|
+
* through the block editor in the corresponding context.
|
|
103
|
+
*
|
|
104
|
+
* @see https://developer.wordpress.org/reference/functions/register_block_type/
|
|
105
|
+
*/
|
|
106
|
+
register_block_type( __DIR__ . '/build', $block_args );
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if ( ! function_exists( 'cagov_design_system_{{slugSnakeCase}}_wp_enqueue_scripts' ) ) {
|
|
111
|
+
/**
|
|
112
|
+
* Register {{title}} scripts/styles
|
|
113
|
+
*
|
|
114
|
+
* Fires when scripts and styles are enqueued.
|
|
115
|
+
*
|
|
116
|
+
* @category add_action( 'wp_enqueue_scripts', 'cagov_design_system_{{slugSnakeCase}}_wp_enqueue_scripts' );
|
|
117
|
+
* @link https://developer.wordpress.org/reference/hooks/wp_enqueue_scripts/
|
|
118
|
+
*
|
|
119
|
+
* @return void
|
|
120
|
+
*/
|
|
121
|
+
function cagov_design_system_{{slugSnakeCase}}_wp_enqueue_scripts() {
|
|
122
|
+
|
|
123
|
+
if ( ! function_exists( 'get_plugin_data' ) ) {
|
|
124
|
+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
$version = get_plugin_data( __FILE__ )['Version'];
|
|
128
|
+
|
|
129
|
+
// Register compiled Gutenberg Block bundles.
|
|
130
|
+
wp_enqueue_script( 'cagov-design-system-{{slug}}', cagov_design_system_{{slugSnakeCase}}_get_min_file( '/js/{{slug}}.js', 'js' ), array(), $version, true );
|
|
131
|
+
|
|
132
|
+
wp_enqueue_style( 'cagov-design-system-{{slug}}', cagov_design_system_{{slugSnakeCase}}_get_min_file( '/css/{{slug}}.css' ), array(), $version );
|
|
133
|
+
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* {{title}} CDEC REST API
|
|
4
|
+
*
|
|
5
|
+
* @see https://cdec.water.ca.gov/resapp/
|
|
6
|
+
*
|
|
7
|
+
* @package cagov-design-system
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
if ( ! function_exists( 'cagov_design_system_cdec_reservoir_conditions_api' ) ) {
|
|
11
|
+
/**
|
|
12
|
+
* Retrieve data from the CDEC Reservoir API
|
|
13
|
+
*
|
|
14
|
+
* @see https://cdec.water.ca.gov/resapp/service/res/conditions
|
|
15
|
+
* @param string $station_id Major reservoirs station that were recommended by CDEC.
|
|
16
|
+
* @return string
|
|
17
|
+
*/
|
|
18
|
+
function cagov_design_system_cdec_reservoir_conditions_api( $station_id = '' ) {
|
|
19
|
+
$result = 'No Results';
|
|
20
|
+
|
|
21
|
+
if ( empty( $station_id ) ) {
|
|
22
|
+
return $result;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
$date = gmdate( 'Y-m-d' );
|
|
26
|
+
|
|
27
|
+
$url = "https://cdec.water.ca.gov/resapp/service/res/conditions?date=$date&stationIds=$station_id";
|
|
28
|
+
|
|
29
|
+
$args = array(
|
|
30
|
+
'headers' => array(
|
|
31
|
+
'Content-Type' => 'application/json',
|
|
32
|
+
),
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
$response = wp_remote_get( $url, $args );
|
|
36
|
+
|
|
37
|
+
if ( 200 === wp_remote_retrieve_response_code( $response ) ) {
|
|
38
|
+
$result = wp_remote_retrieve_body( $response );
|
|
39
|
+
|
|
40
|
+
return json_decode( $result, true )[0];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* {{title}} Filters
|
|
4
|
+
*
|
|
5
|
+
* @package cagov-design-system
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
global $wp_version;
|
|
9
|
+
|
|
10
|
+
$cagov_design_system_is_under_5_8 = version_compare( $wp_version, '5.8', '<' ) ? '' : '_all';
|
|
11
|
+
|
|
12
|
+
add_filter( "block_categories$cagov_design_system_is_under_5_8", 'cagov_design_system_block_categories', 10, 2 );
|
|
13
|
+
add_filter( 'script_loader_tag', 'cagov_design_system_{{slugSnakeCase}}_script_loader_tag', 10, 3 );
|
|
14
|
+
add_filter( "allowed_block_types$cagov_design_system_is_under_5_8", 'cagov_design_system_allowed_block_types' );
|
|
15
|
+
|
|
16
|
+
if ( ! function_exists( 'cagov_design_system_block_categories' ) ) {
|
|
17
|
+
/**
|
|
18
|
+
* Register {{title}} Gutenberg Block categories to the Block editor
|
|
19
|
+
*
|
|
20
|
+
* @link https://developer.wordpress.org/reference/hooks/block_categories_all/
|
|
21
|
+
*
|
|
22
|
+
* @param array $categories Array of categories for block types.
|
|
23
|
+
* @param WP_Block_Editor_Context $post The current block editor context.
|
|
24
|
+
* @return array
|
|
25
|
+
*/
|
|
26
|
+
function cagov_design_system_block_categories( $categories, $post ) {
|
|
27
|
+
return array_merge(
|
|
28
|
+
array(
|
|
29
|
+
array(
|
|
30
|
+
'slug' => 'cagov-design-system',
|
|
31
|
+
'title' => 'CA Design System',
|
|
32
|
+
),
|
|
33
|
+
),
|
|
34
|
+
array(
|
|
35
|
+
array(
|
|
36
|
+
'slug' => 'cagov-data-viz',
|
|
37
|
+
'title' => 'CA Data Visualization',
|
|
38
|
+
),
|
|
39
|
+
),
|
|
40
|
+
$categories
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if ( ! function_exists( 'cagov_design_system_allowed_block_types' ) ) {
|
|
46
|
+
/**
|
|
47
|
+
* {{title}} Allowed Block Types
|
|
48
|
+
*
|
|
49
|
+
* Removes all blocks or patterns from Gutenberg and returns {{title}} Blocks.
|
|
50
|
+
*
|
|
51
|
+
* @link https://developer.wordpress.org/reference/hooks/allowed_block_types_all/
|
|
52
|
+
*
|
|
53
|
+
* @param bool|array $allowed_blocks Array of block type slugs, or boolean to enable/disable all. Default true (all registered block types supported).
|
|
54
|
+
* @return array
|
|
55
|
+
*/
|
|
56
|
+
function cagov_design_system_allowed_block_types( $allowed_blocks ) {
|
|
57
|
+
|
|
58
|
+
// if not debugging, return all blocks.
|
|
59
|
+
if ( ! CAGOV_DESIGN_SYSTEM_DEBUG ) {
|
|
60
|
+
return $allowed_blocks;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
remove_theme_support( 'core-block-patterns' );
|
|
64
|
+
|
|
65
|
+
// Core Components.
|
|
66
|
+
$core = array(
|
|
67
|
+
'core/image',
|
|
68
|
+
'core/paragraph',
|
|
69
|
+
'core/button',
|
|
70
|
+
'core/table',
|
|
71
|
+
'core/heading',
|
|
72
|
+
'core/list',
|
|
73
|
+
'core/custom-html',
|
|
74
|
+
'core/classic',
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
// Dynamically get a list of the cagov-design-system blocks.
|
|
78
|
+
$cagov_blocks = array();
|
|
79
|
+
/*
|
|
80
|
+
array_map(
|
|
81
|
+
function( $b ) {
|
|
82
|
+
return 'cagov-design-system/' . basename( $b );
|
|
83
|
+
},
|
|
84
|
+
glob( '/blocks/*' )
|
|
85
|
+
);
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
// Return the desired components.
|
|
89
|
+
return array_merge( $core, $cagov_blocks );
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if ( ! function_exists( 'cagov_design_system_{{slugSnakeCase}}_script_loader_tag' ) ) {
|
|
94
|
+
/**
|
|
95
|
+
* Filters the HTML script tag of an enqueued script.
|
|
96
|
+
*
|
|
97
|
+
* @param mixed $tag The <script> tag for the enqueued script.
|
|
98
|
+
* @param mixed $handle The script's registered handle.
|
|
99
|
+
* @param mixed $src The script's source URL.
|
|
100
|
+
* @return string
|
|
101
|
+
*/
|
|
102
|
+
function cagov_design_system_{{slugSnakeCase}}_script_loader_tag( $tag, $handle, $src ) {
|
|
103
|
+
// Register script as module.
|
|
104
|
+
if ( 'cagov-design-system-{{slug}}' === $handle ) {
|
|
105
|
+
$tag = sprintf( '<script type="module" id="cagov-design-system-{{slug}}-js" src="%1$s"></script>', $src );
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return $tag;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* {{title}} Helper Functions
|
|
4
|
+
*
|
|
5
|
+
* @package cagov-design-system
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
if ( ! function_exists( 'cagov_design_system_{{slugSnakeCase}}_get_min_file' ) ) {
|
|
9
|
+
/**
|
|
10
|
+
* Load Minified Version of a file
|
|
11
|
+
*
|
|
12
|
+
* @param string $f File to load.
|
|
13
|
+
* @param string $ext Extension of file, default css.
|
|
14
|
+
*
|
|
15
|
+
* @return string
|
|
16
|
+
*/
|
|
17
|
+
function cagov_design_system_{{slugSnakeCase}}_get_min_file( $f, $ext = 'css' ) {
|
|
18
|
+
// if not debugging and a minified version exists load it.
|
|
19
|
+
if ( ! CAGOV_DESIGN_SYSTEM_DEBUG && file_exists( __DIR__ . str_replace( ".$ext", ".min.$ext", $f ) ) ) {
|
|
20
|
+
return {{slugPascalCase}}_URI . str_replace( ".$ext", ".min.$ext", $f );
|
|
21
|
+
} else {
|
|
22
|
+
return {{slugPascalCase}}_URI . $f;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* {{title}} Dynamic Renderer Functions
|
|
4
|
+
*
|
|
5
|
+
* @package {{namespace}}
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
if ( ! function_exists( 'cagov_design_system_{{slugSnakeCase}}_block_renderer' ) ) {
|
|
9
|
+
/**
|
|
10
|
+
* Dynamic Renderer for {{title}} Block
|
|
11
|
+
*
|
|
12
|
+
* @see https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/creating-dynamic-blocks/
|
|
13
|
+
*
|
|
14
|
+
* @param array $attributes Block attributes.
|
|
15
|
+
* @param string $content Block content.
|
|
16
|
+
* @param WP_Block_Type $block Current Block Type.
|
|
17
|
+
* @return string Rendered block type output.
|
|
18
|
+
*/
|
|
19
|
+
function cagov_design_system_{{slugSnakeCase}}_block_renderer( $attributes, $content, $block ) {
|
|
20
|
+
|
|
21
|
+
$output = sprintf( '<p>Render Block Output</p>' );
|
|
22
|
+
|
|
23
|
+
return $output;
|
|
24
|
+
}
|
|
25
|
+
}
|