forked from CPPL/grav-plugin-shortcode-chartjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow chart data inside shortcode with YAML format
This commit enables the following approach [chartjs] type: bar data: labels: [Jan, Feb, Mar] datasets: - label: Bars Other Title data: [1,2,4] [/chartjs] Significant limitation of this approach is that it (currently) requires disabling all Markdown processing on the page to work. Would need some raw page processing to fix this, see the TODO in the source code. It does at least try to detect and warn you off if you try this approach without disabling md processing. Huge benefit is that the strings used map 1-1 to the Chart.js library, so any Chart.js parameters/datasets/options can be utilized. Also, folks can directly reference the Chart.js documentation, no need to read the readme for this plugin to understand how the options here map to chart.js options In order to convert YAML to JSON (faithfully) you need a proper YAML parser. Rather than asking folks to install a PECL extension, I went with the battle-tested Symphony YAML parser. The license is MIT, so it should not conflict with this plugin’s license. I chose to follow the format used in multiple other plugins (and kind of documented at getgrav/grav#32 ) of embedding the composer “vendor” folder directly into the git repo. Not what you typically do, but apparently that is the grav way. I thought I would find a native YAML parser inside Grav (and it’s probably there somewhere) but I gave up after a bit of looking and pulled in one I trusted. My thoughts on using YAML (instead of JSON) inside the shortcode - A shortcode is intended to allow for both quick writing and quick reading. IMO using raw JSON as the contents would have worsened both the quick-writing and quick-reading nature of this shortcode extension. As YAML is a pure superset of JSON, any JSON data can be faithfully reproduced using YAML. If a user has any desire at all to go to raw JSON, they can always paste that JSON directly into the markdown and bypass the shortcode mechanism entirely. IMO the only negative of the YAML is that it makes it harder to copy/paste chart examples into grav using this plugin, but I hope to address that by adding some other functionality later.
- Loading branch information
Showing
72 changed files
with
11,311 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Usage | ||
|
||
This page has some new usage examples. | ||
|
||
## Data Flow | ||
|
||
Document the order in which data sources are scanned... | ||
|
||
|
||
## Data Inside Shortcode | ||
|
||
To use this approach, you must disable `process.markdown` inside your frontmatter. | ||
If you do not, then the YAML inside the `chartjs` shortcode will be processed by | ||
the Markdown formatter, and the plugin will fail to properly process it. | ||
|
||
```` | ||
[chartjs] | ||
type: bar | ||
data: | ||
labels: [Jan, Feb, Mar, Apr] | ||
datasets: | ||
- label: Bars Other Title | ||
data: [1,2,4,7] | ||
[/chartjs] | ||
```` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"require": { | ||
"symfony/yaml": "4.2.*" | ||
}, | ||
"config": { | ||
"optimize-autoloader": true | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
// autoload.php @generated by Composer | ||
|
||
require_once __DIR__ . '/composer/autoload_real.php'; | ||
|
||
return ComposerAutoloaderInitb7b7515bd2f76b476ec219ccf4044334::getLoader(); |
Oops, something went wrong.