Skip to content

Commit 4ba8ce9

Browse files
authored
Merge pull request #36 from adafruit/use-md-files
Add raw markdown option for block docs
2 parents 342b3dc + 934cb69 commit 4ba8ce9

File tree

16 files changed

+1115
-577
lines changed

16 files changed

+1115
-577
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,28 @@ Now 2 processes should be running:
3232

3333
When you're done working simply press `CTRL + C` to terminate the processes.
3434

35+
### Generating Blocks and Docs
36+
37+
To generate a new block file:
38+
```sh
39+
npm run generate:block path/block_type # generates block named "Block Type" at app/blocks/path/block_type.js
40+
```
41+
42+
To generate a complete markdown document for a block:
43+
```sh
44+
npm run generate:block:doc path/block_type # generates app/blocks/path/block_type.md
45+
```
46+
The above will generate an entire block documentation page using the embedded documenation in the `block_type.js` file, if present. The documentation exporter will ignore the block definition and use this file instead.
47+
48+
You can also export certain sections of documentation:
49+
```sh
50+
npm run generate:block:doc path/block_type description # generates app/blocks/path/block_type.description.md
51+
npm run generate:block:doc path/block_type inputs # generates app/blocks/path/block_type.inputs.md
52+
npm run generate:block:doc path/block_type fields # generates app/blocks/path/block_type.fields.md
53+
```
54+
55+
These files are markdown fragments, generated from embedded docs in `block_type.js`, that will be used only for their particular sections.
56+
3557
### Exporting
3658

3759
Export a Blockly application:
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
Compare two text values using different comparison operations. Perfect for conditional logic, filtering data, validating user input, or creating smart automation rules based on text content matching, differences, or substring detection.
2+
3+
## What is Text Compare?
4+
5+
The Text Compare block evaluates two text inputs using a specified comparison operator and returns true or false. This enables you to build conditional logic based on text content, whether checking for exact matches, detecting differences, or finding substrings within larger text.
6+
7+
## How It Works
8+
9+
The block performs three types of text comparison operations:
10+
- **Equals (=)** - Exact match comparison (case-sensitive)
11+
- **Not Equals (≠)** - Different text detection
12+
- **Includes** - Substring detection within text
13+
14+
## Comparison Operators
15+
16+
### Equals (=) - Exact Match
17+
Returns true when both text values are exactly the same, including case sensitivity.
18+
19+
::: warning Case Sensitivity Alert
20+
Text comparison is case-sensitive! "Hello" is NOT equal to "hello"
21+
:::
22+
23+
**Examples:**
24+
- "hello" = "hello" → **true**
25+
- "Hello" = "hello" → **false** (case-sensitive)
26+
- "test123" = "test123" → **true**
27+
- " test " = "test" → **false** (whitespace matters)
28+
29+
**Common Uses:**
30+
- ✅ Check device status: `device_status = "online"`
31+
- ✅ Validate user role: `user_role = "admin"`
32+
- ✅ Confirm completion: `task_status = "completed"`
33+
34+
### Not Equals (≠) - Different Values
35+
Returns true when text values are different in any way.
36+
37+
**Examples:**
38+
- "hello" ≠ "world" → **true**
39+
- "same" ≠ "same" → **false**
40+
- "Test" ≠ "test" → **true** (case-sensitive)
41+
42+
**Common Uses:**
43+
- ⚠️ Detect changes: `current_status ≠ previous_status`
44+
- 🚫 Block guest users: `username ≠ "guest"`
45+
- 📝 Validate required fields: `input_field ≠ ""`
46+
47+
### Includes - Substring Detection
48+
Returns true when the left text contains the right text as a substring.
49+
50+
::: tip Perfect for Keyword Searching
51+
Use includes to search for keywords within longer text like error messages, logs, or user input
52+
:::
53+
54+
**Examples:**
55+
- "hello world" includes "world" → **true**
56+
- "temperature alert" includes "temp" → **true**
57+
- "test" includes "testing" → **false** (left must contain right)
58+
59+
**Common Uses:**
60+
- 🔍 Find errors: `error_log includes "timeout"`
61+
- 📧 Email filtering: `email_address includes "@company.com"`
62+
- 🎯 Command parsing: `voice_command includes "lights"`
63+
64+
## Practical Examples
65+
66+
::: details 🏠 Smart Home Examples
67+
68+
### Door & Security
69+
~~~javascript
70+
// Check if door is locked
71+
door_status = "locked" → Turn off porch light
72+
73+
// Alert if door left open
74+
door_status ≠ "closed" → Send notification
75+
76+
// Security monitoring
77+
security_log includes "breach" → Trigger alarm
78+
~~~
79+
80+
### Temperature & Climate
81+
~~~javascript
82+
// AC control
83+
room_temp = "hot" → Turn on air conditioning
84+
85+
// Sensor errors
86+
temp_reading includes "error" → Send maintenance alert
87+
88+
// Room occupancy
89+
bedroom_status ≠ "occupied" → Reduce heating
90+
~~~
91+
92+
:::
93+
94+
::: details 🔧 System Monitoring Examples
95+
96+
### Error Detection
97+
~~~javascript
98+
// System health
99+
system_status ≠ "healthy" → Send alert
100+
error_message includes "critical" → Immediate notification
101+
102+
// Performance monitoring
103+
response_time includes "slow" → Log performance issue
104+
~~~
105+
106+
### Device Management
107+
~~~javascript
108+
// Connectivity checks
109+
device_ping ≠ "success" → Mark device offline
110+
connection_type = "ethernet" → Use high-speed settings
111+
112+
// Battery monitoring
113+
battery_level includes "low" → Send low battery warning
114+
~~~
115+
116+
:::
117+
118+
## Common Issues & Solutions
119+
120+
::: details 🔤 Case Sensitivity Problems
121+
122+
::: danger Most Common Issue
123+
"Online" ≠ "online" - Case matters in all comparisons!
124+
:::
125+
126+
::: details ⚠️ Whitespace Issues
127+
128+
**Hidden spaces cause comparison failures:**
129+
130+
| What You See | Actual Value | Result |
131+
|--------------|--------------|--------|
132+
| "active" | "active " | Won't match "active" |
133+
| "online" | " online" | Won't match "online" |
134+
135+
**Solutions:**
136+
- Be aware extra spaces break matches
137+
- Check for leading/trailing spaces in your data
138+
- Clean data at the source when possible
139+
140+
:::
141+
142+
::: details 🔢 Text vs Numbers
143+
144+
::: warning Important
145+
This block compares TEXT, not numbers! "10" vs "9" gives unexpected results
146+
:::
147+
148+
## Quick Reference
149+
150+
### When to Use Each Operator
151+
| Operator | Use When | Example |
152+
|----------|----------|---------|
153+
| **Equals (=)** | Need exact match | `status = "online"` |
154+
| **Not Equals (≠)** | Need to detect difference | `role ≠ "guest"` |
155+
| **Includes** | Search within text | `message includes "error"` |
156+
157+
### Related Blocks
158+
- **Number Compare** - For numeric comparisons (>, <, >=, <=)
159+
- **Logic AND/OR** - Combine multiple text comparisons
160+
- **IF/Then** - Use comparison results to control flow

