Skip to content

Commit 9cbb4ea

Browse files
committedNov 7, 2018
feat: Extended @block syntax. Issue #192.
- Rename @block-reference to @block - Default @block imports from a Block module. - Named @block imports from a Block module. - Default Block exports from a module. - Named Block exports from a module. - default as a reserved name. - Introduced simple parser for import/export parsing. - Split apart parser tests into logical packages.
1 parent 2a64dfa commit 9cbb4ea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1701
-978
lines changed
 

‎OLD_README.md

+25-25
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ Root specific declarations:
373373
the file's path is not a legal CSS identifier. Note: the way a path becomes
374374
a name is configurable on a per-application or framework integration basis.
375375
* `implements`: a space separated list of block names that have already been
376-
declared with `@block-reference` (See below).
376+
declared with `@block` (See below).
377377
* `extends`: the value is name of a single block from which to inherit the
378378
styles and public interface. Note that this does not change the output of
379379
the block but instead it affects the classes that are used in the templates
@@ -425,16 +425,16 @@ E.g. `.button[state|size=large], .button[state|size=small]`.
425425

426426
### Block References
427427

428-
You can declare a dependency on another block with the `@block-reference`
428+
You can declare a dependency on another block with the `@block`
429429
@-rule. Block references don't cause any styles to be included. Instead,
430430
they are like an ES6 `import` statement -- they make it possible to refer to
431431
the public interface of another block from within the current block and to
432432
resolve any namespace collisions with locally preferred identifiers.
433433

434-
A `@block-reference` creates a locally scoped alias for the styles in the referenced block:
434+
A `@block` creates a locally scoped alias for the styles in the referenced block:
435435

436436
```css
437-
@block-reference icons from "../../shared/styles/icons/dark.block.css";
437+
@block icons from "../../shared/styles/icons/dark.block.css";
438438
```
439439

440440
### Conflicting Block Names
@@ -457,7 +457,7 @@ automatically generate a unique name for BEM output mode.
457457
`my-component/styles.block.css`
458458

459459
```css
460-
@block-reference shared from "../shared.block.css";
460+
@block shared from "../shared.block.css";
461461

462462
:scope {
463463
block-name: my-block;
@@ -510,7 +510,7 @@ elements.
510510

511511
`navigation.block.css`
512512
```css
513-
@block-reference app from "application.block.css";
513+
@block app from "application.block.css";
514514

