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:
Yiffy Dev 2024-11-04 22:06:29 +05:00 • committed by spushk
commit 40e4d368cf
Signed by: spushk
GPG key ID: 7797B761E105E8AA
10 changed files with 50 additions and 50 deletions

View file

@ -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. 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 ```rust
sabry::sassy!(tokens {"@mixin colored{color: red;}"}); sabry::scssy!(tokens {"@mixin colored{color: red;}"});
``` ```
</td> </td>
@ -146,10 +146,10 @@ sabry = {version = "0.0.1"}
And a proc-macro And a proc-macro
```rust ```rust
// lib.rs // lib.rs
use sabry::sassy; use sabry::scssy;
sassy!(mixins "tests/assets/mixin-module.scss"); scssy!(mixins "tests/assets/mixin-module.scss");
sassy!(styles {" scssy!(styles {"
$primary-color: black; $primary-color: black;
@mixin colored($col: primary) { @mixin colored($col: primary) {
@if $col == primary { @if $col == primary {
@ -290,7 +290,7 @@ use leptos::prelude::*;
use sabry::styly; use sabry::styly;
styly!(scope {" 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'; @use 'tokens';
h1 { h1 {
@include tokens.sectionhead(); @include tokens.sectionhead();
@ -427,9 +427,9 @@ For example `{ie = "9", saf_ios = "13.2"}` will try to generate CSS supported on
## Detailed guide ## 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 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: Examples:
```rust ```rust
use sabry::sassy; use sabry::scssy;
sassy!(module1 {"$primary-color: red;"}); scssy!(module1 {"$primary-color: red;"});
sassy!(module2 "tests/assets/mixin-module.scss"); scssy!(module2 "tests/assets/mixin-module.scss");
sassy!(module3:sass "tests/assets/mixin-module.sass"); scssy!(module3:sass "tests/assets/mixin-module.sass");
// works, but there are catches. // works, but there are catches.
sassy!(module4:sass {" scssy!(module4:sass {"
@mixin colored($col: primary) @mixin colored($col: primary)
@if $col == primary @if $col == primary
color: white color: white
@ -457,7 +457,7 @@ sassy!(module4:sass {"
You may omit the syntax specifier - sabry uses SCSS as the default one. 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. > 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 ### Scoping

View file

@ -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) { @mixin flex($direction, $align, $justify, $gap: .5rem) {
display: flex; display: flex;
list-style: none; list-style: none;
@ -31,7 +31,7 @@ sassy!(utils {"
} }
"}); "});
sassy!(theme {" scssy!(theme {"
$thm-surface-primary: #2b2a29; $thm-surface-primary: #2b2a29;
$thm-surface-secondary: #6C6C6C; $thm-surface-secondary: #6C6C6C;
$thm-surface-tertiary: #4C4C4C; $thm-surface-tertiary: #4C4C4C;
@ -77,7 +77,7 @@ sassy!(theme {"
} }
"}); "});
sassy!(tokens {" scssy!(tokens {"
@use 'theme'; @use 'theme';
@mixin clickable($style: accent, $scale: 1.2, $clickscale: 0.9){ @mixin clickable($style: accent, $scale: 1.2, $clickscale: 0.9){

View file

@ -1,9 +1,9 @@
use define_styles::{theme, tokens, utils as utils_dup}; 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 // This module will have the same name as define_styles_example::utils
// and sabry is configured to merge them // and sabry is configured to merge them
sassy!(utils {" scssy!(utils {"
@mixin nonclickable(){ @mixin nonclickable(){
display: none; display: none;
} }

View file

@ -34,7 +34,7 @@ type BuilderResult = Result<(), SabryBuildError>;
/// ).expect("Sabry failed to build CSS"); /// ).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 /// ```ignore
/// buildy( /// buildy(
/// sabry::usey!( /// sabry::usey!(

View file

