Skip to content

Commit 8802e28

Browse files
committed
feat: add ExampleBadge component for per-example test status
- Add ExampleBadge component with pass/fail/pending status - Support clickable link to GitHub test file with line number - Register component in MDXComponents for MDX usage - Apply example badge to what-is-t-ruby.md as demo Usage: <ExampleBadge status="pass" testFile="spec/.../file_spec.rb" line={23} />
1 parent 576868a commit 8802e28

File tree

3 files changed

+114
-3
lines changed

3 files changed

+114
-3
lines changed

i18n/ko/docusaurus-plugin-content-docs/current/introduction/what-is-t-ruby.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ title: T-Ruby란?
44
description: T-Ruby 소개 - Ruby를 위한 TypeScript 스타일 타입 시스템
55
---
66

7+
<DocsBadge />
8+
79
# T-Ruby란?
810

911
T-Ruby는 Ruby에 TypeScript 스타일의 타입 문법을 도입하는 새로운 접근 방식입니다. TypeScript가 JavaScript에 하는 역할을 Ruby에도 가져옵니다.
@@ -12,7 +14,9 @@ T-Ruby는 Ruby에 TypeScript 스타일의 타입 문법을 도입하는 새로
1214

1315
TypeScript가 JavaScript에 타입 안전성을 추가하듯이, T-Ruby는 Ruby에 동일한 기능을 제공합니다. `.trb` 파일에 타입 주석이 포함된 Ruby 코드를 작성하면, T-Ruby가 이를 순수한 Ruby 코드와 RBS 타입 정의로 컴파일합니다.
1416

15-
```ruby
17+
<ExampleBadge status="pass" testFile="spec/docs_site/pages/introduction/what_is_t_ruby_spec.rb" line={23} />
18+
19+
```trb
1620
# 입력: hello.trb
1721
def greet(name: String): String
1822
"안녕하세요, #{name}!"
@@ -30,7 +34,7 @@ end
3034
user = find_user(123)
3135
```
3236

33-
```ruby
37+
```rbs
3438
# 출력: hello.rbs (RBS 타입 정의)
3539
def greet: (String) -> String
3640
```
@@ -41,7 +45,9 @@ def greet: (String) -> String
4145

4246
T-Ruby의 타입 문법은 TypeScript에서 직접 영감을 받았습니다. TypeScript를 사용해본 경험이 있다면, T-Ruby도 바로 이해할 수 있습니다.
4347

44-
```ruby
48+
<ExampleBadge status="pass" testFile="spec/docs_site/pages/introduction/what_is_t_ruby_spec.rb" line={35} />
49+
50+
```trb
4551
# Union 타입
4652
id: String | Integer = "user-123"
4753
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import React from 'react';
2+
import { BadgeCheck, X, ExternalLink } from 'lucide-react';
3+
4+
interface ExampleBadgeProps {
5+
/** 테스트 통과 여부 */
6+
status: 'pass' | 'fail' | 'pending';
7+
/** 테스트 파일 경로 (예: spec/docs_site/pages/introduction/what_is_t_ruby_spec.rb) */
8+
testFile?: string;
9+
/** 테스트 파일 내 라인 번호 */
10+
line?: number;
11+
/** 예제 ID 또는 설명 (선택) */
12+
id?: string;
13+
}
14+
15+
const GITHUB_REPO = 'https://github.com/type-ruby/t-ruby/blob/main';
16+
17+
export const ExampleBadge: React.FC<ExampleBadgeProps> = ({
18+
status,
19+
testFile,
20+
line,
21+
id
22+
}) => {
23+
const statusConfig = {
24+
pass: {
25+
icon: <BadgeCheck size={12} />,
26+
text: 'Verified',
27+
bgColor: 'rgba(34, 197, 94, 0.1)',
28+
textColor: '#16a34a',
29+
borderColor: 'rgba(34, 197, 94, 0.2)',
30+
},
31+
fail: {
32+
icon: <X size={12} />,
33+
text: 'Failed',
34+
bgColor: 'rgba(239, 68, 68, 0.1)',
35+
textColor: '#dc2626',
36+
borderColor: 'rgba(239, 68, 68, 0.2)',
37+
},
38+
pending: {
39+
icon: <BadgeCheck size={12} style={{ opacity: 0.5 }} />,
40+
text: 'Pending',
41+
bgColor: 'rgba(156, 163, 175, 0.1)',
42+
textColor: '#6b7280',
43+
borderColor: 'rgba(156, 163, 175, 0.2)',
44+
},
45+
};
46+
47+
const config = statusConfig[status];
48+
const testUrl = testFile
49+
? `${GITHUB_REPO}/${testFile}${line ? `#L${line}` : ''}`
50+
: undefined;
51+
52+
const badge = (
53+
<span
54+
style={{
55+
display: 'inline-flex',
56+
alignItems: 'center',
57+
gap: '3px',
58+
padding: '2px 6px',
59+
borderRadius: '3px',
60+
fontSize: '10px',
61+
fontWeight: 500,
62+
backgroundColor: config.bgColor,
63+
color: config.textColor,
64+
border: `1px solid ${config.borderColor}`,
65+
cursor: testUrl ? 'pointer' : 'default',
66+
textDecoration: 'none',
67+
transition: 'opacity 0.2s',
68+
}}
69+
title={testUrl ? `View test: ${testFile}${line ? `:${line}` : ''}` : undefined}
70+
>
71+
{config.icon}
72+
<span>{config.text}</span>
73+
{testUrl && <ExternalLink size={9} style={{ marginLeft: 1, opacity: 0.7 }} />}
74+
</span>
75+
);
76+
77+
if (testUrl) {
78+
return (
79+
<a
80+
href={testUrl}
81+
target="_blank"
82+
rel="noopener noreferrer"
83+
style={{ textDecoration: 'none' }}
84+
>
85+
{badge}
86+
</a>
87+
);
88+
}
89+
90+
return badge;
91+
};
92+
93+
export default ExampleBadge;

src/theme/MDXComponents.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react';
2+
import MDXComponents from '@theme-original/MDXComponents';
3+
import { DocsBadge } from '@site/src/components/DocsBadge';
4+
import { VerifiedBadge } from '@site/src/components/VerifiedBadge';
5+
import { ExampleBadge } from '@site/src/components/ExampleBadge';
6+
7+
export default {
8+
...MDXComponents,
9+
DocsBadge,
10+
VerifiedBadge,
11+
ExampleBadge,
12+
};

0 commit comments

Comments
 (0)