515515
app[state|is-saving] .signout,
516516
.signout[state|disabled] {
@@ -530,7 +530,7 @@ block object.
530530

531531
- `:scope` represents the block root for the current block.
532532
- `a-block-reference.root` represents the block root for the
533-
block that has a `@block-reference` as `a-block-reference` from the current
533+
block that has a `@block` as `a-block-reference` from the current
534534
block. In many cases, the `:scope` can be safely omitted.
535535
- `[state|foo]` or `[state|foo=bar]` represent the
536536
root state named `foo` or the state named `foo` with the substate of `bar`.
@@ -617,7 +617,7 @@ Rather than having to specify the block root, a block class can declare itself t
617617
```
618618
619619
// tabs.block.css
620-
@block-reference tab from "tab.block.css";
620+
@block tab from "tab.block.css";
621621
:scope {
622622
display: flex;
623623
}
@@ -674,7 +674,7 @@ To inherit from another block you must first define a reference to the
674674
other block:
675675

676676
```css
677-
@block-reference another from "./another-block.block.css";
677+
@block another from "./another-block.block.css";
678678
```
679679

680680
And now that block can be referenced within this file by the name
@@ -712,8 +712,8 @@ implementation of that interface. To accomplish this, you can declare
712712
a block `implements` one or more blocks.
713713

714714
```css
715-
@block-reference base from "./base.block.css";
716-
@block-reference other from "./other.block.css";
715+
@block base from "./base.block.css";
716+
@block other from "./other.block.css";
717717
:scope { implements: base, other; color: red; }
718718
```
719719

@@ -768,7 +768,7 @@ that conflict in another block object's selectors.
768768

769769
```css
770770
/* header.block.css */
771-
@block-reference other from "./other.css";
771+
@block other from "./other.css";
772772
.header {
773773
border: none;
774774
border: resolve("other.nav");
@@ -822,7 +822,7 @@ local values to take precedence.
822822

823823
```css
824824
/* header.block.css */
825-
@block-reference other from "./other.css";
825+
@block other from "./other.css";
826826
.header {
827827
border: resolve("other.nav");
828828
border: none;
@@ -854,7 +854,7 @@ selectors of that same pseudo-element are resolved.
854854

855855
```css
856856
/* lists.block.css */
857-
@block-reference links from "./links.block.css";
857+
@block links from "./links.block.css";
858858
.list-item::before {
859859
content: "*";
860860
content: resolve("links.external");
@@ -893,7 +893,7 @@ Example:
893893

894894
```css
895895
/* lists.block.css */
896-
@block-reference links from "./links.block.css";
896+
@block links from "./links.block.css";
897897
.list-item {
898898
color: purple;
899899
color: resolve("links.external");
@@ -967,8 +967,8 @@ same local identifier for the block with the global state. Example:
967967

968968
```css
969969
/* icons.block.css */
970-
@block-reference article from "./article.block.css";
971-
@block-reference app from "./app.block.css";
970+
@block article from "./article.block.css";
971+
@block app from "./app.block.css";
972972
.icon {
973973
color: white;
974974
color: resolve("app[state|is-loading] article.link");
@@ -1026,7 +1026,7 @@ Example:
10261026

10271027
```css
10281028
/* icons.block.css */
1029-
@block-reference article from "./article.block.css";
1029+
@block article from "./article.block.css";
10301030
.icon {
10311031
color: white;
10321032
color: resolve-all("article.link");
@@ -1119,7 +1119,7 @@ local values to take precedence.
11191119

11201120
```css
11211121
/* header.block.css */
1122-
@block-reference other from "./other.css";
1122+
@block other from "./other.css";
11231123
.header {
11241124
font-size: 16px;
11251125
font-size: 1rem;
@@ -1173,7 +1173,7 @@ Consider the following conflicts when `target.main` and `conflicts.article` are
11731173

11741174
```css
11751175
/* conflicts.block.css */
1176-
@block-reference target from "./target.css";
1176+
@block target from "./target.css";
11771177
[state|happy] .article {
11781178
color: green;
11791179
color: resolve("target.main");
@@ -1217,7 +1217,7 @@ Specifically for any property that has a conflict with the super block element
12171217
of the same value in the key selector the following resolution is created:
12181218

12191219
```css
1220-
@block-reference base from "./base.block.css";
1220+
@block base from "./base.block.css";
12211221
:scope { extends: base; }
12221222
.foo {
12231223
color: resolve("base.foo");
@@ -1235,8 +1235,8 @@ composition of the necessary styles as it's own class.
12351235
File: `navigation.block.scss`
12361236

12371237
```scss
1238-
@block-reference super-grid-system from "super-grid-system.block.css";
1239-
@block-reference drop-down from "drop-down.block.css";
1238+
@block super-grid-system from "super-grid-system.block.css";
1239+
@block drop-down from "drop-down.block.css";
12401240

12411241
.profile {
12421242
float: --unset;
@@ -1269,7 +1269,7 @@ You must also tell the debug statement where to output the information.
12691269
Example:
12701270

12711271
```css
1272-
@block-reference icons from "../../shared/styles/icons/dark.block.css";
1272+
@block icons from "../../shared/styles/icons/dark.block.css";
12731273
@block-debug icons to comment;
12741274
```
12751275

@@ -1423,7 +1423,7 @@ the current component's styles:
14231423
`my-component/styles.block.css`
14241424

14251425
```css
1426-
@block-reference icons from "../../shared/styles/icons/dark.block.css";
1426+
@block icons from "../../shared/styles/icons/dark.block.css";
14271427

14281428
:scope {
14291429
border: 1px solid black;

‎README.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ CSS Blocks is under active development and there are a number of features that h
111111
|| <code>[state&#124;name=value]</code> | Bare state (not associated with an Originating Element) and optional substate selectors for targeting all elements in the Block that possess the state an/or sub-state. |
112112
| 🖌 | <code>.class[state&#124;name default]</code> | Default state value to be applied when there is no other match. |
113113
| **At Rules** ||
114-
|| `@block-reference local-name from "./file/path.css"` | Reference another Block using a local name. |
114+
|| `@block local-name from "./file/path.css"` | Reference another Block using a local name. |
115115
|| `@block-debug block-name to channel` | Debug call that will print a block interface to a "channel": `comment`, `stderr`, or `stdout`. |
116116
|| `@block-global block.path` | Declare a Block class or state as public. It may be used as a context selector in other Blocks. |
117117
| 🖌 | `@is-block block-name` | Block class can declare itself to be the root of another block in a specific state or set of states. |
@@ -296,14 +296,14 @@ There are only two (2) common-sense rules to follow when using Block styles in y
296296
# 🏗 Block Composition
297297
Blocks styles are, by design, scoped to the file they are written in, but we all know that in a real app your styles can't live in a vacuum!
298298

299-
As you'll see below, there are many methods to compose blocks together in your application. However, most of these methods will begin with the humble `@block-reference`.
299+
As you'll see below, there are many methods to compose blocks together in your application. However, most of these methods will begin with the humble `@block`.
300300

301301
## Block References
302-
A Block may declare a dependency on another Block by using a `@block-reference` at the top of your file. A `@block-reference` creates a locally scoped alias where you can access the public API (declared classes and states) of the referenced block.
302+
A Block may declare a dependency on another Block by using a `@block` at the top of your file. A `@block` creates a locally scoped alias where you can access the public API (declared classes and states) of the referenced block.
303303

304304
Block references don't cause any styles to be included. Instead, they are like an ES6 `import` statement -- they make it possible to refer to the public interface of another Block from within the current Block.
305305

306-
Adding a `@block-reference` is as simple as this:
306+
Adding a `@block` is as simple as this:
307307

308308
```css
309309
/* block-1.block.css */
@@ -314,14 +314,14 @@ Adding a `@block-reference` is as simple as this:
314314

315315
```css
316316
/* block-2.block.css */
317-
@block-reference other-block from "./block-1.block.css";
317+
@block other-block from "./block-1.block.css";
318318

319319
:scope { block-name: block-2; }
320320
```
321321

322322
> 🔮 **Future Feature: Node Modules Block Resolution **
323323
>
324-
> Whether you're integrating with a 3rd party library, or pulling in dependencies internal to your company, at some point you'll want to integrate with styles delivered via NPM! The resolution logic for `@block-reference`s to `node_modules` hasn't yet been implemented yet, but you can track progress (or even help out!) [over on Github](https://github.com/linkedin/css-blocks/issues/112).
324+
> Whether you're integrating with a 3rd party library, or pulling in dependencies internal to your company, at some point you'll want to integrate with styles delivered via NPM! The resolution logic for `@block`s to `node_modules` hasn't yet been implemented yet, but you can track progress (or even help out!) [over on Github](https://github.com/linkedin/css-blocks/issues/112).
325325
326326
With the above code, `block-2` now has a local reference `other-block` which points to `block-1`. We can now freely use the `other-block` identifier inside of `block-2` when we want to reference reference `block-1`. This comes in handy! Especially with features like:
327327

@@ -341,7 +341,7 @@ You do this via the special `implements` property in a Block's `:scope` selector
341341

342342
```css
343343
/* block-2.block.css */
344-
@block-reference other-block from "./block-1.block.css";
344+
@block other-block from "./block-1.block.css";
345345

346346
:scope {
347347
block-name: block-2;
@@ -363,7 +363,7 @@ For the build to pass, we need to implement the *full public interface* of `bloc
363363

364364
```css
365365
/* block-2.block.css */
366-
@block-reference other-block from "./block-1.block.css";
366+
@block other-block from "./block-1.block.css";
367367

368368
:scope {
369369
block-name: block-2;
@@ -403,7 +403,7 @@ Instead, we can simply extend the `<basic-form>` Block, and only apply the small
403403

404404
```css
405405
/* danger-form.block.css */
406-
@block-reference basic-form from "./basic-form.block.css";
406+
@block basic-form from "./basic-form.block.css";
407407

408408
:scope { extends: basic-form; }
409409
.button { background-color: darkred; }
@@ -465,7 +465,7 @@ Block Paths take the form:
465465
block.class[state|name='value']
466466
```
467467

468-
All sections of this selector – except the leading Block name – are optional. The leading Block name *must* refer to an imported `@block-reference` at the top of the file. If css-blocks is unable to resolve a Block Path at build time, you will get a friendly error message in your console!
468+
All sections of this selector – except the leading Block name – are optional. The leading Block name *must* refer to an imported `@block` at the top of the file. If css-blocks is unable to resolve a Block Path at build time, you will get a friendly error message in your console!
469469

470470
All the following syntaxes are legal to select any given stylable on a referenced Block:
471471

@@ -509,7 +509,7 @@ For Glimmer, using multiple blocks in a single template will look something like
509509

510510
```css
511511
/* stylesheet.css */
512-
@block-reference other from "./hoverable.css";
512+
@block other from "./hoverable.css";
513513

514514
:scope { block-name: main; }
515515
.form {
@@ -679,7 +679,7 @@ So, for the following two Blocks where `my-class-1[state|enabled]` and `my-class
679679
```css
680680
/* main.css */
681681

682-
@block-reference other from "./other.css";
682+
@block other from "./other.css";
683683

684684
.my-class-2::before {
685685
border-width: 2px;
@@ -724,7 +724,7 @@ This is most useful for global application states – like during initial applic
724724
```css
725725
/* navigation.block.css */
726726

727-
@block-reference app from "application.block.css";
727+
@block app from "application.block.css";
728728

729729
/* Gray out signout button when app is saving */
730730
app[state|is-saving] .signout {

0 commit comments

Comments
 (0)
Please sign in to comment.