CDN

For quick reference when prototyping you can use the CDN package.

To use a CDN class it must be imported.

from domonic.CDN import *

Or just classes you need…

from domonic.CDN import CDN_JS, CDN_CSS

CDN_JS

script(_src=CDN_JS.JQUERY_3_5_1)

CDN_CSS

classless_css = link(_rel="stylesheet", _href=CDN_CSS.WATER_LATEST)

currently constants exist for:

  • BOOTSTRAP_5_ALPHA

  • BOOTSTRAP_4

  • MARX

  • MVP

  • WATER_LATEST

  • BALLOON

  • THREE_DOTS_0_2_0

  • MILLIGRAM_1_3_0

  • X3DOM

  • FONTAWESOME_5_7_1

  • MDI_5_4_55

CDN_IMG

CDN_IMG has a placeholder service.

# to change it. do this...
CDN_IMG.PLACEHOLDER_SERVICE = "placebear.com/g"

img(_src=CDN_IMG.PLACEHOLDER(300,100))

# optional seperator if the site uses x instead of slash between dimensions
img(_src=CDN_IMG.PLACEHOLDER(300,100,'x'))

# there’s tons to pick from. (NOT ALL ARE HTTPS):

domonic.CDN

For quick reference when prototyping you can use the CDN package. (Don’t rely on a CDN package for production code. wget a local copy.)

TODO - integrity/cross origin/module?

class domonic.CDN.CDN_CSS[source]

Preferably use version numbers if available. use LATEST if it always gets the latest

BALLOON: str = 'https://unpkg.com/balloon-css/balloon.min.css'
BOOTSTRAP_4: str = 'https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css'
BOOTSTRAP_5_ALPHA: str = 'https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/js/bootstrap.min.js'
FONTAWESOME_5_7_1: str = 'https://use.fontawesome.com/releases/v5.7.1/css/all.css'
MARX: str = 'https://unpkg.com/marx-css/css/marx.min.css'
MDI_5_4_55: str = 'https://cdn.materialdesignicons.com/5.4.55/css/materialdesignicons.min.css'
MILLIGRAM_1_3_0: str = 'https://cdnjs.cloudflare.com/ajax/libs/milligram/1.3.0/milligram.css'
MVP: str = 'https://unpkg.com/mvp.css'
SIMPLE: str = 'https://cdn.simplecss.org/simple.min.css'
TAILWIND_2_2_15: str = 'https://unpkg.com/tailwindcss@^2.2.15/dist/tailwind.min.css'
THREE_DOTS_0_2_0: str = 'https://cdnjs.cloudflare.com/ajax/libs/three-dots/0.2.0/three-dots.min.css'
WATER_LATEST: str = 'https://cdn.jsdelivr.net/gh/kognise/water.css@latest/water.min.css'
X3DOM: str = 'https://www.x3dom.org/download/x3dom.css'
class domonic.CDN.CDN_IMG[source]

CDN images

static PLACEHOLDER(width: int = 100, height: int = 100, HTTP: str = '', seperator: str = '/') str[source]

to update do CDN_IMG.PLACEHOLDER_SERVICE = “placebear.com/g” usage : img(_src=CDN_IMG.PLACEHOLDER(300,100)) default HTTP is none, to let the browser decide # use optional seperator if the site uses x instead of slash img(_src=CDN_IMG.PLACEHOLDER(300,100,’x’))

class domonic.CDN.CDN_JS[source]

js libs

AFRAME_1_2: str = 'https://aframe.io/releases/1.2.0/aframe.min.js'
BOOTSTRAP_4: str = 'https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js'
BOOTSTRAP_5 = 'https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js'

latest

BOOTSTRAP_5_ALPHA: str = 'https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/js/bootstrap.min.js'
BRYTHON_3_9_5: str = 'https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.5/brython.min.js'
D3: str = 'https://cdnjs.cloudflare.com/ajax/libs/d3/7.4.3/d3.min.js'

latest

D3_6_1_0: str = 'https://cdnjs.cloudflare.com/ajax/libs/d3/6.1.0/d3.min.js'
HTMX: str = 'https://unpkg.com/htmx.org@1.7.0'

latest

JQUERY: str = 'https://code.jquery.com/jquery-3.6.0.min.js'

latest

JQUERY_3_5_1: str = 'https://code.jquery.com/jquery-3.5.1.min.js'
JQUERY_UI: str = 'https://code.jquery.com/ui/1.12.0/jquery-ui.min.js'
MATHML: str = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=MML_HTMLorMML'
MODERNIZER_2_8_3: str = 'https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js'
MOMENT_2_27_0: str = 'https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.27.0/moment.min.js'
PIXI_5_3_3: str = 'https://cdnjs.cloudflare.com/ajax/libs/pixi.js/5.3.3/pixi.min.js'
POPPER_1_16_1: str = 'https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js'
SOCKET_1_4_5: str = 'https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.4.5/socket.io.min.js'
UNDERSCORE: str = 'https://cdn.jsdelivr.net/npm/underscore@1.11.0/underscore-min.js'
X3DOM: str = 'https://www.x3dom.org/download/x3dom.js'

domonic.utils

snippets etc

class domonic.utils.Utils[source]
static acronym(sentence: str) str[source]

[pass a sentence, returns the acronym]

Parameters

sentence ([str]) – [typically 3 words]

Returns

[a TLA (three letter acronym)]

Return type

[str]

static case_camel(s: str) str[source]

case_camel(‘camel-case’) > ‘camelCase’

static case_kebab(s: str) str[source]

kebab(‘camelCase’) # ‘camel-case’

static case_snake(s: str) str[source]

snake(‘camelCase’) # ‘camel_case’

