Skip to content

Commit

Permalink
Feature: ftd.ui variable reference
Browse files Browse the repository at this point in the history
  • Loading branch information
Arpita-Jaiswal committed Mar 2, 2023
1 parent 5efa27c commit 0dbd5a0
Show file tree
Hide file tree
Showing 3 changed files with 1,893 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ftd/src/interpreter2/things/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,22 @@ impl PropertyValue {
value: ftd::ast::VariableValue,
doc: &mut ftd::interpreter2::TDoc,
definition_name_with_arguments: Option<(&str, &[ftd::interpreter2::Argument])>,
loop_object_name_and_kind: &Option<(String, ftd::interpreter2::Argument)>,
) -> ftd::interpreter2::Result<
ftd::interpreter2::StateWithThing<ftd::interpreter2::PropertyValue>,
> {
let line_number = value.line_number();

if key.eq("ftd.ui") {
return ftd::interpreter2::PropertyValue::from_ast_value_with_argument(
value,
doc,
false,
Some(&ftd::interpreter2::Kind::ui().into_kind_data()),
definition_name_with_arguments,
loop_object_name_and_kind,
);
}
let ast_component = ftd::ast::Component::from_variable_value(key, value, doc.name)?;
let component = try_ok_state!(ftd::interpreter2::Component::from_ast_component(
ast_component,
Expand Down Expand Up @@ -779,6 +791,7 @@ impl PropertyValue {
value,
doc,
definition_name_with_arguments,
loop_object_name_and_kind
)?)
} else {
try_ok_state!(PropertyValue::from_ast_value(
Expand Down Expand Up @@ -1608,6 +1621,21 @@ impl Value {
}
}

pub fn ui(
&self,
doc_id: &str,
line_number: usize,
) -> ftd::interpreter2::Result<ftd::interpreter2::Component> {
match self {
ftd::interpreter2::Value::UI { component, .. } => Ok(component.to_owned()),
t => ftd::interpreter2::utils::e2(
format!("Expected UI, found: `{:?}`", t),
doc_id,
line_number,
),
}
}

pub fn optional_string(
&self,
doc_id: &str,
Expand Down
18 changes: 18 additions & 0 deletions ftd/t/html/75-ui-list-display.ftd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- ftd.ui list uis:

-- ftd.text: Hello

-- ftd.column:
-- ftd.text: Column Hello
-- end: ftd.column

-- end: uis


-- ftd.column:
-- ftd.column.children:

-- ftd.ui: $uis.1

-- end: ftd.column.children
-- end: ftd.column
Loading

0 comments on commit 0dbd5a0

Please sign in to comment.