Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show full program in tutorial with highlighted lines #552

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/linters/.markdown-lint.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"MD007": { "indent": 4 },
"MD013": false,
"MD026": false
"MD026": false,
"MD038": false
}
33 changes: 24 additions & 9 deletions docs/types/classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

Just like other object-oriented languages, Pony has __classes__. A class is declared with the keyword `class`, and it has to have a name that starts with a capital letter, like this:

```pony
--8<-- "classes-wombat.pony:1:1"
```
=== "Snippet"
```pony
--8<-- "classes-wombat.pony:1:1"
```
=== "Full program"
```pony hl_lines="1"
--8<-- "classes-wombat.pony"
```

__Do all types start with a capital letter?__ Yes! And nothing else starts with a capital letter. So when you see a name in Pony code, you will instantly know whether it's a type or not.

Expand All @@ -20,9 +25,14 @@ A class is composed of:

These are just like fields in C structures or fields in classes in C++, C#, Java, Python, Ruby, or basically any language, really. There are three kinds of fields: `var`, `let`, and `embed` fields. A `var` field can be assigned to over and over again, but a `let` field is assigned to in the constructor and never again. Embed fields will be covered in more detail in the documentation on [variables](/expressions/variables.md).

```pony
--8<-- "classes-wombat.pony:1:3"
```
=== "Snippet"
```pony
--8<-- "classes-wombat.pony:1:3"
```
=== "Full program"
```pony hl_lines="1-3"
--8<-- "classes-wombat.pony"
```

Here, a `Wombat` has a `name`, which is a `String`, and a `_hunger_level`, which is a `U64` (an unsigned 64-bit integer).

Expand Down Expand Up @@ -50,9 +60,14 @@ Every constructor has to set every field in an object. If it doesn't, the compil

Sometimes it's convenient to set a field the same way for all constructors.

```pony
--8<-- "classes-wombat.pony:1:12"
```
=== "Snippet"
```pony
--8<-- "classes-wombat.pony:1:12"
```
=== "Full program"
```pony hl_lines="1-12"
--8<-- "classes-wombat.pony"
```

Here, every `Wombat` begins a little bit thirsty, regardless of which constructor is called.

Expand Down
5 changes: 5 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ markdown_extensions:
- name: mermaid
class: mermaid-experimental
format: !!python/name:pymdownx.superfences.fence_code_format
- pymdownx.tabbed:
alternate_style: true
slugify: !!python/object/apply:pymdownx.slugs.slugify
kwds:
case: lower
- pymdownx.snippets:
base_path: ['code-samples']
check_paths: true
Expand Down
Loading