Skip to content

Commit a1750a2

Browse files
committed
docs(examples): add parsing and networking examples, translate the skeleton
example_parse extracts data from an HTML fixture via CSS selectors and parse_json_var; example_net makes live request/request_html/request_json calls. The example_manga_parser skeleton comments are translated to English.
1 parent ca1c928 commit a1750a2

5 files changed

Lines changed: 329 additions & 111 deletions

File tree

examples/CMakeLists.txt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,29 @@ add_executable(aniparse-example-manga-parser
99

1010
set_property(TARGET aniparse-example-manga-parser PROPERTY CXX_STANDARD 23)
1111

12-
target_link_libraries(aniparse-example-manga-parser PRIVATE aniparse)
12+
target_link_libraries(aniparse-example-manga-parser PRIVATE aniparse)
13+
14+
# Parsing showcase: loads a saved HTML fixture (no network) and extracts data
15+
# via CSS selectors + JS/JSON. EXAMPLE_DATA_DIR points at the fixtures so the
16+
# binary finds them from any working directory.
17+
add_executable(aniparse-example-parse
18+
"${CMAKE_CURRENT_LIST_DIR}/example_parse.cpp"
19+
)
20+
21+
set_property(TARGET aniparse-example-parse PROPERTY CXX_STANDARD 23)
22+
23+
target_compile_definitions(aniparse-example-parse
24+
PRIVATE EXAMPLE_DATA_DIR="${CMAKE_CURRENT_LIST_DIR}/data"
25+
)
26+
27+
target_link_libraries(aniparse-example-parse PRIVATE aniparse)
28+
29+
# Networking showcase: makes real HTTP requests through the curl-backed client
30+
# via request() / request_html() / request_json(). Needs network access.
31+
add_executable(aniparse-example-net
32+
"${CMAKE_CURRENT_LIST_DIR}/example_net.cpp"
33+
)
34+
35+
set_property(TARGET aniparse-example-net PROPERTY CXX_STANDARD 23)
36+
37+
target_link_libraries(aniparse-example-net PRIVATE aniparse)

examples/data/manga_list.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head><title>Example Manga List</title></head>
4+
<body>
5+
<div id="content">
6+
<div class="card" data-id="1">
7+
<a class="card-link" href="/manga/one-piece">One Piece</a>
8+
<div class="tags">
9+
<a class="tag" href="/tag/action">Action</a>
10+
<a class="tag" href="/tag/adventure">Adventure</a>
11+
</div>
12+
<span class="rating">9.2</span>
13+
</div>
14+
<div class="card" data-id="2">
15+
<a class="card-link" href="/manga/berserk">Berserk</a>
16+
<div class="tags">
17+
<a class="tag" href="/tag/dark-fantasy">Dark Fantasy</a>
18+
</div>
19+
<span class="rating">9.5</span>
20+
</div>
21+
</div>
22+
23+
<script>
24+
// Real sites often ship gallery data as a JS array rather than markup.
25+
var gallery = ['https://cdn.example.com/1.jpg', 'https://cdn.example.com/2.jpg'];
26+
</script>
27+
</body>
28+
</html>

0 commit comments

Comments
 (0)