88Sketch CSS is a tool to generate CSS from Sketch Class definitions. Because pure
99CSS generation is straightforward, ` sketch_css ` does not need a cache to
1010generate 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
1616To 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
4083Because 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
4487generates the class, with a CSS variable, letting you update it, override it,
4588etc.
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```
0 commit comments