feat: make story connect · inherd/uncode@145acd2 · GitHub
Skip to content

Commit 145acd2

Browse files
committed
feat: make story connect
1 parent 5c7247e commit 145acd2

10 files changed

Lines changed: 139 additions & 21 deletions

File tree

‎src-tauri/src/main.rs‎

Lines changed: 17 additions & 2 deletions

‎uncode/Cargo.lock‎

Lines changed: 28 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎uncode/uncode-core/Cargo.toml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "uncode-core"
2+
name = "uncode_core"
33
version = "0.1.0"
44
authors = ["Inherd Group <group@inherd.org>", "Phodal Huang <h@phodal.com>"]
55
edition = "2018"
@@ -25,3 +25,4 @@ exclude = [
2525
[dependencies]
2626
# serial
2727
serde = { version = "1.0" }
28+
serde_json = { version = "1.0" }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// pub mod story_;
1+
pub mod story_model;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
#[derive(Serialize, Deserialize, Debug, Clone)]
4+
pub struct StoryModel {
5+
pub title: String,
6+
pub status: String,
7+
pub description: String,
8+
}
9+
10+
impl Default for StoryModel {
11+
fn default() -> Self {
12+
StoryModel {
13+
title: "".to_string(),
14+
status: "".to_string(),
15+
description: "".to_string()
16+
}
17+
}
18+
}

‎uncode/uncode-core/src/lib.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
extern crate serde_json;
2+
3+
pub use domain::story_model::StoryModel;
14
pub mod domain;

‎uncode/uncode-story/Cargo.toml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,10 @@ exclude = [
2323
]
2424

2525
[dependencies]
26+
walkdir = "2"
2627
gherkin_rust = "0.10.1"
28+
29+
serde_json = "1.0"
30+
serde = "1.0"
31+
32+
uncode_core = { path = "../uncode-core" }

‎uncode/uncode-story/src/lib.rs‎

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,58 @@
1+
extern crate serde_json;
2+
13
use gherkin_rust::{Feature};
4+
use uncode_core::StoryModel;
5+
use walkdir::{WalkDir, DirEntry};
6+
use std::fs;
27

3-
fn parse() {
4-
let result = Feature::parse("
5-
Feature: Title
6-
Description
7-
8-
Scenario: Nothing
9-
Given I just started
10-
", Default::default());
11-
match result {
12-
Ok(feature) => {
13-
println!("{:?}", feature);
14-
}
15-
Err(err) => {
16-
println!("{:?}", err);
8+
pub fn parse(content: &str) -> StoryModel {
9+
let mut story = StoryModel::default();
10+
let result = Feature::parse(content, Default::default());
11+
if let Ok(feature) = result {
12+
story.title = feature.name;
13+
story.description = feature.description.unwrap_or("".to_string());
14+
};
15+
16+
story
17+
}
18+
19+
pub fn parse_dir(path: String) -> Vec<StoryModel> {
20+
fn is_story(entry: &DirEntry) -> bool {
21+
entry.file_name()
22+
.to_str()
23+
.map(|s| s.ends_with(".feature"))
24+
.unwrap_or(false)
25+
}
26+
27+
let walker = WalkDir::new(path).into_iter();
28+
let mut stories = vec![];
29+
for entry in walker.filter_entry(|e| !is_story(e)) {
30+
match entry {
31+
Ok(dir) => {
32+
if dir.file_type().is_file() {
33+
let content = fs::read_to_string(dir.path()).expect("error to load file");
34+
stories.push(parse(&*content));
35+
}
36+
}
37+
Err(_) => {}
1738
}
39+
};
40+
41+
stories
42+
}
43+
44+
#[cfg(test)]
45+
mod tests {
46+
use std::path::PathBuf;
47+
use crate::parse_dir;
48+
49+
#[test]
50+
fn should_parse_demo_project_story() {
51+
let d = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
52+
let path = format!("{}", d.join("story").display());
53+
let stories = parse_dir(path);
54+
55+
assert_eq!(1, stories.len());
56+
assert_eq!("1", stories[0].title);
1857
}
1958
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# status: Done
2+
# author: Phodal HUANG
3+
# language: zh-CN
4+
功能: 第一个用户故事
5+
6+
场景打开 Uncode
7+
假如我在 Terminal 工具里
8+
当输入 uncode
9+
那么则能在 Uncode IDE 里打开当前项目
Lines changed: 2 additions & 0 deletions

0 commit comments

Comments
 (0)