-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #600 from Sharktheone/css/attr-function
Implement some css function, most notably `attr()`
- Loading branch information
Showing
9 changed files
with
176 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
pub use attr::*; | ||
pub use calc::*; | ||
pub use var::*; | ||
|
||
mod attr; | ||
mod calc; | ||
mod var; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use gosub_css3::stylesheet::CssValue; | ||
use gosub_html5::node::Node; | ||
|
||
pub fn resolve_attr(values: &[CssValue], node: &Node) -> Vec<CssValue> { | ||
let Some(attr_name) = values.first().map(|v| v.to_string()) else { | ||
return vec![]; | ||
}; | ||
|
||
let ty = values.get(1).cloned(); | ||
|
||
let Some(attr_value) = node.get_attribute(&attr_name) else { | ||
let _default_value = values.get(2).cloned(); | ||
|
||
if let Some(ty) = ty { | ||
return vec![ty]; | ||
} | ||
|
||
return vec![]; | ||
}; | ||
|
||
let Ok(value) = CssValue::parse_str(attr_value) else { | ||
return vec![]; | ||
}; | ||
|
||
vec![value] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use gosub_css3::stylesheet::CssValue; | ||
|
||
pub fn resolve_calc(_values: &[CssValue]) -> Vec<CssValue> { | ||
todo!() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use std::collections::HashMap; | ||
|
||
use gosub_css3::stylesheet::CssValue; | ||
use gosub_html5::node::Node; | ||
use gosub_html5::parser::document::Document; | ||
|
||
#[derive(Clone, Debug, Default)] | ||
pub struct VariableEnvironment { | ||
pub values: HashMap<String, CssValue>, | ||
} | ||
|
||
impl VariableEnvironment { | ||
pub fn get(&self, name: &str, _doc: &Document, _node: &Node) -> Option<CssValue> { | ||
let mut current = Some(self); | ||
|
||
while let Some(env) = current { | ||
if let Some(value) = env.values.get(name) { | ||
return Some(value.clone()); | ||
} | ||
|
||
current = None; | ||
|
||
//TODO: give node a variable env | ||
// let node = doc.get_parent(node); | ||
// current = node.get_variable_env(); | ||
} | ||
|
||
None | ||
} | ||
} | ||
|
||
pub fn resolve_var(values: &[CssValue], doc: &Document, node: &Node) -> Vec<CssValue> { | ||
let Some(name) = values.first().map(|v| { | ||
let mut str = v.to_string(); | ||
|
||
if str.starts_with("--") { | ||
str.remove(0); | ||
str.remove(0); | ||
} | ||
|
||
str | ||
}) else { | ||
return vec![]; | ||
}; | ||
|
||
// let environment = doc.get_variable_env(node); | ||
|
||
let environment = VariableEnvironment::default(); //TODO: get from node | ||
|
||
let Some(value) = environment.get(&name, doc, node) else { | ||
let Some(default) = values.get(1).cloned() else { | ||
return vec![]; | ||
}; | ||
|
||
return vec![default]; | ||
}; | ||
|
||
vec![value.clone()] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters