diff --git a/fastn-type/src/component.rs b/fastn-type/src/component.rs index 5cadc53d6..7b9ac9438 100644 --- a/fastn-type/src/component.rs +++ b/fastn-type/src/component.rs @@ -36,6 +36,22 @@ pub struct Loop { pub line_number: usize, } +impl Loop { + pub fn new( + on: fastn_type::PropertyValue, + alias: &str, + loop_counter_alias: Option, + line_number: usize, + ) -> fastn_type::Loop { + fastn_type::Loop { + on, + alias: alias.to_string(), + line_number, + loop_counter_alias, + } + } +} + #[derive(Debug, Clone, PartialEq, Default, serde::Deserialize, serde::Serialize)] pub enum ComponentSource { #[default] @@ -117,4 +133,22 @@ pub struct ComponentDefinition { pub line_number: usize, } +impl fastn_type::ComponentDefinition { + pub fn new( + name: &str, + arguments: Vec, + definition: fastn_type::Component, + css: Option, + line_number: usize, + ) -> fastn_type::ComponentDefinition { + fastn_type::ComponentDefinition { + name: name.to_string(), + arguments, + definition, + css, + line_number, + } + } +} + pub type Argument = fastn_type::Field; diff --git a/ftd/src/executor/element.rs b/ftd/src/executor/element.rs index 3314047ec..922bf60fb 100644 --- a/ftd/src/executor/element.rs +++ b/ftd/src/executor/element.rs @@ -302,7 +302,7 @@ impl ImageSrc { .resolve(&doc.itdoc(), line_number)? .string(doc.name, line_number)?, Some(line_number), - vec![value.into_property(fastn_type::PropertySource::header("light"))], + vec![value.to_property(fastn_type::PropertySource::header("light"))], ) }; @@ -314,7 +314,7 @@ impl ImageSrc { .resolve(&doc.itdoc(), line_number)? .string(doc.name, line_number)?, Some(line_number), - vec![value.into_property(fastn_type::PropertySource::header("dark"))], + vec![value.to_property(fastn_type::PropertySource::header("dark"))], ) } else { light.clone() @@ -405,7 +405,7 @@ impl RawImage { .resolve(&doc.itdoc(), line_number)? .string(doc.name, line_number)?, Some(line_number), - vec![value.into_property(fastn_type::PropertySource::header("src"))], + vec![value.to_property(fastn_type::PropertySource::header("src"))], ) }; diff --git a/ftd/src/executor/fastn_type_functions.rs b/ftd/src/executor/fastn_type_functions.rs index 9df4c8f4f..9a926e296 100644 --- a/ftd/src/executor/fastn_type_functions.rs +++ b/ftd/src/executor/fastn_type_functions.rs @@ -1,9 +1,9 @@ pub(crate) trait PropertyValueExt { - fn into_property(&self, source: fastn_type::PropertySource) -> fastn_type::Property; + fn to_property(&self, source: fastn_type::PropertySource) -> fastn_type::Property; } impl PropertyValueExt for fastn_type::PropertyValue { - fn into_property(&self, source: fastn_type::PropertySource) -> fastn_type::Property { + fn to_property(&self, source: fastn_type::PropertySource) -> fastn_type::Property { fastn_type::Property { value: self.clone(), source, diff --git a/ftd/src/executor/styles.rs b/ftd/src/executor/styles.rs index 28b1620f7..a2a9b7abc 100644 --- a/ftd/src/executor/styles.rs +++ b/ftd/src/executor/styles.rs @@ -482,7 +482,7 @@ impl BreakpointWidth { .integer(doc.name, line_number)?, Some(line_number), vec![get_property_value("mobile")? - .into_property(fastn_type::PropertySource::header("mobile"))], + .to_property(fastn_type::PropertySource::header("mobile"))], ); Ok(BreakpointWidth { mobile }) @@ -955,9 +955,7 @@ impl BackgroundImage { line_number, )?, Some(line_number), - vec![ - get_property_value("src")?.into_property(fastn_type::PropertySource::header("src")) - ], + vec![get_property_value("src")?.to_property(fastn_type::PropertySource::header("src"))], ); let repeat = ftd::executor::Value::new( @@ -968,7 +966,7 @@ impl BackgroundImage { )?, Some(line_number), vec![get_property_value("repeat")? - .into_property(fastn_type::PropertySource::header("repeat"))], + .to_property(fastn_type::PropertySource::header("repeat"))], ); let size = ftd::executor::Value::new( @@ -978,8 +976,9 @@ impl BackgroundImage { line_number, )?, Some(line_number), - vec![get_property_value("size")? - .into_property(fastn_type::PropertySource::header("size"))], + vec![ + get_property_value("size")?.to_property(fastn_type::PropertySource::header("size")) + ], ); let position = ftd::executor::Value::new( @@ -990,7 +989,7 @@ impl BackgroundImage { )?, Some(line_number), vec![get_property_value("position")? - .into_property(fastn_type::PropertySource::header("position"))], + .to_property(fastn_type::PropertySource::header("position"))], ); Ok(ftd::executor::BackgroundImage { @@ -1139,7 +1138,7 @@ impl LinearGradientColor { )?, Some(line_number), vec![get_property_value("start")? - .into_property(fastn_type::PropertySource::header("start"))], + .to_property(fastn_type::PropertySource::header("start"))], ); let end = ftd::executor::Value::new( @@ -1149,9 +1148,7 @@ impl LinearGradientColor { line_number, )?, Some(line_number), - vec![ - get_property_value("end")?.into_property(fastn_type::PropertySource::header("end")) - ], + vec![get_property_value("end")?.to_property(fastn_type::PropertySource::header("end"))], ); let stop_position = ftd::executor::Value::new( @@ -1162,7 +1159,7 @@ impl LinearGradientColor { )?, Some(line_number), vec![get_property_value("stop-position")? - .into_property(fastn_type::PropertySource::header("stop-position"))], + .to_property(fastn_type::PropertySource::header("stop-position"))], ); Ok(ftd::executor::LinearGradientColor { @@ -1353,7 +1350,7 @@ impl LinearGradient { )?, Some(line_number), vec![get_property_value("direction")? - .into_property(fastn_type::PropertySource::header("direction"))], + .to_property(fastn_type::PropertySource::header("direction"))], ); let colors = ftd::executor::Value::new( @@ -1364,7 +1361,7 @@ impl LinearGradient { )?, Some(line_number), vec![get_property_value("colors")? - .into_property(fastn_type::PropertySource::header("colors"))], + .to_property(fastn_type::PropertySource::header("colors"))], ); Ok(ftd::executor::LinearGradient { direction, colors }) @@ -1841,35 +1838,36 @@ impl Shadow { Length::from_value(get_property_value("x-offset")?.clone(), doc, line_number)?, Some(line_number), vec![get_property_value("x-offset")? - .into_property(fastn_type::PropertySource::header("x-offset"))], + .to_property(fastn_type::PropertySource::header("x-offset"))], ); let y_offset = ftd::executor::Value::new( Length::from_value(get_property_value("y-offset")?.clone(), doc, line_number)?, Some(line_number), vec![get_property_value("y-offset")? - .into_property(fastn_type::PropertySource::header("y-offset"))], + .to_property(fastn_type::PropertySource::header("y-offset"))], ); let blur = ftd::executor::Value::new( Length::from_value(get_property_value("blur")?.clone(), doc, line_number)?, Some(line_number), - vec![get_property_value("blur")? - .into_property(fastn_type::PropertySource::header("blur"))], + vec![ + get_property_value("blur")?.to_property(fastn_type::PropertySource::header("blur")) + ], ); let spread = ftd::executor::Value::new( Length::from_value(get_property_value("spread")?.clone(), doc, line_number)?, Some(line_number), vec![get_property_value("spread")? - .into_property(fastn_type::PropertySource::header("spread"))], + .to_property(fastn_type::PropertySource::header("spread"))], ); let color = ftd::executor::Value::new( Color::from_value(get_property_value("color")?.clone(), doc, line_number)?, Some(line_number), vec![get_property_value("color")? - .into_property(fastn_type::PropertySource::header("color"))], + .to_property(fastn_type::PropertySource::header("color"))], ); let inset = ftd::executor::Value::new( @@ -1879,7 +1877,7 @@ impl Shadow { .bool(doc.name, line_number)?, Some(line_number), vec![get_property_value("inset")? - .into_property(fastn_type::PropertySource::header("inset"))], + .to_property(fastn_type::PropertySource::header("inset"))], ); Ok(ftd::executor::Shadow { @@ -2022,7 +2020,7 @@ impl Color { line_number, )?, Some(line_number), - vec![value.into_property(fastn_type::PropertySource::header("light"))], + vec![value.to_property(fastn_type::PropertySource::header("light"))], ) }; @@ -2038,7 +2036,7 @@ impl Color { line_number, )?, Some(line_number), - vec![value.into_property(fastn_type::PropertySource::header("dark"))], + vec![value.to_property(fastn_type::PropertySource::header("dark"))], ) } else { light.clone() diff --git a/ftd/src/interpreter/things/component.rs b/ftd/src/interpreter/things/component.rs index bbd848b9e..637a43eda 100644 --- a/ftd/src/interpreter/things/component.rs +++ b/ftd/src/interpreter/things/component.rs @@ -3,13 +3,6 @@ use ftd::interpreter::things::function::FunctionCallExt; use ftd::interpreter::things::record::FieldExt; pub trait ComponentDefinitionExt { - fn new( - name: &str, - arguments: Vec, - definition: fastn_type::Component, - css: Option, - line_number: usize, - ) -> fastn_type::ComponentDefinition; fn scan_ast( ast: ftd_ast::Ast, doc: &mut ftd::interpreter::TDoc, @@ -22,22 +15,6 @@ pub trait ComponentDefinitionExt { } impl ComponentDefinitionExt for fastn_type::ComponentDefinition { - fn new( - name: &str, - arguments: Vec, - definition: fastn_type::Component, - css: Option, - line_number: usize, - ) -> fastn_type::ComponentDefinition { - fastn_type::ComponentDefinition { - name: name.to_string(), - arguments, - definition, - css, - line_number, - } - } - fn scan_ast( ast: ftd_ast::Ast, doc: &mut ftd::interpreter::TDoc, @@ -1019,8 +996,8 @@ pub trait ComponentExt { condition: &Option, loop_object_name_and_kind: &Option<(String, fastn_type::Argument, Option)>, events: &[fastn_type::Event], - ast_properties: &Vec, - ast_children: &Vec, + ast_properties: &[ftd_ast::Property], + ast_children: &[ftd_ast::ComponentInvocation], line_number: usize, ) -> ftd::interpreter::Result>>; } @@ -1352,8 +1329,8 @@ impl ComponentExt for fastn_type::Component { condition: &Option, loop_object_name_and_kind: &Option<(String, fastn_type::Argument, Option)>, events: &[fastn_type::Event], - ast_properties: &Vec, - ast_children: &Vec, + ast_properties: &[ftd_ast::Property], + ast_children: &[ftd_ast::ComponentInvocation], line_number: usize, ) -> ftd::interpreter::Result>> { @@ -1455,12 +1432,6 @@ impl ComponentExt for fastn_type::Component { } pub trait LoopExt { - fn new( - on: fastn_type::PropertyValue, - alias: &str, - loop_counter_alias: Option, - line_number: usize, - ) -> fastn_type::Loop; fn from_ast_loop( ast_loop: ftd_ast::Loop, definition_name_with_arguments: &mut Option<(&str, &mut [fastn_type::Argument])>, @@ -1483,19 +1454,6 @@ pub trait LoopExt { } impl LoopExt for fastn_type::Loop { - fn new( - on: fastn_type::PropertyValue, - alias: &str, - loop_counter_alias: Option, - line_number: usize, - ) -> fastn_type::Loop { - fastn_type::Loop { - on, - alias: alias.to_string(), - line_number, - loop_counter_alias, - } - } fn from_ast_loop( ast_loop: ftd_ast::Loop, definition_name_with_arguments: &mut Option<(&str, &mut [fastn_type::Argument])>,