Simple implementation of markup for Scriptable widgets.

Overview

Widget Markup

Widget Markup for Scriptable

Write Scriptable widgets with markup.

Installation

Just import the library script to your scriptable widget file.

const {widgetMarkup, concatMarkup} = importModule('WidgetMarkup');

The library exposes only two template literal tags, widgetMarkup and concatMarkup.

widgetMarkup

This is the primary markup parser. This is where you place your markup tags and is the main body of your widget. It will return an instance of Scriptable's ListWidget class.

const widget = await widgetMarkup`
  <widget>
    <spacer value="10" />
    <stack>
	       <text>Hi I'm a widget 👋</text>
    </stack>
    <spacer value="15" />
  </widget>
`;
if (config.runsInWidget) {
    // Runs inside a widget so add it to the homescreen widget
    Script.setWidget(widget);
}
Script.complete()

concatMarkup

This method is used to concatenate markup elements to the main widget body. This method is used to ensure that the parser can properly set the styles of the elements being concatenated.

const textElement = concatMarkup`<text>I'm from the outside.</text>`

const widget = await widgetMarkup`
  <widget
    <stack>
	       ${textElement}
    </stack>
  </widget>
`;

Tags Supported

Currently the libtrary only supports the following tags

  • <widget> — The parent element of the widget. There can only be one widget tag per widget. This is the container for all the elements in the widget.

  • <stack> — The equivalent of Scriptable's .addStack() method. This tag can have other tags inside as children. It could also have other stack tags as children.

    <stack>
    	<text>Hello World</text>
    	<spacer value="10" />
    </stack>
  • <text> — The equivalent of Scriptable's .addText() method. Place widget text between this tag.

    <text>Hi I'm a widget text</text>
  • <image> — The equivalent of Scriptable's addImage() method. Used to add image to the widget. This tag requires a src attribute which takes in data with type Image.

    const docsSymbol = SFSymbol.named("book");
    const widget = await widgetMarkup`
      <widget>
    	    <stack>
    	       <image src="${docsSymbol.image}" />
    	    </stack>
      </widget>
    `;
  • <spacer> — The equivalent of Scriptable's addSpacer() method. This tag accepts a value attribute which takes in a numeric value for the length. If the value of the value attribute is 0 then this instructs the spacer to have a flexible length.

  • <date> — The equivalent of Scriptable's addDate() method. This tag requires value attribute which takes in an instance of the Date class.

Styling

All tags can accept a styles attribute. This attribute can only accept an object which is the list of styles the element will have. Here's a simple example of styling a text element.

const textStyles = {
	minimumScaleFactor: 0.5,
  	textColor: Color.white(),
  	font: Font.systemFont(18)	
};

const widget = await widgetMarkup`
  <widget>
	    <text styles="${textStyles}">Hello World</text>
  </widget>
`;

The code above would be equivalent to this in Scriptable.

const widget = new ListWidget();
const text = widget.addText('Hello World');
text.minimumScaleFactor = 0.5;
text.textColor = Color.white();
text.font = Font.systemFont(18);

The library encourages you to separate your styles from the structure of your widget. As the complexity of the structure of your widget grows, this way of coding will hopefully make your code more readable and maintainable.

Methods

Some styling properties in Scriptable needs to be called as a function/method. An example of this is layoutVertically or layoutHorizontally for stacks. For this type of styling, the library requires that the method name should be prefixed with a * . This is to signal to the parser that the styling property needs to be called as a function. Here's an example.

const stackStyles = {
    '*layoutVertically': null, // prefix with * and given a value of null if the method does not require a parameter.
    size: new Size(100, 20)
};

const widget = await widgetMarkup`
  <widget>
	    <stack styles="${stackStyles}">
            ...
        </stack>
  </widget>
`;

Which would be equivalent to this...

const widget = new ListWidget();
const stackElement = widget.addStack();
stackElement.layoutVertically(); // Called as a function.
stackElement.size = new Size(100, 20);

What if the styling method requires a parameter? A perfect example of this is the setPadding method which can take four parameters. For this you can pass in the parameters as an array of values.

const stackStyles = {
    '*setPadding': [5, 9, 5, 5], // Assign an array of values for the parameters
    size: new Size(100, 20)
};

const widget = await widgetMarkup`
  <widget>
	    <stack styles="${stackStyles}">
            ...
        </stack>
  </widget>
`;

The code above is equivalent to...

const widget = new ListWidget();
const stackElement = widget.addStack();
stackElement.setPadding(5, 9, 5, 5); // Padding assigned.
stackElement.size = new Size(100, 20);

Syntax Highlighting

If you are using vscode for development. I suggest installing Matt Bierner's Comment tagged templates extension. This makes your widget markup even more readable while you code.

Markup syntax highlighting

Conclusion

This library is still on a very early stage of development and you may encounter bugs. Just let me know if you have any questions about it or if you found a bug. You can contact me here. This library is also open for you to edit and improve. Play around with it and make it work for your needs. Hopefully it encourages you to write more awesome Scriptable iOS widgets.

If you find this library helpful, send me a screenshot of your widget or a code snippet on how you are using it. I'd love to see how you guys are using this library.

Download with ScriptDude

You might also like...

Different Widgets: Accordion, Search from Wikipedia(Wiki API), DropDown, Translate(Google API)

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: ya

Dec 19, 2021

A UI library by WeChat official design team, includes the most useful widgets/modules in mobile web applications.

A UI library by WeChat official design team, includes the most useful widgets/modules in mobile web applications.

WeUI - tailor-made for WeChat web service 中文版本 Introduction WeUI is an WeChat-like UI framework officially designed by the WeChat Design Team, tailor-

Jan 2, 2023

NG Bootstrap - Angular powered Bootstrap widgets

NG Bootstrap - Angular powered Bootstrap widgets Angular widgets built from the ground up using only Bootstrap 4 CSS with APIs designed for the Angula

Dec 24, 2022

Backgrid.js is a set of components for building semantic and easily stylable data grid widgets

Backgrid.js is a set of components for building semantic and easily stylable data grid widgets. It offers a simple, intuitive programming interface that makes easy things easy, but hard things possible when dealing with tabular data.

Nov 21, 2022

A UI library by WeChat official design team, includes the most useful widgets/modules.

A UI library by WeChat official design team, includes the most useful widgets/modules.

WeUI for 小程序 为微信小程序量身设计 概述 WeUI 是一套同微信原生视觉体验一致的基础样式库,由微信官方设计团队为微信内网页和微信小程序量身设计,令用户的使用感知更加统一。包含button、cell、dialog、 progress、 toast、article、actionsheet、

Jan 4, 2023

💸 getting sponsored made easy with widgets !

Ponsor getting sponsored made easy through widgets Tech Stack A lot of different tech and soft wares were used to create Ponsor, here is a list of the

Jan 4, 2023

Better select widgets in vanilla javascript.

Select Better select widgets in vanilla javascript. The code is intentionally very simple and close to browser defaults. Usage link rel="stylesheet"

Jun 17, 2022

waitlyst.js provides in-app widgets for collecting customer feedback & product analytics.

waitlyst.js provides in-app widgets for collecting customer feedback & product analytics.

waitlyst.js provides in-app widgets for collecting customer feedback & product analytics. Track every event on your app Understand your users and how

Dec 3, 2022

Scriptable Headless Browser

PhantomJS - Scriptable Headless WebKit PhantomJS (phantomjs.org) is a headless WebKit scriptable with JavaScript. The latest stable release is version

Jan 5, 2023

A scriptable browser like PhantomJS, based on Firefox

SlimerJS http://slimerjs.org/ SlimerJS is a scriptable browser. It allows you to manipulate a web page with an external Javascript script: opening a w

Dec 31, 2022

Scriptable Development Environment for VSCode

Scriptable Development Environment This project includes Scriptable types generated from documentation page RUN SCRIPT hotkey: ⌘ + SHIFT + B, it will

Dec 29, 2022

A swiss army knife with lots of tools, extensions and (scriptable) enhancements for Visual Studio Code.

A swiss army knife with lots of tools, extensions and (scriptable) enhancements for Visual Studio Code.

vscode-powertools A swiss army knife with lots of tools, extensions and (scriptable) enhancements for Visual Studio Code. ⚠️ ⚠️ ⚠️ NOTICE: If you have

Nov 24, 2022

TrySomethingNewWidget - A script for the iOS app called "Scriptable" prompting you with new ideas for things to try daily!

TrySomethingNewWidget A script for the iOS app called "Scriptable" prompting you with new ideas for things to try daily! (Beware that the small widget

Jul 11, 2022

A library to log for Scriptable.

scriptable-logger Logger is a library to log for Scriptable. Usage const Logger = importModule('logger'); Logger.log('log'); // 'log' in white color.

Apr 29, 2022

Collection of Scriptable scripts.

Collection of Scriptable scripts.

Scriptable Scripts GitLab Contribution Graph A widget that shows an overview of your recent GitLab contributions. It is available in small and medium

Nov 18, 2022

PoGOEvents is a Scriptable widget that displays current and upcoming Pokemon GO events.

PoGOEvents is a Scriptable widget that displays current and upcoming Pokemon GO events.

PoGOEvents PoGOEvents is a Scriptable widget that displays current and upcoming Pokemon GO events. All event data is gathered from from ScrapedDuck, w

Nov 12, 2022

Scriptable Widget which shows current news from tagesschau.de

Scriptable Widget which shows current news from tagesschau.de

tagesschau-widget for Scriptable Based on this reddit post of u/trbn_hck Unfortunately the Repositorie in his GitHub profile is no longer exist. Widge

Sep 12, 2022

Use jsx to make scriptable's layout.

scriptable-jsx This project helps you to write Scriptable widgets with JSX syntax. And add some useful tools by the way. you can check demos in demo f

Oct 10, 2022

A rugged, minimal framework for composing JavaScript behavior in your markup.

Alpine.js Alpine.js offers you the reactive and declarative nature of big frameworks like Vue or React at a much lower cost. You get to keep your DOM,

Jan 2, 2023
Owner
Rafael Gandionco
minimalist | photographer | web developer
Rafael Gandionco
A scriptable browser like PhantomJS, based on Firefox

SlimerJS http://slimerjs.org/ SlimerJS is a scriptable browser. It allows you to manipulate a web page with an external Javascript script: opening a w

Laurent Jouanneau 3k Dec 31, 2022
Scriptable Development Environment for VSCode

Scriptable Development Environment This project includes Scriptable types generated from documentation page RUN SCRIPT hotkey: ⌘ + SHIFT + B, it will

Slavik Nychkalo 80 Dec 29, 2022
TrySomethingNewWidget - A script for the iOS app called "Scriptable" prompting you with new ideas for things to try daily!

TrySomethingNewWidget A script for the iOS app called "Scriptable" prompting you with new ideas for things to try daily! (Beware that the small widget

Mathias Guldfeldt 2 Jul 11, 2022
A simple and stable cross-browser testing tool. 简单稳定的跨浏览器测试工具。

totoro A simple and stable cross-browser testing tool. Latest stable version: v2.0 Change Log 中文版使用文档 0. Features Run in real browsers Support all tes

totoro 568 Dec 21, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
A simple Angular-library with some widgets.

angular-workspace Contains a simple Angular-library with the next widgets: Clock Timer, crono, countdown Wizard Run: npm install to install all depend

Masiel Villalba 3 Apr 11, 2022
Simple CSS library for semantic HTML markup

awsm.css awsm.css is a simple CSS library for semantic HTML, which doesn't require classes, ids, attributes, etc. Just start to create page with HTML5

Igor Adamenko 1.4k Dec 30, 2022
Add a super simple rotating text to your website with little to no markup

#Super Simple Text Rotator by Pete R. A light weight jQuery plugin that will allow you to add a super simple rotating text to your website with little

Pete R. 754 Dec 6, 2022