Skip to content

Commit deede5a

Browse files
authored
Added description to landing page examples (#1185)
* Added description to landing page examples * Added missing headlines to example page
1 parent f4c1d9b commit deede5a

File tree

16 files changed

+167
-24
lines changed

16 files changed

+167
-24
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Read data directly from a php associative array. Relays on `array_to_rows` DSL function.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Read data from a csv file.
2+
3+
```php
4+
function from_csv(
5+
string|Path|array $path,
6+
bool $with_header = true,
7+
bool $empty_to_null = true,
8+
?string $delimiter = null,
9+
?string $enclosure = null,
10+
?string $escape = null,
11+
int $characters_read_in_line = 1000,
12+
?Schema $schema = null
13+
):
14+
```
15+
16+
* `with_header` - default true, if false, the first row will be treated as data
17+
* `empty_to_null` - default false, if true, empty string will be treated as null
18+
* `delimiter` - the delimiter of the csv file, when not set, it will be auto detected
19+
* `enclosure` - the enclosure of the csv file, when not set, it will be auto detected
20+
* `escape` - default `\`, the escape character of the csv file
21+
* `characters_in_line` - default `1000`, size of chunk used to read lines from the file
22+
* `schema` - the schema of the csv file, when not set, it will be auto detected
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Read data from a json file.
2+
3+
```php
4+
function from_json(
5+
string|Path|array $path,
6+
?string $pointer = null,
7+
?Schema $schema = null,
8+
);
9+
```
10+
11+
* `pointer` - default null, used to iterate only results of a subtree, read more about [pointers](https://github.com/halaxa/json-machine#parsing-a-subtree)
12+
* `schema` - the schema of the csv file, when not set, it will be auto detected
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Read data from a json file.
2+
3+
```php
4+
function from_parquet(
5+
string|Path|array $uri,
6+
array $columns = [],
7+
Options $options = new Options(),
8+
ByteOrder $byte_order = ByteOrder::LITTLE_ENDIAN,
9+
?int $offset = null,
10+
);
11+
```
12+
13+
* `columns` - default [], list of columns to read, when empty, all columns will be read
14+
* `options` - custom Parquet Reader [Options](https://github.com/flow-php/flow/blob/1.x/src/lib/parquet/src/Flow/Parquet/Options.php)
15+
* `byte_order` - default `ByteOrder::LITTLE_ENDIAN`, the byte order of the parquet file
16+
* `offset` - default null, rows to skip from the beginning of the file
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Read data from a json file.
2+
3+
```php
4+
function from_xml(
5+
string|Path|array $path,
6+
string $xml_node_path = ''
7+
);
8+
```
9+
10+
* `xml_node_path` - default '', the path to the node to read, when empty, the root node will be read. It's not xpath, it is just a sequence of node names separated with slash.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Schema inferring is a process of generating a schema from a whole or part of the dataset.
2+
Once schema is inferred, it can be saved and used to speed up next dataset processing.

src/adapter/etl-adapter-parquet/src/Flow/ETL/Adapter/Parquet/functions.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,26 @@
1313
use Flow\Parquet\{ByteOrder, Options};
1414

1515
/**
16-
* @param array<Path>|Path|string $uri
16+
* @param array<Path>|Path|string $path
1717
* @param array<string> $columns
1818
*
1919
* @return Extractor
2020
*/
2121
function from_parquet(
22-
string|Path|array $uri,
22+
string|Path|array $path,
2323
array $columns = [],
2424
Options $options = new Options(),
2525
ByteOrder $byte_order = ByteOrder::LITTLE_ENDIAN,
2626
?int $offset = null,
2727
) : Extractor {
28-
if (\is_array($uri)) {
28+
if (\is_array($path)) {
2929
$extractors = [];
3030

3131
if ($offset !== null) {
3232
throw new InvalidArgumentException('Offset can be used only with single file path, not with pattern');
3333
}
3434

35-
foreach ($uri as $filePath) {
35+
foreach ($path as $filePath) {
3636
$extractors[] = new ParquetExtractor(
3737
$filePath,
3838
$options,
@@ -45,7 +45,7 @@ function from_parquet(
4545
}
4646

4747
return new ParquetExtractor(
48-
\is_string($uri) ? Path::realpath($uri) : $uri,
48+
\is_string($path) ? Path::realpath($path) : $path,
4949
$options,
5050
$byte_order,
5151
$columns,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {Controller} from '@hotwired/stimulus';
2+
3+
/* stimulusFetch: 'lazy' */
4+
export default class extends Controller
5+
{
6+
connect()
7+
{
8+
this.element.querySelectorAll('a').forEach(link => {
9+
link.target = '_blank';
10+
link.rel = 'noopener';
11+
});
12+
}
13+
}

web/landing/assets/styles/app.css

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,28 @@ code {
5959

6060
#blog-post hr {
6161
@apply text-blue-100 my-4 border-t-2 rounded;
62+
}
63+
64+
#example-description h1 {
65+
@apply font-bold text-2xl;
66+
}
67+
68+
#example-description h2 {
69+
@apply font-bold text-xl mt-4;
70+
}
71+
72+
#example-description h1, h2, ul, hr, p {
73+
@apply mb-3;
74+
}
75+
76+
#example-description ul {
77+
@apply list-disc pl-6;
78+
}
79+
80+
#example-description hr {
81+
@apply text-blue-100 my-4 border-t-2 rounded;
82+
}
83+
84+
#example-description code {
85+
@apply text-orange-100;
6286
}

web/landing/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"monolog/monolog": "^3.5",
2424
"symfony/monolog-bundle": "^3.10",
2525
"coduo/php-humanizer": "^4.0",
26-
"twig/markdown-extra": "^3.8",
26+
"twig/markdown-extra": "^3.11",
2727
"twig/extra-bundle": "^3.8",
2828
"league/commonmark": "^2.4"
2929
},

web/landing/composer.lock

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

web/landing/src/Flow/Website/Controller/DefaultController.php renamed to web/landing/src/Flow/Website/Controller/ExamplesController.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
namespace Flow\Website\Controller;
66

7-
use Flow\Website\Service\{Examples};
7+
use Flow\Website\Service\Examples;
88
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
99
use Symfony\Component\HttpFoundation\Response;
1010
use Symfony\Component\Routing\Attribute\Route;
1111

12-
final class DefaultController extends AbstractController
12+
final class ExamplesController extends AbstractController
1313
{
1414
public function __construct(
1515
private readonly Examples $examples,
@@ -30,19 +30,12 @@ public function example(string $topic, string $example) : Response
3030
'examples' => $examples,
3131
'currentTopic' => $topic,
3232
'currentExample' => $example,
33+
'description' => $this->examples->description($currentTopic, $currentExample),
3334
'code' => $this->examples->code($currentTopic, $currentExample),
3435
'output' => $this->examples->output($currentTopic, $currentExample),
3536
]);
3637
}
3738

38-
#[Route('/', name: 'main')]
39-
public function main() : Response
40-
{
41-
return $this->render('main/index.html.twig', [
42-
'topics' => $this->examples->topics(),
43-
]);
44-
}
45-
4639
#[Route('/{topic}/', name: 'topic', priority: 10)]
4740
public function topic(string $topic) : Response
4841
{
@@ -57,6 +50,7 @@ public function topic(string $topic) : Response
5750
'examples' => $examples,
5851
'currentTopic' => $currentTopic,
5952
'currentExample' => $currentExample,
53+
'description' => $this->examples->description($currentTopic, $currentExample),
6054
'code' => $this->examples->code($currentTopic, $currentExample),
6155
'output' => $this->examples->output($currentTopic, $currentExample),
6256
]);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Flow\Website\Controller;
6+
7+
use Flow\Website\Service\{Examples};
8+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
9+
use Symfony\Component\HttpFoundation\Response;
10+
use Symfony\Component\Routing\Attribute\Route;
11+
12+
final class HomeController extends AbstractController
13+
{
14+
public function __construct(
15+
private readonly Examples $examples,
16+
) {
17+
}
18+
19+
#[Route('/', name: 'home')]
20+
public function home() : Response
21+
{
22+
return $this->render('main/index.html.twig', [
23+
'topics' => $this->examples->topics(),
24+
]);
25+
}
26+
}

web/landing/src/Flow/Website/Service/Examples.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ public function code(string $topic, string $example) : string
2121
return \file_get_contents($path);
2222
}
2323

24+
public function description(string $topic, string $example) : ?string
25+
{
26+
$path = \sprintf('%s/topics/%s/%s/description.md', \realpath($this->examplesPath), $topic, $example);
27+
28+
if (false === \file_exists($path)) {
29+
return null;
30+
}
31+
32+
return \file_get_contents($path);
33+
}
34+
2435
/**
2536
* @return string[]
2637
*/

web/landing/templates/base.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<body class="scroll-smooth bg-black text-white">
5252
<header class="py-2 text-white bg-blue-200">
5353
<div class="mx-auto max-w-screen-xl px-4 flex items-center justify-between">
54-
<a href="{{ path('main') }}">
54+
<a href="{{ path('home') }}">
5555
<img src="{{ asset('images/logo.svg') }}" alt="flow php" width="176" height="48">
5656
</a>
5757

web/landing/templates/example/index.html.twig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
{% block main %}
1212
<div class="py-10 px-2 sm:px-4 mx-auto max-w-screen-xl" data-hx-boost="true">
13+
<h2 class="mb-4 text-2xl font-semibold tracking-wide">Examples:</h2>
1314
<nav class="font-medium text-center bg-orange-100 rounded">
1415
<ul class="flex whitespace-nowrap overflow-auto justify-between">
1516
{% for topic in topics %}
@@ -37,7 +38,18 @@
3738
</nav>
3839

3940
<div id="example" class="-mt-36 pt-36">
41+
{% if description %}
42+
<h2 class="text-xl mt-5 mb-5">Description</h2>
43+
<article id="example-description"
44+
class="rounded px-4 pt-4 overflow-auto shadow-2xl shadow-gray rounded border-gray border-2 relative mb-10"
45+
{{ stimulus_controller('all_links_external') }}
46+
>
47+
{{ description|markdown_to_html }}
48+
</article>
49+
{% endif %}
50+
4051
{% apply spaceless %}
52+
<h2 class="text-xl mt-5 mb-5">Code</h2>
4153
<pre class="rounded p-4 overflow-auto shadow-2xl shadow-gray rounded border-gray border-2 relative">
4254
<button class="absolute top-0 right-0 bg-orange-100 rounded px-4 leading-9 [&.copied]:before:content-['Copied!'] before:absolute before:-translate-x-24" title="copy code" data-clipboard-target="#code" {{ stimulus_controller('clipboard') }}>
4355
<img src="{{ asset('images/icons/copy.svg') }}" alt="copy code" width="20" height="20" class="inline">

0 commit comments

Comments
 (0)