How can I expose plugin functions to docpad partials? - plugins

tldr; Is there a way to expose functions defined in one plugin for another plugin to use?
I'm trying to use the tagging plugin (https://github.com/rantecki/docpad-plugin-tagging) within a partial.
I have a Jade partial setup as follows:
.post-tags
| Posted in
each tag in tags
a(href=getTagUrl(tag))= tag + ' '
where getTagUrl is a function defined by the tagging plugin. The problem is that the partial has no knowledge and this partial does not render.

As v2.8.0+ of the partials plugin now includes the template data by default (you don't have to manually specify it's inclusion anymore), try running docpad update in your project's root directory and trying again. Otherwise, we'll probably have to see the source code of your project to help isolate the issue.

It's because partial do not have access by default to templateData, the object holding the getTagUrl helper. You have to pass it explicitly to the partial.
Here's a similar answer provided for the eco templating language :
https://stackoverflow.com/a/16631649/232943

Related

Simple API call within the context of DocFx preprocessor

I would like to know if it is possible to make a simple API call (e.g. GitHub API v3) within the context of a DocFx custom template preprocessor. I have been trying all sorts of different approaches, but nothing has fully worked so far.
My goal is to make a call to an API to retrieve some data, and then update the model accordingly to be used in the *.liquid or *.tmpl renderers.
I have tried using the http/https node modules. I have also tried using node-fetch. It results in a docfx build error something like:
Error:Error transforming model ".../index.raw.json" generated from
".../index.md" using "conceptual.html.primary.js". Error running
Transform function inside template preprocessor
According to DocFx documentation, preprocessors follow the ES 5.1 standard. My code conforms to this.
Does anyone know if this is possible?
By the way, I am able to do simple model manipulation just fine, so I understand the basic concepts here with the DocFx preprocessors.
Thanks!
For the benefit of others, I discovered DocFX uses jint which cannot require a Node library directly. Therefore, it appears the plugin route is a better way to go for this use case.

How to access per project / per preset configuration data in vue-cli 3.x?

I'm looking to create a vue-cli 3.x plugin that generates extra files in the project when invoked and templates these based on configuration info entered by the user.
It's rather easy to collect this information from user prompts but it'd be much nicer if users could put this info into some sort of configuration file and have the plugin read it from there.
I understand vue-cli now uses a vue.config.js file on the project level and ~/.vuerc on a more global (preset) level. However, it doesn't look like my generator function would have access to either one of those files.
"The entire preset" should be passed as the third argument to the function when invoking the plugin with module.exports = (api, options, rootOptions) => {} in ./generator/index.js, rootOptions is undefined.
Sililarly, the use of vue.config.js is discussed in the documentation when talking about service plugins, but there's no mention how to use it in a generator function.
Am I missing something obvious here or is there really no officially sanctioned way to do this? Nothing stops me from reading vue.config.js in my function, but this feels hacky. And I wouldn't even know how to find out which preset was used to create the project.
So your problem is that you can't find ~/.vuerc?
I had the same issue and I found the solution here.
The solution is to use the command line
vue config
to see .vuerc, and then use
vue config --delete presets.yourPresetName
to delete your preset.
As well, if you can't type in your preset name in the terminal because it contains a space or an apostrophe, you can use
vue config --edit
to open .vuerc with a text editor and just edit it there

Playframework templates getting started

I'm new to Scala && InteliJ && PlayFramework so i have created template from activator that has generated some play/scala code and templates.
for example one in file views/index.scala.html
#play20.welcome(message, style = "Java")
How can I locate in which package is this template, and see available templates? I tried right click && reference, GoTo -> Declatration but it showed nothing ?
Play comes with some basic template tags you can use, they are all located here:
http://github.com/playframework/playframework/tree/2.5.4/framework/src/play/src/main/scala/views
As you can see #play20.welcome(...) is inside the play20 folder.
You may find the tags inside the helper (for html forms) and defaultpages interesting.
However I would recommend you to read the Play Framework documentation, specially the part about templates: https://www.playframework.com/documentation/2.5.x/JavaTemplates
Throughout the documentation actually all the template tags play comes with will be mentioned somewhere - and how to use them in which cases.
Tip: In case you want to use Bootstrap there is an awesome library for the Play Framework which comes with all Bootstrap related tags you need: https://adrianhurt.github.io/play-bootstrap/

SystemJS - Provide JQuery global object

I have a project which is a mix of new code and old libraries, some of which is based on JQuery and JQuery plugins. I'm facing some issues where some plugins are using the global object ($) to integrate, and other are doing require("jquery") or the equivalent. This appears to be fetching two different instances of JQuery.
Because of some existing code, I need the global object to be there. However, to support my newer code I want anything that requires or imports 'jquery' to be provided the window.jQuery object instead of trying to load an external module.
Can I do this with SystemJS?
Did you try the SystemJS-Adapter-Modules? Create a file jquery.js and reference the globally loaded jQuery function:
module.exports = window.jQuery;
When you import "jquery" you should get a reference to the already loaded jQuery function.
SystemJS-Adapter-Modules

TypoScript: Check if JS/CSS File is already included

anybody knows how to check if a js/css file is already included with typoscript?
Example
[Template_A.ts]
page.includeJS {
jsfile = fileadmin/Template/js/jquery-1.10.2.min.js
}
now if i got an extension with the same include e.g.
[Extension_A.ts]
page.includeJS {
jsfile = fileadmin/Template/js/jquery-1.10.2.min.js
}
Is there a way to prevent this kind of double code injection? Maybe i got another Template e.g. Template_B.ts where jquery is not included - than the Extension_A.ts has to include jquery by itself.
Kinldy
You can use the same key inside includeJS such it just gets overridden if you include the file twice.
Other than that you should put jQuery into includeJSlibs, such that it is loaded before the other JS files.
Other than that, the TS should be unique for each page. Therefore you always to make sure anyway that all resources are included in-order.
You should not include JS libs with the automatic extension TS setups. Use your documentation to tell the integrator what needs to be included and what not.
The various and independent inclusion of scripts by plugins and templates is one of the tricky points in TYPO3. As far as I know, this point cannot be managed at one single point.
There is a plugin "t3jquery" that offers to build, compress and share a common jQuery library. It also has a service to analyze other plugins for their dependencies. But this doesn't solve the problem in general, as many plugins don't check for libraries already loaded.
The most stable way is to remove all plugin's references to libraries manually in your TypoSkript. This gives you some simple additional TypoSkript lines. I use lines like these:
plugin.tx_imagecycle_pi1.file.jQueryLibrary >
plugin.tx_imagecycle_pi1.jQueryLibrary >
plugin.tx_multicontent_pi1.file.jQueryLibrary >
plugin.tx_multicontent_pi1.jQueryLibrary >
# Fluid
page.headerData.998 >
You can find the matching TypoSkript descriptors by searching for the library name in the TypoSkript browser or by greping in the plugin's source code. You will also need this if you wish to add libraries as part of content that was get by AJAX, thus separating the libs from the page content.
Here's a tut (in German): http://jweiland.net/typo3/typoscript/javascript-manuell-entfernen-oder-einbinden.html
Futher possibilities you can check:
Some plugins are written in good structure and offer to keep back their Javascript in the settings.
Some script inclusions may come rather from the static template but from a plugin, so don't forget to have a look there.