@ -2,7 +2,7 @@
use proc_macro::TokenStream; use proc_macro::TokenStream;
use sabry_procmacro_impl::impls::{ 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. /// Macro that makes sass code rusty.
@ -13,28 +13,28 @@ use sabry_procmacro_impl::impls::{
/// ## Usage /// ## Usage
/// ///
/// ```ignore /// ```ignore
/// sassy!(scssmodule { /// scssy!(scssmodule {
/// /* SCSS */ /// /* SCSS */
/// }); /// });
/// sassy!(sassmodule:sass { /// scssy!(sassmodule:sass {
/// /* SASS (WIP) */ /// /* SASS (WIP) */
/// }); /// });
/// sassy!(scssmod2:scss { /// scssy!(scssmod2:scss {
/// /* SCSS */ /// /* SCSS */
/// }); /// });
/// ``` /// ```
/// Or read code from file /// Or read code from file
/// ```ignore /// ```ignore
/// sassy!(filemodule "src/styles/a.scss"); /// scssy!(filemodule "src/styles/a.scss");
/// sassy!(filemodule:sass "src/styles/b.sass"); /// scssy!(filemodule:sass "src/styles/b.sass");
/// ``` /// ```
/// ///
/// \[SCSS syntax requires 'scss' feature\] /// \[SCSS syntax requires 'scss' feature\]
/// \[SASS syntax requires 'sass' feature (WIP)\] /// \[SASS syntax requires 'sass' feature (WIP)\]
/// ///
#[proc_macro] #[proc_macro]
pub fn sassy(input: TokenStream) -> TokenStream { pub fn scssy(input: TokenStream) -> TokenStream {
sassy_macro_impl(input.into()).into() scssy_macro_impl(input.into()).into()
} }
/// Macro that brings sass code into app /// Macro that brings sass code into app

View file

@ -1,8 +1,8 @@
use std::{collections::HashSet, fs}; use std::{collections::HashSet, fs};
use sabry_procmacro::{sassy, usey}; use sabry_procmacro::{scssy, usey};
sassy!(scmod:scss {" scssy!(scmod:scss {"
@mixin abc(){ @mixin abc(){
color: red; color: red;
} }
@ -10,18 +10,18 @@ sassy!(scmod:scss {"
@include abc; @include abc;
} }
"}); "});
sassy!(samod:sass {" scssy!(samod:sass {"
@mixin abc() @mixin abc()
color: green color: green
.sel1 .sel1
@include abc @include abc
"}); "});
sassy!(scmicromod:scss "sabry_procmacro/tests/scmicro.scss"); scssy!(scmicromod:scss "sabry_procmacro/tests/scmicro.scss");
sassy!(samicromod:sass "sabry_procmacro/tests/samicro.sass"); scssy!(samicromod:sass "sabry_procmacro/tests/samicro.sass");
#[test] #[test]
fn sassy_contract() { fn scssy_contract() {
assert_eq!(scmod!(syntax), "scss"); assert_eq!(scmod!(syntax), "scss");
assert_eq!( assert_eq!(
scmod!(), scmod!(),

View file

@ -6,7 +6,7 @@ use regex::Regex;
use sabry_intrnl::syntax::ostrta::OneSyntaxToRuleThemAll; use sabry_intrnl::syntax::ostrta::OneSyntaxToRuleThemAll;
use syn::{braced, parse::Parse, Ident, LitStr, Token}; use syn::{braced, parse::Parse, Ident, LitStr, Token};
pub mod sassy; pub mod scssy;
pub mod styly; pub mod styly;
pub mod usey; pub mod usey;

View 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 {}

View file

@ -32,7 +32,7 @@ impl StyleCall {
let call_code = &self.call; let call_code = &self.call;
let call_path = &self.call.path; let call_path = &self.call.path;
let call_bang = &self.call.bang_token; 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 call_syntax = quote! {#call_path #call_bang (syntax)};
let module_name = call_path let module_name = call_path

View file

@ -1,10 +1,10 @@
use sabry::styly; use sabry::styly;
pub mod sass { pub mod sass {
use sabry::sassy; use sabry::scssy;
sassy!(mixins_sass:sass "tests/assets/mixin-module.sass"); scssy!(mixins_sass:sass "tests/assets/mixin-module.sass");
sassy!(mixins_inline_sass:sass {" scssy!(mixins_inline_sass:sass {"
@mixin color($color: black) @mixin color($color: black)
@if $color == black @if $color == black
color: white color: white
@ -24,8 +24,8 @@ pub mod sass {
&:hover &:hover
transform: translateX(10%) transform: translateX(10%)
"}); "});
sassy!(module_sass:sass "tests/assets/module-forward.sass"); scssy!(module_sass:sass "tests/assets/module-forward.sass");
sassy!(module_inline_sass:sass {" scssy!(module_inline_sass:sass {"
@forward 'mixins_a' @forward 'mixins_a'
@forward 'mixins_c' @forward 'mixins_c'
"}); "});
@ -36,10 +36,10 @@ pub mod sass {
} }
pub mod scss { pub mod scss {
use sabry::sassy; use sabry::scssy;
sassy!(mixins_scss:scss "tests/assets/mixin-module.scss"); scssy!(mixins_scss:scss "tests/assets/mixin-module.scss");
sassy!(mixins_inline_scss:scss {" scssy!(mixins_inline_scss:scss {"
@mixin surface($color: black){ @mixin surface($color: black){
@if $color == black{ @if $color == black{
color: white; color: white;
@ -64,8 +64,8 @@ pub mod scss {
} }
} }
"}); "});
sassy!(module_scss:scss "tests/assets/module-forward.scss"); scssy!(module_scss:scss "tests/assets/module-forward.scss");
sassy!(module_inline_scss:scss {" scssy!(module_inline_scss:scss {"
@forward 'mixins_a'; @forward 'mixins_a';
@forward 'mixins_c'; @forward 'mixins_c';
"}); "});