fix: found that macro name was nasty. Also my team starts a production with sabry, so lets call it release
This commit is contained in:
parent
4fa26061ee
commit
fc432ddde0
10 changed files with 50 additions and 50 deletions
28
README.md
28
README.md
|
|
@ -25,7 +25,7 @@ At first, I'll show how this crate "tastes". With SABRY, its in your power to:
|
|||
Write arbitrary SASS/SCSS code and ship it *as a crate* however you please: with modules, with feature flags, etc. Say "bye" to manual copying, cli-tools and consts.
|
||||
|
||||
```rust
|
||||
sabry::sassy!(tokens {"@mixin colored{color: red;}"});
|
||||
sabry::scssy!(tokens {"@mixin colored{color: red;}"});
|
||||
```
|
||||
|
||||
</td>
|
||||
|
|
@ -146,10 +146,10 @@ sabry = {version = "0.0.1"}
|
|||
And a proc-macro
|
||||
```rust
|
||||
// lib.rs
|
||||
use sabry::sassy;
|
||||
use sabry::scssy;
|
||||
|
||||
sassy!(mixins "tests/assets/mixin-module.scss");
|
||||
sassy!(styles {"
|
||||
scssy!(mixins "tests/assets/mixin-module.scss");
|
||||
scssy!(styles {"
|
||||
$primary-color: black;
|
||||
@mixin colored($col: primary) {
|
||||
@if $col == primary {
|
||||
|
|
@ -290,7 +290,7 @@ use leptos::prelude::*;
|
|||
use sabry::styly;
|
||||
|
||||
styly!(scope {"
|
||||
// assuming we have tokens!() macro generated by `sassy!`, which is handled by `buildy`
|
||||
// assuming we have tokens!() macro generated by `scssy!`, which is handled by `buildy`
|
||||
@use 'tokens';
|
||||
h1 {
|
||||
@include tokens.sectionhead();
|
||||
|
|
@ -427,9 +427,9 @@ For example `{ie = "9", saf_ios = "13.2"}` will try to generate CSS supported on
|
|||
|
||||
## Detailed guide
|
||||
|
||||
### Style definition with `sassy!`
|
||||
### Style definition with `scssy!`
|
||||
|
||||
The `sassy!` macro is available with *procmacro* feature which is enabled by default.
|
||||
The `scssy!` macro is available with *procmacro* feature which is enabled by default.
|
||||
|
||||
It does accept the following syntax: `$name(:$syntax)? ({ $code })|($filename)`, where
|
||||
|
||||
|
|
@ -440,13 +440,13 @@ It does accept the following syntax: `$name(:$syntax)? ({ $code })|($filename)`,
|
|||
|
||||
Examples:
|
||||
```rust
|
||||
use sabry::sassy;
|
||||
use sabry::scssy;
|
||||
|
||||
sassy!(module1 {"$primary-color: red;"});
|
||||
sassy!(module2 "tests/assets/mixin-module.scss");
|
||||
sassy!(module3:sass "tests/assets/mixin-module.sass");
|
||||
scssy!(module1 {"$primary-color: red;"});
|
||||
scssy!(module2 "tests/assets/mixin-module.scss");
|
||||
scssy!(module3:sass "tests/assets/mixin-module.sass");
|
||||
// works, but there are catches.
|
||||
sassy!(module4:sass {"
|
||||
scssy!(module4:sass {"
|
||||
@mixin colored($col: primary)
|
||||
@if $col == primary
|
||||
color: white
|
||||
|
|
@ -457,7 +457,7 @@ sassy!(module4:sass {"
|
|||
|
||||
You may omit the syntax specifier - sabry uses SCSS as the default one.
|
||||
|
||||
The given code to `sassy!` is not checked to be valid code in given syntax (wip).
|
||||
The given code to `scssy!` is not checked to be valid code in given syntax (wip).
|
||||
|
||||
> SASS support inside of rust files is experimental. If you do want to use SASS tabbed syntax - consider to use files path instead of sass-in-rust option.
|
||||
|
||||
|
|
@ -590,7 +590,7 @@ sabry::buildy(
|
|||
)?;
|
||||
```
|
||||
|
||||
Exactly this kind of macros is produced by [`sassy!`](#style-definition-with-sassy).
|
||||
Exactly this kind of macros is produced by [`scssy!`](#style-definition-with-scssy).
|
||||
|
||||
### Scoping
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use sabry::sassy;
|
||||
use sabry::scssy;
|
||||
|
||||
sassy!(style "src/style.scss");
|
||||
scssy!(style "src/style.scss");
|
||||
|
||||
sassy!(utils {"
|
||||
scssy!(utils {"
|
||||
@mixin flex($direction, $align, $justify, $gap: .5rem) {
|
||||
display: flex;
|
||||
list-style: none;
|
||||
|
|
@ -31,7 +31,7 @@ sassy!(utils {"
|
|||
}
|
||||
"});
|
||||
|
||||
sassy!(theme {"
|
||||
scssy!(theme {"
|
||||
$thm-surface-primary: #2b2a29;
|
||||
$thm-surface-secondary: #6C6C6C;
|
||||
$thm-surface-tertiary: #4C4C4C;
|
||||
|
|
@ -77,7 +77,7 @@ sassy!(theme {"
|
|||
}
|
||||
"});
|
||||
|
||||
sassy!(tokens {"
|
||||
scssy!(tokens {"
|
||||
@use 'theme';
|
||||
|
||||
@mixin clickable($style: accent, $scale: 1.2, $clickscale: 0.9){
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use define_styles::{theme, tokens, utils as utils_dup};
|
||||
use sabry::{sassy, usey};
|
||||
use sabry::{scssy, usey};
|
||||
|
||||
// This module will have the same name as define_styles_example::utils
|
||||
// and sabry is configured to merge them
|
||||
sassy!(utils {"
|
||||
scssy!(utils {"
|
||||
@mixin nonclickable(){
|
||||
display: none;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ type BuilderResult = Result<(), SabryBuildError>;
|
|||
/// ).expect("Sabry failed to build CSS");
|
||||
/// ```
|
||||
///
|
||||
/// Also you could use style-macros defined anywhere with `sabry::sassy!` procmacro:
|
||||
/// Also you could use style-macros defined anywhere with `sabry::scssy!` procmacro:
|
||||
/// ```ignore
|
||||
/// buildy(
|
||||
/// sabry::usey!(
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use proc_macro::TokenStream;
|
||||
use sabry_procmacro_impl::impls::{
|
||||
sassy::sassy_macro_impl, styly::styly_macro_impl, usey::usey_macro_impl,
|
||||
scssy::scssy_macro_impl, styly::styly_macro_impl, usey::usey_macro_impl,
|
||||
};
|
||||
|
||||
/// Macro that makes sass code rusty.
|
||||
|
|
@ -13,28 +13,28 @@ use sabry_procmacro_impl::impls::{
|
|||
/// ## Usage
|
||||
///
|
||||
/// ```ignore
|
||||
/// sassy!(scssmodule {
|
||||
/// scssy!(scssmodule {
|
||||
/// /* SCSS */
|
||||
/// });
|
||||
/// sassy!(sassmodule:sass {
|
||||
/// scssy!(sassmodule:sass {
|
||||
/// /* SASS (WIP) */
|
||||
/// });
|
||||
/// sassy!(scssmod2:scss {
|
||||
/// scssy!(scssmod2:scss {
|
||||
/// /* SCSS */
|
||||
/// });
|
||||
/// ```
|
||||
/// Or read code from file
|
||||
/// ```ignore
|
||||
/// sassy!(filemodule "src/styles/a.scss");
|
||||
/// sassy!(filemodule:sass "src/styles/b.sass");
|
||||
/// scssy!(filemodule "src/styles/a.scss");
|
||||
/// scssy!(filemodule:sass "src/styles/b.sass");
|
||||
/// ```
|
||||
///
|
||||
/// \[SCSS syntax requires 'scss' feature\]
|
||||
/// \[SASS syntax requires 'sass' feature (WIP)\]
|
||||
///
|
||||
#[proc_macro]
|
||||
pub fn sassy(input: TokenStream) -> TokenStream {
|
||||
sassy_macro_impl(input.into()).into()
|
||||
pub fn scssy(input: TokenStream) -> TokenStream {
|
||||
scssy_macro_impl(input.into()).into()
|
||||
}
|
||||
|
||||
/// Macro that brings sass code into app
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::{collections::HashSet, fs};
|
||||
|
||||
use sabry_procmacro::{sassy, usey};
|
||||
use sabry_procmacro::{scssy, usey};
|
||||
|
||||
sassy!(scmod:scss {"
|
||||
scssy!(scmod:scss {"
|
||||
@mixin abc(){
|
||||
color: red;
|
||||
}
|
||||
|
|
@ -10,18 +10,18 @@ sassy!(scmod:scss {"
|
|||
@include abc;
|
||||
}
|
||||
"});
|
||||
sassy!(samod:sass {"
|
||||
scssy!(samod:sass {"
|
||||
@mixin abc()
|
||||
color: green
|
||||
.sel1
|
||||
@include abc
|
||||
"});
|
||||
|
||||
sassy!(scmicromod:scss "sabry_procmacro/tests/scmicro.scss");
|
||||
sassy!(samicromod:sass "sabry_procmacro/tests/samicro.sass");
|
||||
scssy!(scmicromod:scss "sabry_procmacro/tests/scmicro.scss");
|
||||
scssy!(samicromod:sass "sabry_procmacro/tests/samicro.sass");
|
||||
|
||||
#[test]
|
||||
fn sassy_contract() {
|
||||
fn scssy_contract() {
|
||||
assert_eq!(scmod!(syntax), "scss");
|
||||
assert_eq!(
|
||||
scmod!(),
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use regex::Regex;
|
|||
use sabry_intrnl::syntax::ostrta::OneSyntaxToRuleThemAll;
|
||||
use syn::{braced, parse::Parse, Ident, LitStr, Token};
|
||||
|
||||
pub mod sassy;
|
||||
pub mod scssy;
|
||||
pub mod styly;
|
||||
pub mod usey;
|
||||
|
||||
|
|
|
|||
64
sabry_procmacro_impl/src/impls/scssy.rs
Normal file
64
sabry_procmacro_impl/src/impls/scssy.rs
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
use sabry_intrnl::scoper::ArbitraryScope;
|
||||
use syn::{parse::Parse, Ident};
|
||||
|
||||
use super::{ArbitraryStyleBlock, ArbitraryStyleSyntax};
|
||||
|
||||
/// Syntax:
|
||||
/// `#ident(:$syntax)? { $code }`
|
||||
///
|
||||
/// `$syntax`: sass/scss
|
||||
///
|
||||
/// `$code`: intended to be valid based on $syntax
|
||||
pub fn scssy_macro_impl(input: TokenStream) -> TokenStream {
|
||||
let MacroSyntax {
|
||||
ident,
|
||||
syntax: mode,
|
||||
code,
|
||||
} = match syn::parse2::<MacroSyntax>(input) {
|
||||
Ok(m) => m,
|
||||
Err(e) => return e.to_compile_error(),
|
||||
};
|
||||
|
||||
// quick raffia syntax check
|
||||
match ArbitraryScope::from_source(mode.0, ident.clone(), &code.code) {
|
||||
Ok(_) => {}
|
||||
Err(e) => return syn::Error::new(code.span, format!("{e:?}")).into_compile_error(),
|
||||
}
|
||||
|
||||
let sourcesass = code.to_string();
|
||||
let macro_doc = format!("Arbitrary {:?} code declared with `scssy!`. Pretty usable in tandem with `usey!` and `magic()` at build time", mode);
|
||||
|
||||
quote! {
|
||||
#[doc = #macro_doc]
|
||||
#[macro_export]
|
||||
macro_rules! #ident {
|
||||
() => {#sourcesass};
|
||||
(syntax) => {#mode};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MacroSyntax {
|
||||
ident: Ident,
|
||||
syntax: ArbitraryStyleSyntax,
|
||||
code: ArbitraryStyleBlock,
|
||||
}
|
||||
|
||||
impl Parse for MacroSyntax {
|
||||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||
let ident = input.parse::<Ident>()?;
|
||||
let mode = input.parse::<ArbitraryStyleSyntax>()?;
|
||||
let code = input.parse::<ArbitraryStyleBlock>()?;
|
||||
|
||||
Ok(Self {
|
||||
ident,
|
||||
syntax: mode,
|
||||
code,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {}
|
||||
|
|
@ -32,7 +32,7 @@ impl StyleCall {
|
|||
let call_code = &self.call;
|
||||
let call_path = &self.call.path;
|
||||
let call_bang = &self.call.bang_token;
|
||||
// the following calls are expected by macro genereted by `sassy!`
|
||||
// the following calls are expected by macro genereted by `scssy!`
|
||||
let call_syntax = quote! {#call_path #call_bang (syntax)};
|
||||
|
||||
let module_name = call_path
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
use sabry::styly;
|
||||
|
||||
pub mod sass {
|
||||
use sabry::sassy;
|
||||
use sabry::scssy;
|
||||
|
||||
sassy!(mixins_sass:sass "tests/assets/mixin-module.sass");
|
||||
sassy!(mixins_inline_sass:sass {"
|
||||
scssy!(mixins_sass:sass "tests/assets/mixin-module.sass");
|
||||
scssy!(mixins_inline_sass:sass {"
|
||||
@mixin color($color: black)
|
||||
@if $color == black
|
||||
color: white
|
||||
|
|
@ -24,8 +24,8 @@ pub mod sass {
|
|||
&:hover
|
||||
transform: translateX(10%)
|
||||
"});
|
||||
sassy!(module_sass:sass "tests/assets/module-forward.sass");
|
||||
sassy!(module_inline_sass:sass {"
|
||||
scssy!(module_sass:sass "tests/assets/module-forward.sass");
|
||||
scssy!(module_inline_sass:sass {"
|
||||
@forward 'mixins_a'
|
||||
@forward 'mixins_c'
|
||||
"});
|
||||
|
|
@ -36,10 +36,10 @@ pub mod sass {
|
|||
}
|
||||
|
||||
pub mod scss {
|
||||
use sabry::sassy;
|
||||
use sabry::scssy;
|
||||
|
||||
sassy!(mixins_scss:scss "tests/assets/mixin-module.scss");
|
||||
sassy!(mixins_inline_scss:scss {"
|
||||
scssy!(mixins_scss:scss "tests/assets/mixin-module.scss");
|
||||
scssy!(mixins_inline_scss:scss {"
|
||||
@mixin surface($color: black){
|
||||
@if $color == black{
|
||||
color: white;
|
||||
|
|
@ -64,8 +64,8 @@ pub mod scss {
|
|||
}
|
||||
}
|
||||
"});
|
||||
sassy!(module_scss:scss "tests/assets/module-forward.scss");
|
||||
sassy!(module_inline_scss:scss {"
|
||||
scssy!(module_scss:scss "tests/assets/module-forward.scss");
|
||||
scssy!(module_inline_scss:scss {"
|
||||
@forward 'mixins_a';
|
||||
@forward 'mixins_c';
|
||||
"});
|
||||
|
|
|
|||
Loading…
Reference in a new issue