Skip to content

Commit e8ca108

Browse files
committed
Merge branch 'feat/4.0.0'
2 parents 2745002 + 30819e8 commit e8ca108

File tree

22 files changed

+285
-127
lines changed

22 files changed

+285
-127
lines changed

sketch/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
## v4.0.0 - Unreleased
1+
## v4.0.0 - 2024-01-12
22

33
v4.0.0 marks a major release for Sketch! It bundles new improvements, new
4-
features, and improve namespacing! Six months after the initial release of v3,
4+
features, and improved namespacing! Six months after the initial release of v3,
55
v4 marks a new milestone as Sketch gains in maturity, usability and usage. More
66
and more people are using it, and as such, Sketch has to evolve in the right
77
path!

sketch/README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ abstraction allows a greater flexibility, without adding too much burden, as
6565
they're still all generated at runtime. Sketch favour explicitness and CSS
6666
generation for every node instead of relying on cascading and inheritance.
6767

68+
## Examples
69+
70+
Want to see examples to jump directly on subject? Take a look at
71+
[e2e folder on GitHub](https://github.com/ghivert/sketch/tree/main/e2e) to see
72+
how it works!
73+
6874
## Sketch Lustre
6975

7076
### Setup
@@ -119,7 +125,7 @@ simple node, without any class linked on it.
119125

120126
```gleam
121127
import sketch/css
122-
import sketch/csssize.{px}
128+
import sketch/css/length.{px}
123129
import sketch/lustre/element
124130
import sketch/lustre/element/html
125131
@@ -209,7 +215,7 @@ time.
209215
```gleam
210216
import redraw/html as h
211217
import sketch/css
212-
import sketch/css/size.{px}
218+
import sketch/css/length.{px}
213219
import sketch/redraw/html
214220
215221
fn main_style() {
@@ -384,8 +390,8 @@ to call the proper functions, and Sketch will take care of the rest.
384390

385391
```gleam
386392
import sketch/css
393+
import sketch/css/length.{px}
387394
import sketch/css/media
388-
import sketch/css/size.{px}
389395
390396
fn my_class() {
391397
css.class([

sketch/gleam.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ path = "sketch"
1818
[dependencies]
1919
gleam_erlang = ">= 0.25.0 and < 1.0.0"
2020
gleam_otp = ">= 0.10.0 and < 1.0.0"
21-
gleam_stdlib = ">= 0.34.0 and < 1.0.0"
21+
gleam_stdlib = ">= 0.42.0 and < 1.0.0"
2222

2323
[dev-dependencies]
2424
birdie = ">= 1.2.5 and < 2.0.0"

sketch/manifest.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ packages = [
3535
birdie = { version = ">= 1.2.5 and < 2.0.0" }
3636
gleam_erlang = { version = ">= 0.25.0 and < 1.0.0" }
3737
gleam_otp = { version = ">= 0.10.0 and < 1.0.0" }
38-
gleam_stdlib = { version = ">= 0.34.0 and < 1.0.0" }
38+
gleam_stdlib = { version = ">= 0.42.0 and < 1.0.0" }
3939
startest = { version = ">= 0.6.0 and < 1.0.0" }

sketch/src/sketch.gleam

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn render(cache: StyleSheet) -> String {
3030
}
3131

3232
@target(javascript)
33-
/// Convert a `Class` to its class name, to use it anywhere in your application.
33+
/// Converts a `Class` to its class name, to use it anywhere in your application.
3434
/// It always returns the StyleSheet, because the class can have been pushed
3535
/// in the StyleSheet itself.
3636
pub fn class_name(class: Class, stylesheet: StyleSheet) -> #(StyleSheet, String) {
@@ -45,6 +45,8 @@ pub fn class_name(class: Class, stylesheet: StyleSheet) -> #(StyleSheet, String)
4545
}
4646

4747
@target(javascript)
48+
/// Pushes an `@rule` in the StyleSheet, to get it bundled in the outputted CSS.
49+
/// It returns the StyleSheet with the rule added.
4850
pub fn at_rule(rule: AtRule, stylesheet: StyleSheet) -> StyleSheet {
4951
let cache = cache.at_rule(rule, stylesheet.cache)
5052
StyleSheet(..stylesheet, cache:)

sketch/src/sketch/css.gleam

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub type Style =
2323
pub type Class =
2424
style.Class
2525

26-
/// Represents an at-rule.
26+
/// Represents an [at-rule](https://developer.mozilla.org/docs/Web/CSS/At-rule).
2727
pub type AtRule =
2828
style.AtRule
2929

@@ -137,15 +137,15 @@ pub fn all(value: String) -> Style {
137137
/// ---
138138
///
139139
/// This property is a shorthand for the following CSS properties:
140-
/// [`animation-delay`](https://developer.mozilla.org/docs/Web/CSS/animation-delay)
141-
/// [`animation-direction`](https://developer.mozilla.org/docs/Web/CSS/animation-direction)
142-
/// [`animation-duration`](https://developer.mozilla.org/docs/Web/CSS/animation-duration)
143-
/// [`animation-fill-mode`](https://developer.mozilla.org/docs/Web/CSS/animation-fill-mode)
144-
/// [`animation-iteration-count`](https://developer.mozilla.org/docs/Web/CSS/animation-iteration-count)
145-
/// [`animation-name`](https://developer.mozilla.org/docs/Web/CSS/animation-name)
146-
/// [`animation-play-state`](https://developer.mozilla.org/docs/Web/CSS/animation-play-state)
147-
/// [`animation-timeline`](https://developer.mozilla.org/docs/Web/CSS/animation-timeline)
148-
/// [`animation-timing-function`](https://developer.mozilla.org/docs/Web/CSS/animation-timing-function)
140+
/// - [`animation-delay`](https://developer.mozilla.org/docs/Web/CSS/animation-delay)
141+
/// - [`animation-direction`](https://developer.mozilla.org/docs/Web/CSS/animation-direction)
142+
/// - [`animation-duration`](https://developer.mozilla.org/docs/Web/CSS/animation-duration)
143+
/// - [`animation-fill-mode`](https://developer.mozilla.org/docs/Web/CSS/animation-fill-mode)
144+
/// - [`animation-iteration-count`](https://developer.mozilla.org/docs/Web/CSS/animation-iteration-count)
145+
/// - [`animation-name`](https://developer.mozilla.org/docs/Web/CSS/animation-name)
146+
/// - [`animation-play-state`](https://developer.mozilla.org/docs/Web/CSS/animation-play-state)
147+
/// - [`animation-timeline`](https://developer.mozilla.org/docs/Web/CSS/animation-timeline)
148+
/// - [`animation-timing-function`](https://developer.mozilla.org/docs/Web/CSS/animation-timing-function)
149149
///
150150
/// ---
151151
///

sketch/src/sketch/css/font_face.gleam

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
//// The `@font-face` CSS at-rule specifies a custom font with which to display
2+
//// text; the font can be loaded from either a remote server or a
3+
//// locally-installed font on the user's own computer.
4+
////
5+
//// ---
6+
////
7+
//// [MDN Reference](https://developer.mozilla.org/docs/Web/CSS/@font-face)
8+
19
import gleam/float
210

311
/// A `FontFace` is a part of a `@font-face` rule.

sketch/src/sketch/css/keyframe.gleam

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
//// The `@keyframes` CSS [at-rule](https://developer.mozilla.org/en-US/docs/Web/CSS/At-rule)
2+
//// controls the intermediate steps in a CSS animation sequence by defining
3+
//// styles for keyframes (or waypoints) along the animation sequence. This
4+
//// gives more control over the intermediate steps of the animation sequence
5+
//// than [transitions](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_transitions).
6+
////
7+
//// ---
8+
////
9+
//// [MDN Reference](https://developer.mozilla.org/docs/Web/CSS/@keyframes)
10+
111
import gleam/int
212
import sketch/internals/cache/cache as style
313

sketch_css/README.md

Lines changed: 71 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
Sketch CSS is a tool to generate CSS from Sketch Class definitions. Because pure
99
CSS generation is straightforward, `sketch_css` does not need a cache to
1010
generate correct CSS files. Instead, `sketch_css` ships with a CLI tool, able to
11-
read your Gleam styles files, and output corresponding your CSS automagically,
12-
while providing an abstraction layer written in Gleam, to make sure you're using
13-
the right classes! It's an other way to leverage Sketch core and enjoy the
14-
styling in Gleam, while taking advantage of all the static CSS power!
11+
read your Gleam styles files, and output corresponding CSS automagically, while
12+
providing an abstraction layer written in Gleam, to make sure you're using the
13+
right classes! It's an other way to leverage Sketch core and enjoy the styling
14+
in Gleam, while taking advantage of all the static CSS power!
1515

1616
To run the generator, you have to use the command
1717
`gleam run -m sketch/css generate` at the root of your project. By default,
@@ -25,16 +25,59 @@ in `src/sketch/styles`, matching your styles files, to use in your project!
2525

2626
### Options
2727

28-
Sketch CSS generation has strong defaults, but everything can be customised. Use
29-
the CLI flags to configure what you need. CLI exposes 3 flags:
28+
Sketch CSS generation has strong defaults, but everything can be customised. To
29+
pass options to Sketch CSS, you have three ways:
30+
31+
- Pass them directly on the CLI. Every option has its equivalent exposed in the
32+
CLI.
33+
- Write them in a `sketch_css.toml` file, at root of your project, next
34+
`gleam.toml`.
35+
- Write them directly in `gleam.toml`, under `[sketch_css]` section.
36+
37+
Sketch CSS has 3 distinct options:
3038

3139
- `--dest`, accepting a folder, relative to current directory. It defaults to
32-
`styles`
40+
`styles`.
3341
- `--src`, accepting a folder, relative to current directory. It defaults to
3442
`src`.
3543
- `--interface`, accepting a folder, relative to current directory. It defaults
3644
to `src/sketch/styles`.
3745

46+
Write directly the folder, path resolution is done with current working
47+
directory as root.
48+
49+
#### Examples
50+
51+
```sh
52+
gleam run -m sketch_css generate --src="src" --dest="styles" --interface="src/sketch/styles"
53+
```
54+
55+
```toml
56+
# sketch_css.toml
57+
src = "src"
58+
dest = "styles"
59+
interface = "src/sketch/styles"
60+
```
61+
62+
```toml
63+
# gleam.toml
64+
name = "name"
65+
version = "1.0.0"
66+
67+
[sketch_css]
68+
src = "src"
69+
dst = "styles"
70+
interface = "src/sketch/styles"
71+
72+
[dependencies]
73+
gleam_stdlib = ">= 0.34.0 and < 2.0.0"
74+
sketch = ">= 4.0.0 and < 5.0.0"
75+
sketch_css = ">= 2.0.0 and < 3.0.0"
76+
77+
[dev-dependencies]
78+
gleeunit = ">= 1.0.0 and < 2.0.0"
79+
```
80+
3881
### A note on generation algorithm
3982

4083
Because a Sketch `Class` can be generated in multiple ways, and with variable,
@@ -44,43 +87,49 @@ generated with the variable taken into account! Sketch CSS being opinionated, it
4487
generates the class, with a CSS variable, letting you update it, override it,
4588
etc.
4689

47-
All `_` are also automatically transformed into `-`, because CSS classes are
48-
most of the time used with dashes, so Sketch CSS follows that convention!
90+
Sketch CSS also acts as a basic interpreter. It means you can write basic
91+
constants or variables, and they will be taking into account. Be sure to write
92+
classes like you would do in CSS yet: Sketch CSS does not execute your
93+
functions!
4994

5095
### Example
5196

5297
```gleam
5398
// src/main_styles.gleam
54-
import sketch
99+
import sketch/css
55100
56-
fn flexer() {
57-
sketch.class([
58-
sketch.display("flex"),
59-
])
101+
pub fn flexer() {
102+
let display = "flex"
103+
css.class([css.display(display)])
104+
}
105+
106+
fn direction(flex_direction: String) {
107+
css.flex_direction(flex_direction)
60108
}
61109
62-
fn flexer_direction(flex_direction: String) {
63-
sketch.class([
64-
sketch.compose(flexer()),
65-
sketch.flex_direction(flex_direction),
110+
pub fn flexer_direction(flex_direction: String) {
111+
css.class([
112+
css.compose(flexer()),
113+
direction(flex_direction),
66114
])
67115
}
68116
```
69117

70118
```css
71119
/* styles/main_styles.css */
72-
.flexer {
120+
.main_styles-flexer {
73121
display: flex;
74122
}
75123

76-
.flexer-direction {
124+
.main_styles-flexer_direction {
125+
display: flex;
77126
flex-direction: var(--flex-direction);
78127
}
79128
```
80129

81130
```gleam
82131
// src/sketch/styles/main_styles.gleam
83-
pub const flexer = "flexer"
132+
pub const flexer = "main_styles-flexer"
84133
85-
pub const flexer_direction = "flexer flexer-direction"
134+
pub const flexer_direction = "main_styles-flexer_direction"
86135
```

sketch_css/gleam.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ path = "sketch_css"
2121
argv = ">= 1.0.2 and < 2.0.0"
2222
glance = ">= 2.0.0 and < 3.0.0"
2323
gleam_erlang = ">= 0.25.0 and < 1.0.0"
24-
gleam_stdlib = ">= 0.34.0 and < 2.0.0"
24+
gleam_stdlib = ">= 0.42.0 and < 2.0.0"
2525
glint = ">= 1.2.0 and < 2.0.0"
2626
simplifile = ">= 2.0.1 and < 3.0.0"
2727
sketch = {path = "../sketch"}

0 commit comments

Comments
 (0)