Skip to content

Commit

Permalink
Array of values printing all indexes fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vrrashkov committed Jul 3, 2023
1 parent 68257b0 commit 155a6be
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "design_token_parser"
version = "3.1.0"
version = "3.1.1"
edition = "2021"
repository = "https://github.com/vrrashkov/TokenParser"
readme = "README.md"
Expand Down
4 changes: 3 additions & 1 deletion src/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub fn generate_tokens(tokens_config: &deserializer::TokensConfig) -> Vec<templa

token_data_wrapper_list.push(token_data_wrapper);
}

token_data_wrapper_list
}

Expand Down Expand Up @@ -104,7 +105,7 @@ pub fn create_template_file(template_config: &deserializer::ConfigTokensTemplate
}

pub fn filter_properties(json: &serde_json::Value) -> Vec<template::TokenData> {
let data_object = &json.as_object();
let data_object: &Option<&serde_json::Map<String, Value>> = &json.as_object();

let mut token_data_list:Vec<template::TokenData> = vec![];
for (key, val) in data_object.iter().flat_map(|d| d.iter()) {
Expand All @@ -119,6 +120,7 @@ pub fn filter_properties(json: &serde_json::Value) -> Vec<template::TokenData> {
}

}

token_data_list
}

Expand Down
10 changes: 5 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn main() {

// Covert to usable code
let matches: clap::ArgMatches = Command::new("Design Tokens")
.version("3.1.0")
.version("3.1.1")
.author("Vladislav R. <[email protected]>")
.about("Parses figma design tokens to usable code")
.arg(Arg::new("config").short('c').long("config").action(ArgAction::Set).required(true))
Expand All @@ -40,10 +40,10 @@ fn main() {

let config_file = matches.get_one::<String>("config").expect("required");

println!(
"config: {:?}",
&config_file
);
// println!(
// "config: {:?}",
// &config_file
// );

// Deserialize the config file
let token_config: deserializer::TokensConfig = general::get_config(config_file);
Expand Down
12 changes: 10 additions & 2 deletions src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn template_content_custom(
template_update_list_values(file_data_list, &mut current_template, template_type.to_owned(), value);
},
deserializer::CustomConfigTempalteTypeValue::Values(values) => {

template_list_replaced_values(file_data_list, &mut current_template, template_type.to_owned(),values);
},
}
Expand Down Expand Up @@ -83,6 +83,7 @@ fn template_update_list_values(file_data_list: &[template::TokenData], current_t
fn template_list_replaced_values(file_data_list: &[template::TokenData], current_template: &mut CustomTemplate, config_type: String, templates: &[String]) {
let mut values_content:Vec<String> = Vec::new();
let pure_values = template_pure_values(file_data_list, config_type.to_owned());

for (index, template) in templates.iter().enumerate() {
let current = template_replaced_values(index, template, &pure_values);
current_template.update_template_values(config_type.to_owned(), current);
Expand Down Expand Up @@ -141,6 +142,7 @@ pub fn template_set_values(index: usize, data: &template::TokenValue, pure_templ
let token_value = data;
let mut template: Option<String> = Some(pure_template.to_string());


for field_data in fields {
let field_name = field_data.key_full.as_str();
let field_name_without_index = field_data.key_without_index.as_str();
Expand All @@ -161,9 +163,15 @@ pub fn template_set_values(index: usize, data: &template::TokenValue, pure_templ
if let Some(val) = value.get("value") {
match val {
serde_json::Value::Array(values) => {
if (index != values.len()-1) {
return None;
}
pure_value = val.get(field_index)?.get(field_name_without_index);
},
serde_json::Value::Object(obj_val) => {
serde_json::Value::Object(obj_val) => {
if (index != 0) {
return None;
}
pure_value = obj_val.get(field_name_without_index);

}
Expand Down
3 changes: 2 additions & 1 deletion src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ pub fn set_optional_global(globals: &mut liquid_core::Object, key: &str, value:
_ => {
value_transformed = liquid::model::Value::scalar(default.to_string());
}
}
}

globals.insert(key.to_owned().into(), value_transformed);
} else {
globals.insert(key.to_owned().into(), liquid::model::Value::scalar(default.to_string()));
Expand Down

0 comments on commit 155a6be

Please sign in to comment.