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

Composer dependencies in plugins #32

Closed
maximkou opened this issue Aug 25, 2014 · 2 comments
Closed

Composer dependencies in plugins #32

maximkou opened this issue Aug 25, 2014 · 2 comments
Labels

Comments

@maximkou
Copy link

If I right understand, grav install only can clone plugin from git repos. But now many projects use composer for managing dependencies and autoloading.

I think, must be provided some functionality, which run setup commands for plugins, e.g. composer install.

Thanks.

@rhukster
Copy link
Member

Grav itself uses composer for it's supporting libraries that are stored in vendor. Currently we are stripping out extra folders (tests, examples, non-essential files) and actually pushing these into the Grav repo itself.

We did this because originally we had planned on using *git subtrees so that the Grav repo could be 100% self contained. I.e. you could clone it and it would have everything including libraries, theme, essential plugins etc. Unfortunately subtrees in their current state proved troublesome when working with gitflow, and we quickly abandoned that plan. To get around this issue, we decided to just have a simple CLI command install that any user could run even if they didn't have composer. This just makes a local call to git to clone the dependencies. We considered using composer here, but it's definitely more complicated. Each of our repos would have to be a composer package, and the user would have to have working copy of composer. This is not something we've ruled out, we just pushed it back to look at again a bit further down the road.

The question you actually asked is a bit tricker. A plugin is an optional install, also it needs to be self-contained. That is, you should be able to drop it into a Grav site, and with just minimal configuration perhaps, it should work. A unified composer really doesn't play well with this type of functionality. To get composer to add a library needed for a plugin, you would need to add that library to the composer.json then run composer update. Not something an average user would want to do.

What we have done in a couple of our plugins, is actually have the plugin have it's own composer.json that during development, was used to install any vendor libraries, and also provide an autoload. These then become part of the plugin itself, and are pushed to the plugin repo.

Alternatively you could leave all the composer vendor folders out of the repo, just commit the composer.json and create a bulild script to make your 100% self contained zip packages that are intended for distribution. This is probably the route we will go with for Grav in GitHub in the near future.

Hope that helps...

@bobrocke
Copy link

rhukster,

Thanks for the perspective. It is interesting to watch a new product being developed and to have some view of the inner workings behind the design decisions. Thanks for making this project so open.

Bob

hamiltont added a commit to hamiltont/grav-plugin-shortcode-chartjs that referenced this issue Jan 25, 2019
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants