10.0.4 • Published 2 years ago

@jdeighan/starbucks v10.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

starbucks - a sveltekit utility

Date: 8/27/2021

How starbucks() transforms .starbucks files to .svelte files:

A simple webpage

#starbucks webpage

h1 Hello, World!

becomes

<h1>
   Hello, World!
</h1>

A simple component

#starbucks component

h1 Hello, World!

becomes

<h1>
   Hello, World!
</h1>

NOTE: The above both produce the same output. However, handling of parameters differs between web pages and components

NOTE: The above resembles pug syntax, but it's not. See attributes below.

Multiple HTML elements

#starbucks webpage

h1 Hello, World!
p a paragraph

becomes

<h1>
   Hello, World!
</h1>
<p>
   a paragraph
</p>

Nested HTML elements

#starbucks webpage

div
	h1 Hello, World!
	p a paragraph

becomes

<div>
   <h1>
      Hello, World!
   </h1>
   <p>
      a paragraph
   </p>
</div>

Comments

#starbucks webpage

# --- this is a comment
#
# --- this is another comment

p a paragraph

becomes

<p>
   a paragraph
</p>

i.e. both comments and empty lines are ignored. A comment is a line where the first non-whitespace character is a '#' and either 1) the '#' is immediately followed by a whitespace character, or 2) there is nothing following the '#' on the line.

This is true inside script and style sections, as well as markdown. However, in #included markdown files, '# header' will be changed to 'header' followed by '======' and '##header' wil be changed to 'header' followed by '------'.

HTML attributes

#starbucks webpage

p class=bold a paragraph

becomes

<p class="bold">
   a paragraph
</p>

#starbucks webpage

p class='bold' a paragraph

becomes

<p class="bold">
   a paragraph
</p>

#starbucks webpage

p class="bold" a paragraph

becomes

<p class="bold">
   a paragraph
</p>

#starbucks webpage

p.bold a paragraph

becomes

<p class="bold">
   a paragraph
</p>

#starbucks webpage

p.bold class="red" a paragraph

becomes

<p class="bold red">
   a paragraph
</p>

#starbucks webpage

p.bold name="mine" a paragraph

becomes

<p name="mine" class="bold">
   a paragraph
</p>

#starbucks webpage

p.bold name="mine" 'a paragraph'

becomes

<p name="mine" class="bold">
   a paragraph
</p>

i.e. you can quote the text contained in an element if you're afraid that it might be interpreted

as an attribute

#starbucks webpage

p.bold name="mine" "a paragraph"

becomes

<p name="mine" class="bold">
   a paragraph
</p>

Parameters in a component

#starbucks component (name)

h1 title

becomes

<h1>
   title
</h1>

<script>
   import {undef,say,ask,isEmpty,nonEmpty} from '@jdeighan/coffee-utils'
export var name = undef;

</script>

NOTE: Whenever there is a <script> section, some common functions are automatically imported. TO DO: check which are actually used and only import those. Also, there should be a semicolon terminating the import statement.

NOTE: The export statement should be indented. The blank line should not appear.

Parameters in a web page

#starbucks webpage (name)

h1 title

becomes

<script context="module">
export var load = function({page}) {
  return {
    props: {name}
  };
};

</script>

<h1>
	title
</h1>

Substitution of env vars using {{name}}

NOTE: This requires a .env file in a valid location, e.g. a file named .env in the same dir containing the source starbucks file containing:

name = John
color = lightGray

Then,

#starbucks webpage

h1 My name is {{name}}

becomes

<h1>
	My name is John
</h1>

#starbucks webpage

script
	myName = '{{name}}'

becomes

<script>
	import {undef,say,ask,isEmpty,nonEmpty} from '@jdeighan/coffee-utils'
var myName;

myName = 'John';

</script>

#starbucks webpage

style
	p
		background-color: {{color}}

becomes

<style>
p {
		background-color: lightGray;
}
</style>

Command #envvar

NOTE: In starbucks syntax, a command is a line on which the first non-whitespace character is '#', which is immediately followed by the name of the command, which always consists of one or more lower-case letters

#starbucks webpage

#envvar lastName = Deighan
p My last name is {{lastName}}

becomes

<p>
	My last name is Deighan
</p>

Command #if

#starbucks webpage

#envvar lastName = Deighan

#if known
	p My last name is {{lastName}}
#else
	p I don't know

becomes

