Skip to content

Commit

Permalink
Merge pull request #29 from Asone/21-add-template-engine
Browse files Browse the repository at this point in the history
feat(template): slight improvements on examples
  • Loading branch information
Asone authored Apr 10, 2023
2 parents 2d9e17b + a7c2a93 commit 61406d7
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ NOSTR_BANNER="https://example.com/banner.png"
NOSTR_DESCRIPTION="Craig Wright is not satoshi"
NOSTR_PICTURE="https://example.com/picture.jpg"

DEFAULT_TEMPLATE="test nostrss template\nFeed: {name}\nUrl:{url}\nTags:{tags}"
DEFAULT_TEMPLATE="test nostrss template\nFeed: {name}\nUrl: {url}\nTags: {tags}"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Below are the variables you can use for templating :
| Variable | Description |
| ------------ |---------------------------------- |
| name | The `feed` given name |
| title | The `entry` title |
| content | The `entry` content. Usually a description of the item |
| url | The URL to the `entry` |
| tags | The tags of the `feed` |
Expand Down
4 changes: 2 additions & 2 deletions src/fixtures/default.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Default nostrss template file
Feed: {name}
Url:{url}
Tags:{tags}
Url: {url}
Tags: {tags}
6 changes: 4 additions & 2 deletions src/fixtures/rss.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"id": "bitcoin-reddit",
"name": "reddit r/bitcoin",
"url": "https://www.reddit.com/r/bitcoin/.rss",
"schedule": "1/5 * * * * * *"
"schedule": "1/5 * * * * * *",
"template": "./src/fixtures/default.template"
},
{
"id": "nostr-reddit",
Expand All @@ -18,6 +19,7 @@
"schedule": "1/10 * * * * * *",
"profiles": [
"reddit"
]
],
"template": null
}
]
2 changes: 2 additions & 0 deletions src/fixtures/rss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
schedule: "1/5 * * * * * *"
tags: ["wikipedia","changes"]
profiles: null
template: "./src/fixtures/default.template"
- id: "stackernews"
name: "Stacker news feed"
url: "https://stacker.news/rss"
schedule: "1/30 * * * * * *"
template: null
- id: "bitcoin-reddit"
name: "r/bitcoin reddit feed"
url: "https://www.reddit.com/r/bitcoin/.rss"
Expand Down
10 changes: 5 additions & 5 deletions src/template/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl TemplateProcessor {
tags_string = format!("{} #{}", tags_string, tag);
}

map.insert("tags", tags_string);
map.insert("tags", tags_string.trim().to_string());

let templ = Template::new(&template);

Expand Down Expand Up @@ -128,7 +128,7 @@ mod tests {
assert_eq!(result.is_ok(), true);

let expected =
"test nostrss template\nFeed: Generic feed\nUrl:https://www.nostr.info\nTags:"
"test nostrss template\nFeed: Generic feed\nUrl: https://www.nostr.info\nTags: "
.to_string();
let result = result.unwrap();

Expand Down Expand Up @@ -173,7 +173,7 @@ mod tests {
assert_eq!(result.is_ok(), true);

let result = result.unwrap();
let expected = "Default nostrss template file\nFeed: Generic feed\nUrl:https://www.nostr.info\nTags: #Test #nostrss".to_string();
let expected = "Default nostrss template file\nFeed: Generic feed\nUrl: https://www.nostr.info\nTags: #Test #nostrss".to_string();

assert_eq!(result, expected);
}
Expand Down Expand Up @@ -217,7 +217,7 @@ mod tests {

let result = result.unwrap();
let expected =
"Default nostrss template file\nFeed: {name}\nUrl:{url}\nTags:{tags}".to_string();
"Default nostrss template file\nFeed: {name}\nUrl: {url}\nTags: {tags}".to_string();
assert_eq!(result, expected);

let bad_path = "./src/fixture/nonexistant.template".to_string();
Expand All @@ -229,7 +229,7 @@ mod tests {
assert_eq!(result.is_ok(), true);

let result = result.unwrap();
let expected = "test nostrss template\nFeed: {name}\nUrl:{url}\nTags:{tags}".to_string();
let expected = "test nostrss template\nFeed: {name}\nUrl: {url}\nTags: {tags}".to_string();
assert_eq!(result, expected);
}
}

0 comments on commit 61406d7

Please sign in to comment.