static chunk(list: list, size: int) list[source]

chunk a list into batches

static chunks(iterable, size: int, format=<built-in function iter>)[source]

Iterate over any iterable (list, set, file, stream, strings, whatever), of ANY size

static clean(lst: list) list[source]

[removes falsy values (False, None, 0 and “”) from a list ]

Parameters

lst ([list]) – [lst to operate on]

Returns

[a new list with falsy values removed]

Return type

[list]

static dictify(arr: list) dict[source]

[turns a list into a dictionary where the list items are the keys]

Parameters

arr ([list]) – [list to change]

Returns

[a new dict where the list items are now the keys]

Return type

[dict]

static digits(text: str = '') str[source]

[takes a string of mix of digits and letters and returns a string of digits]

Parameters

text (str, optional) – [the text to change]. Defaults to ‘’.

Returns

[a string of digits]

Return type

[str]

static escape(s: str) str[source]

[escape a string]

Parameters

s ([str]) – [the string to escape]

Returns

[the escaped string]

Return type

[str]

static frequency(data)[source]

[check the frequency of elements in the data]

Parameters

data ([type]) – [the data to check]

Returns

[a dict of elements and their frequency]

Return type

[dict]

static get_vowels(string: str) list[source]

[get a list of vowels from the word]

Parameters

string ([str]) – [the word to check]

Returns

[a list of vowels]

Return type

[list]

static has_internet(url: str = 'http://www.google.com/', timeout: int = 5) bool[source]

[check if you have internet connection]

Parameters
  • url (str, optional) – [the url to check]. Defaults to ‘http://www.google.com/’.

  • timeout (int, optional) – [the timeout]. Defaults to 5.

Returns

[True if you have internet]

Return type

[bool]

static init_assets(dir: str = 'assets') None[source]

[creates an assets directory with nested js/css/img dirs]

Parameters

dir (str, optional) – [default directory name]. Defaults to ‘assets’.

static is_linux() bool[source]

[check if the system is a linux]

Returns

[description]

Return type

[bool]

static is_mac() bool[source]

[check if the system is a mac]

Returns

[True if the system is a mac]

Return type

[bool]

static is_nix() bool[source]

[check if the system is a nix based system]

Returns

[True if it is a nix based system]

Return type

[bool]

static is_windows() bool[source]

[check if the system is a windows]

Returns

[True if windows]

Return type

[bool]

static merge_dictionaries(a: dict, b: dict) dict[source]

[merges 2 dicts]

Parameters
  • a ([dict]) – [dict a]

  • b ([dict]) – [dict b]

Returns

[a new dict]

Return type

[dict]

static permutations(word: str) list[source]

[provides all the possible permutations of a given word]

Parameters

word ([str]) – [the word to get permutations for]

Returns

[a list of permutations]

Return type

[list]

static replace_between(content: str, match: str, replacement: str, start: int = 0, end: int = 0)[source]

[replace some text but only between certain indexes]

Parameters
  • content (str) – [the content whos text you will be replacing]

  • match (str) – [the string to find]

  • replacement (str) – [the string to replace it with]

  • start (int, optional) – [start index]. Defaults to 0.

  • end (int, optional) – [end index]. Defaults to 0.

Returns

[the new string]

Return type

[str]

static squash(the_list: list) list[source]

[turns a 2d array into a flat one]

Parameters

the_list ([list]) – [a 2d array]

Returns

[a flattened 1d array]

Return type

[list]

static to_dictionary(keys: list, values: list) dict[source]

[take a list of keys and values and returns a dict]

Parameters
  • keys ([list]) – [a list of keys]

  • values ([list]) – [a list of value]

Returns

[a dictionary]

Return type

[dict]

static truncate(text: str = '', length: int = 0) str[source]

[truncates a string and appends 3 dots]

Parameters
  • text (str, optional) – [the text to truncate]. Defaults to ‘’.

  • length (int, optional) – [the max length]. Defaults to 0.

Returns

[the truncated string]

Return type

[str]

static unescape(s: str) str[source]

[unescape a string]

Parameters

s ([str]) – [the string to unescape]

Returns

[the unescaped string]

Return type

[str]

static unique(some_arr: list) list[source]

[removes duplicates from a list]

Parameters

some_arr ([list]) – [list containing duplicates]

Returns

[a list containing no duplicates]

Return type

[list]

static untitle(string: str) str[source]

[the opposite of title]

Parameters

str ([str]) – [the string to change]

Returns

[a string with the first character set to lowercase]

Return type

[str]

static url2file(url: str) str[source]

[gen a safe filename from a url. by replacing ‘/’ for ‘_’ and ‘:’ for ‘__’ ]

Parameters

url ([str]) – [the url to turn into a filename]

Returns

[description]

Return type

[str]

domonic.decorators

domonic.decorators.as_json(func)[source]

decorate any function to return json instead of a python obj note - used by JSON.py

domonic.decorators.called(before=None, error: Optional[Callable[[Exception], None]] = None)[source]

Decorator to call a function before and after a function call.

domonic.decorators.check(f)[source]

Prints entry and exit of a function to the console

domonic.decorators.deprecated(func)[source]

marks a function as deprecated.

domonic.decorators.el(element='div', string: bool = False)[source]

[wraps the results of a function in an element]

domonic.decorators.iife(before=None, error: Optional[Callable[[Exception], None]] = None)

Decorator to call a function before and after a function call.

domonic.decorators.instead(f, somethingelse)[source]

what to return if it fails

domonic.decorators.log(logger, level='info')[source]

@log(logging.getLogger(‘main’), level=’warning’)

domonic.decorators.silence(*args, **kwargs)[source]

stop a function from doing anything