{#if known }
	<p>
		My last name is Deighan
	</p>
{:else}
	<p>
		I don't know
	</p>
{/if}

NOTE: known is a JavaScript variable, and if it changes, the block of code that is displayed may change. However, lastName is a constant at the time that this code is generated, and as such, will always be 'Deighan'.

#starbucks webpage

#envvar lastName = Deighan

#if known
	p My last name is {{lastName}}
#elsif standard
	p My last name is Smith
#else
	p I don't know

becomes

{#if known }
	<p>
		My last name is Deighan
	</p>
{:else if standard }
	<p>
		My last name is Smith
	</p>
{:else}
	<p>
		I don't know
	</p>
{/if}

Command #for

#starbucks webpage

#envvar lastName = Deighan

#for name in lNames
	p My name is {name}

becomes

{#each lNames as name}
	<p>
		My name is {name}
	</p>
{/each}

#starbucks webpage

#for name,i in lNames
	p {i}. My name is {name}

becomes

{#each lNames as name,i}
	<p>
		{i}. My name is {name}
	</p>
{/each}

#starbucks webpage

#for name,i in lNames  (key  =  id)
	p {i}. My name is {name}

becomes

{#each lNames as name,i (id)}
	<p>
		{i}. My name is {name}
	</p>
{/each}

Command #await

#starbucks webpage

#await fetch('https://disease.sh/v3/covid-19/historical/all?lastdays=30')
	p please wait...
#then lData
	ul
		#for n,i in lData
			li [{i}] {n}
#catch err
	div.error {err.message}

becomes

{#await fetch('https://disease.sh/v3/covid-19/historical/all?lastdays=30')}
	<p>
		please wait...
	</p>
{:then lData}
	<ul>
		{#each lData as n,i}
			<li>
				[{i}] {n}
			</li>
		{/each}
	</ul>
{:catch err}
	<div class="error">
		{err.message}
	</div>
{/await}

Nested Styles (a la SASS)

#starbucks webpage

h1.error
	p.message {err.message}
	p.solution Please set env var dir_root

style
	h1.error
		p.message
			background-color: red
		p.solution
			background-color: orange

becomes

<h1 class="error">
	<p class="message">
		{err.message}
	</p>
	<p class="solution">
		Please set env var dir_root
	</p>
</h1>

<style>
h1.error p.message {
		background-color: red;
}
h1.error p.solution {
		background-color: orange;
}
</style>

Attribute values = {...}

becomes

10.0.0

2 years ago

10.0.1

2 years ago

10.0.2

2 years ago

10.0.3

2 years ago

10.0.4

2 years ago

9.0.0

2 years ago

8.0.0

2 years ago

7.0.23

2 years ago

7.0.24

2 years ago

7.0.21

2 years ago

7.0.22

2 years ago

7.0.29

2 years ago

7.0.27

2 years ago

7.0.28

2 years ago

7.0.25

2 years ago

7.0.26

2 years ago

7.0.34

2 years ago

7.0.35

2 years ago

7.0.32

2 years ago

7.0.33

2 years ago

7.0.30

2 years ago

7.0.31

2 years ago

7.0.38

2 years ago

7.0.36

2 years ago

7.0.37

2 years ago

7.0.19

2 years ago

7.0.20

2 years ago

7.0.13

3 years ago

7.0.18

3 years ago

7.0.16

3 years ago

7.0.17

3 years ago

7.0.14

3 years ago

7.0.15

3 years ago

7.0.9

3 years ago

7.0.12

3 years ago

7.0.10

3 years ago

7.0.11

3 years ago

7.0.8

3 years ago

7.0.7

3 years ago

7.0.6

3 years ago

7.0.5

3 years ago

5.0.6

3 years ago

5.0.5

3 years ago

5.0.4

3 years ago

5.0.3

3 years ago

7.0.0

3 years ago

7.0.4

3 years ago

7.0.3

3 years ago

7.0.2

3 years ago

7.0.1

3 years ago

6.0.15

3 years ago

6.0.14

3 years ago

6.0.13

3 years ago

6.0.12

3 years ago

6.0.11

3 years ago

6.0.10

3 years ago

6.0.7

3 years ago

6.0.6

3 years ago

6.0.9

3 years ago

6.0.8

3 years ago

6.0.1

3 years ago

6.0.0

3 years ago

6.0.3

3 years ago

6.0.2

3 years ago

6.0.5

3 years ago

6.0.4

3 years ago

5.0.2

3 years ago

5.0.1

3 years ago

4.0.5

3 years ago

5.0.0

3 years ago

4.0.4

3 years ago

4.0.3

3 years ago

4.0.1

3 years ago

4.0.2

3 years ago

2.0.5

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

4.0.0

3 years ago

2.0.3

3 years ago

2.0.4

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.2.2

3 years ago

1.2.0

3 years ago

1.2.1

3 years ago

1.1.29

3 years ago

1.1.28

3 years ago

1.1.30

3 years ago

1.1.34

3 years ago

1.1.33

3 years ago

1.1.32

3 years ago

1.1.31

3 years ago

1.1.35

3 years ago

1.1.27

3 years ago

1.1.26

3 years ago

1.1.25

3 years ago

1.1.24

3 years ago

1.1.23

3 years ago

1.1.22

3 years ago

1.1.21

3 years ago

1.1.20

3 years ago

1.1.9

3 years ago

1.1.12

3 years ago

1.1.11

3 years ago

1.1.10

3 years ago

1.1.16

3 years ago

1.1.15

3 years ago

1.1.14

3 years ago

1.1.13

3 years ago

1.1.19

3 years ago

1.1.18

3 years ago

1.1.17

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.0.26

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago