Dynamic including/autoload of external TypoScript templates - dynamic

Is it possible to include automatically all external TS templates in some folders to avoid manual linking ?
Instead of writing each time manually INCLUDE_TYPOSCRIPT like this :
Constants :
<INCLUDE_TYPOSCRIPT: source="FILE:fileadmin/templates/typoscript/setup/1.ts">
<INCLUDE_TYPOSCRIPT: source="FILE:fileadmin/templates/typoscript/setup/2.ts">
...
<INCLUDE_TYPOSCRIPT: source="FILE:fileadmin/templates/typoscript/setup/999.ts">
Setup :
<INCLUDE_TYPOSCRIPT: source="FILE:fileadmin/templates/typoscript/constants/1.ts">
<INCLUDE_TYPOSCRIPT: source="FILE:fileadmin/templates/typoscript/constants/2.ts">
...
<INCLUDE_TYPOSCRIPT: source="FILE:fileadmin/templates/typoscript/constants/999.ts">
I would like to have something like this instead of manual include file per file :
Constants :
<INCLUDE_TYPOSCRIPT_ALL: source="FILE:fileadmin/templates/typoscript/constants/">
Setup :
<INCLUDE_TYPOSCRIPT_ALL: source="FILE:fileadmin/templates/typoscript/setup/">
Recursive option could be helpful also.
Is it possible, or I need to hack the core to realize such functionality ?

The only way is including sub-files in one main file. It's similar approach like using #import in CSS files for including other substyles.
Then you can just include one file in your TS:
<INCLUDE_TYPOSCRIPT: source="FILE:fileadmin/templates/typoscript/setup/main.ts">
and at the main.ts you can paste additional includes

Related

Define variables per folder in dbt

I'm trying to have a structure to run a dbt project, where I have multiple entities (bank, names, cars). I'm going to have exactly the same code for them all.
Based on that, I'm trying to have several folder with the same code, where I can define inside the dbt_project.yamlfile. The idea is something like this:
vars:
db_name: 'db_official'
staging:
bank: 'variable_bank'
car: 'variable_car'
name: 'variable_name'
The variable "db_name" works. So, my the two problems I'm having are:
How to have this structure inside the the yaml file?
How to reference this structure inside each file?
(extra) Any other ideas how to handle this?
Thanks!
vars are basically globals. They can be scoped to your whole project, or to a package within your project, but not more specifically than that (they share a flat namespace). See the docs.
I would pull out the common code into a macro, then call that macro from each model file, passing in the unique values as string literals in the model file:
-- models/staging/bank.sql
{{ my_model_template('variable_bank') }}
-- models/staging/car.sql
{{ my_model_template('variable_car') }}

Merge styles - How to use vendor prefixes

I'm using this library #uifabric/merge-styles from office-ui-fabric. My question is how to use vendor prefixes inside mergeStyleSets?
Example -webkit-filter:
import { mergeStyleSets } from '#uifabric/merge-styles'
mergeStyleSets({
webkitFilter: 'blur(5px)', // Error! No Typescript definition.
})
Is there any other way to achieve this?
Merge Styles Library
It looks like there is no Typescript definitions for it
IRawStyleBase.ts
Addition to #Vitalie Braga answer:
This is temporary solution if you are using Typescript project:
const foo = mergeStyleSets({
root: [
{
backgroundColor: '#f00',
...({ '-webkit-filter': 'blur(5px)' } as any)
},
]
})
Issues Page - Git OFFICE UI FABRIC
#uifabric/merge-styles library has smarts about automatic vendor prefixing for you but the only issue with that is that the rules that are auto-prefixed today are limited to just one: user-select. I would advise you go and submit an issue in their github repo here and either ask if new rules can be added or ask how to handle this situation.
From a deeper investigation looks like they have some vendor specific support but is very limited in IRawStyleBase.ts. Those rules will automatically be transformed into vendor rules.
So to answer your questions if you are using a TS project there is no way you can specify something that is not compatible with the IRawStyleBase interface but if you are using a js script you can probably try your luck as I did in this code-sandbox and it looks like the filter get's through but nothing else.

Accessing custom jbake confing properties in asciidoc

After some time I spent staring at the jbake code, I figured out that if I declare my own property in jbake.properties :
...
foo=bar
...
I can reuse that in files that go through a template engine by referencing it as ${config.foo}. I'd like to have this substitution working also on the content lvl, i.e. for files written in asciidoc, living inside the content directory.
Is there any non-trivial way to achieve it? How can I make the templating engine to proccess the result of asciidoc parses engine, or make it running it before the asciidoctor?
I found the answer myself.
To use the property substitution in asciidoc files, add following to the jbake.properties:
...
asciidoctor.attributes.export=true
foo=world
...
and reference the variable in aFile.adoc this way:
Hello {foo}!

Loop through files in a directory or a list

I am trying to generate multiple CSS classes for a single .css file to be used by the body element of a page to change the page's entire color scheme.
I have a folder of .less files containing variables #base00 to #base0F for their specific color scheme (https://github.com/AndrewBelt/hack.chat/tree/master/client/base16) and would like to import each of these files for each CSS class name.
Here's some psuedocode to achieve what I need.
// This syntax does not exist in LESS
for each #scheme in ./base16/ {
#import "#scheme"
body.#{scheme} {
background: #base00;
color: #base07;
}
...
}
I might have to think outside of the box for this one, like creating a Makefile to build by replacing variable by command line and concatenate each .css file generated by LESS to a single master .css file. But perhaps there is a more elegant way using pure LESS.
No, there's no built-in file system functions/features Less. (It's designed to work in several environments and some of those do not even permit "directory sniffing"). If necessary one can write a plugin to provide such functionality, but I suppose in this case it would be more easy to do this externally.
Compiling and concatenating multiple files is not necessary the simplest method. For example you can simply generate Less file that imports all schemes and applies each to a main template, e.g. just a list of:
.scheme-name {
#import "scheme-name";
#import (multiple) "scheme-styles-template";
}
statements. Where scheme-styles-template is the same as your scheme.less except body to be defined as:
body& {
background: #base00;
color: #base05;
}

Lua - Question on modules

Say I want to make a module for say a set of GUI controls, how would I create a module that would load all of the GUI scripts, and should I put those scripts as modules themselves? I was thinking of having a system like this:
module("bgui", package.seeall)
dofile("modules/bgui/control.lua")
dofile("modules/bgui/container.lua")
dofile("modules/bgui/screenmanager.lua")
dofile("modules/bgui/form.lua")
dofile("modules/bgui/button.lua")
dofile("modules/bgui/textbox.lua")
dofile("modules/bgui/label.lua")
Would all the files run then have the variables they set as part of the bgui module?
Aka if in control.lua I had control = {...} would it be defined as bgui.control or should I make the control.lua a module itself, something like module("bgui.control") would that work as I intend?
Sorry if this isn't very clear had to write it in a rush, thanks :)
You are actually asking two questions here:
First, "is this way of loading lots of files on a module ok?"
The answer is - yes. It is kind of an unspoken standard to call that file mymodule/init.lua. Most people have ?/init.lua included on their path, so you can just write require('modules/bgui') and init.lua will be loaded automatically.
This said, you might want to remove some code duplication by using a temp table and a loop:
# modules/bgui/init.lua
local files = {
'control', 'container', 'screenmanager', 'form', 'button', 'textbox', 'label'
}
for _,file in ipairs(files) do dofile("modules/bgui/" .. file .. ".lua") end
Second, "are objects defined on one file available on bgui?".
The answer is also yes, as long as the file defining the variable is "done" (with dofile or require) before the file using the variable.