Lua - Question on modules - module

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.

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') }}

How to declare module_name in groups Odoo

I used this code in a xml view in ideas_app module:
groups="group_vote_user"
but i got this error "External ID must be fully qualified"
Is it really need module name like groups="ideas_app.group_vote_user" even this view in same module with group_vote_user security (in module ideas_app)?
Is there any ways to not declare module name or change with this.group_vote_user like that?
I think, you need to check sequence of files in manifest file. For example, security.xml should be come first and then others view files.
I am not sure if there is a way to change it. But as per standards, we need to follow standard way like "module_name.xml_ID"

How to apply metadata to all files in a content directory

I have a content directory called foo and I want all files under that directory to have an extra metadata item foovar: default, unless explicitly overridden in the file header. I think I'm supposed to do this with EXTRA_PATH_METADATA, but I can't figure out what incantation it wants.
(for my current use case I'm trying to apply template: sometemplate within this dir, but I'm interested in solving the general case as it would make several related headaches go away)
I think what you're looking for is actually DEFAULT_METADATA. Check out this portion of the documentation:
DEFAULT_METADATA = {}
The default metadata you want to use for all articles and pages.
So, in your case it might look something like this in your config file:
DEFAULT_METADATA = {'foovar': 'default'}
Then to assign your custom template(s), see this portion of the documentation.
This wasn't possible at the time I asked. I've since sent the devs a PR adding support, and it's been merged to master. Presumably it will go out in the next release. It makes EXTRA_PATH_METADATA recursive, so you can apply settings to a subdir like this:
EXTRA_PATH_METADATA = {'dirname/subdir': {'status': 'hidden'}}

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}!

How to allow access to group of generated sub trees in web.config using RegEx?

Here is what I need to do:
In my CodeIgniter application, I have a folder named "modules", and each module contains (among others) a folder named assets, which contains all the resources that need to be available from the browser.
The file structure is in this format:
modules
MyModule
assets
views
etc...
The MyModule folder is dynamic, so I need to add a rule that does not rewrite the paths like
/modules/ANY MATCH/assets
but I can't figure out the proper Regular Expression...
My current pattern is the following:
^(index\.php|robots\.txt|libs|themes|app/modules/^.$/assets|sitemap.xml)
but the ^.$ obviously doesn't work... I'm a complete RegEx noob :/
Any help would be appreciated. Thanks for your time!
I think you want
^(index\.php|robots\.txt|libs|themes|app/modules/.*/assets|sitemap\.xml)
or better, if ANY MATCH is always a single folder only:
^(index\.php|robots\.txt|libs|themes|app/modules/[^/]*/assets|sitemap\.xml)