app/blocks/text/compare.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,32 @@
22
export default {
33
type: 'text_compare',
44
bytecodeKey: 'textCompare',
5-
name: "Compare Text",
5+
name: "Text Compare",
6+
67
colour: 180,
78
inputsInline: true,
89
primaryCategory: "Logic",
9-
description: "Compare any two pieces of text or data to build conditional logic in your Actions. Perfect for creating if/then statements like 'if device status equals online', 'if user name is not guest', or 'if error message contains timeout'. Works with feed values, variables, user input, or any text-based data.",
10+
1011
connections: {
1112
mode: "value",
1213
output: "expression",
1314
},
14-
template: `%A %OP %B`,
15+
16+
template: "%A %OP %B",
17+
1518
inputs: {
1619
A: {
17-
description: "The first value to compare (left side). Can be feed data, variable content, user input, or any text. Numbers and other data types will be automatically converted to text for comparison.",
20+
description: "Left text value to compare",
1821
check: "expression",
19-
shadow: 'io_text'
22+
shadow: "io_text"
2023
},
2124
B: {
22-
description: "The second value to compare (right side). Can be literal text like 'online', variable content, feed values, or any data you want to compare against the first input. Also automatically converted to text.",
25+
description: "Right text value to compare",
2326
check: "expression",
24-
shadow: 'io_text'
25-
},
27+
shadow: "io_text"
28+
}
2629
},
30+
2731
fields: {
2832
OP: {
2933
description: "Choose how to compare the two text inputs:",
@@ -34,6 +38,7 @@ export default {
3438
]
3539
}
3640
},
41+
3742
generators: {
3843
json: (block, generator) => {
3944
const
@@ -50,6 +55,7 @@ export default {
5055
return [ blockPayload, 0 ]
5156
}
5257
},
58+
5359
regenerators: {
5460
json: (blockObject, helpers) => {
5561
const

0 commit comments

Comments
 (0)