Domonic: CDN

To quickly use and reference external assets when prototyping use the CDN package.

Currently there are 3 types of CDN. .js, .css and .img

Their features will be added here.

To use features from CDN they must be imported.

from domonic.CDN import *

Or just class you need

from domonic.CDN import CDN_JS

CDN_JS

script(_src=CDN_JS.JQUERY_3_5_1)

currently constants exist for:

  • JQUERY_3_5_1
  • JQUERY_UI
  • UNDERSCORE
  • BOOTSTRAP_4
  • POPPER_1_16_1
  • BOOTSTRAP_5_ALPHA
  • D3_6_1_0
  • MODERNIZER_2_8_3
  • MOMENT_2_27_0
  • PIXI_5_3_3
  • SOCKET_1_4_5

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

Refs to some useful .js and .css libs.

use for prototyping. wget anything in later and create your own local references once ur happy

TODO - integrity/cross origin/module?

WARNING/NOTE - dont use. this isn’t released or documented. just ideas atm…

class domonic.CDN.CDN_CSS[source]

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

class domonic.CDN.CDN_IMG[source]

CDN images

static PLACEHOLDER(width=100, height=100, HTTP='', seperator='/')[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]

You will need to append the lib version number if you add any libs here # obvious candidates… https://github.com/sorrycc/awesome-javascript

domonic.utils

snippets etc

class domonic.utils.Utils[source]

utils

static acronym(sentence: 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)[source]

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

static case_kebab(s: str)[source]

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

static case_snake(s: str)[source]

snake(‘camelCase’) # ‘camel_case’

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

chunk a list into batches

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

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

static clean(lst)[source]

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

Parameters:lst ([type]) – [lst to operate on]
Returns:[a new list with falsy values removed]
Return type:[type]
static dictify(arr: str)[source]

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

Parameters:arr ([type]) – [list to change]
Returns:[a new dict where the list items are now the keys]
Return type:[type]
static escape(s: str)[source]

[escape a string]

Parameters:s ([str]) – [the string to escape]
Returns:[description]
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)[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='http://www.google.com/', timeout=5)[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:

[description]

Return type:

[bool]

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

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

Parameters:dir (str, optional) – [default directory name]. Defaults to ‘assets’.
static merge_dictionaries(a, b)[source]

[merges 2 dicts]

Parameters:
  • a ([type]) – [dict a]
  • b ([type]) – [dict b]
Returns:

[a new dict]

Return type:

[dict]

static permutations(word: str)[source]

[provides all the possible permutations of a given word]

Parameters:word ([str]) – [the word to get permutations for]
Returns:[description]
Return type:[str]
static random_color(self)[source]

TODO - remove in 0.3 as we have color class.

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:

[description]

Return type:

[str]

static squash(the_list: list)[source]

[turns a 2d array into a flat one]

Parameters:the_list ([type]) – [a 2d array]
Returns:[a flattened 1d array]
Return type:[type]
static to_dictionary(keys, values)[source]

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

Parameters:
  • keys ([type]) – [a list of keys]
  • values ([type]) – [a list of value]
Returns:

[a dictionary]

Return type:

[dict]

static truncate(text='', length=0)[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:

[description]

Return type:

[str]

static unescape(s: str)[source]

[unescape a string]

Parameters:s ([str]) – [the string to unescape]
Returns:[description]
Return type:[str]
static unique(some_arr)[source]

[removes duplicates from a list]

Parameters:some_arr ([type]) – [list containing duplicates]
Returns:[a list containing no duplicates]
Return type:[type]
static untitle(string: str)[source]

[the opposite of title]

Parameters:str ([type]) – [the string to change]
Returns:[a string with the first character set to lowercase]
Return type:[type]
static url2file(url: 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.called(before=None, error=None)[source]

[calls before() passing the response as args to the decorated function. optional error handler. run the decorated function immediately.

WARNING: this is not for the regular decorating of a function its syntactical sugar for a callback i.e.

@called(
lambda: º.ajax(’https://www.google.com’), lambda err: print(‘error:’, err))
def success(data=None):
print(“sweet!”) print(data)
domonic.decorators.check(f)[source]

logs entry and exit of a function

domonic.decorators.deprecated(func)[source]

This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emitted when the function is used.

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

[wraps the results of a function in an element]

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