Skip to content

Commit

Permalink
Template files and the generator itself is almost finished
Browse files Browse the repository at this point in the history
  • Loading branch information
meatball133 committed Jan 2, 2024
1 parent a9a7a9f commit a4c942b
Show file tree
Hide file tree
Showing 54 changed files with 350 additions and 79 deletions.
1 change: 1 addition & 0 deletions concepts/array-methods/.meta/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% $array-methods \ $array-methods."flatten & compact & transpose & uniq" %}
1 change: 1 addition & 0 deletions concepts/array/.meta/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% $array \ $"array"."Array pointer" %}
3 changes: 3 additions & 0 deletions concepts/basics/.meta/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Basics

{% $basics \ $basics.Basics %}
2 changes: 0 additions & 2 deletions concepts/basics/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,8 @@ Comments are not executed by the compiler.
```

[arguments]: https://crystal-lang.org/reference/latest/tutorials/basics/60_methods.html#arguments
[assignement]: https://crystal-lang.org/reference/latest/syntax_and_semantics/assignment.html#assignment
[comments]: https://crystal-lang.org/reference/latest/syntax_and_semantics/comments.html
[constants]: https://crystal-lang.org/reference/latest/syntax_and_semantics/constants.html
[default_arguments]: https://crystal-lang.org/reference/latest/tutorials/basics/60_methods.html#default-arguments
[methods]: https://crystal-lang.org/reference/latest/tutorials/basics/60_methods.html#methods
[return]: https://crystal-lang.org/reference/latest/tutorials/basics/60_methods.html#returning-a-value
[snake-case]: https://en.wikipedia.org/wiki/Snake_case
Expand Down
1 change: 1 addition & 0 deletions concepts/binary-octal-hexadecimal/.meta/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% $binary-octal-hexadecimal \ $binary-octal-hexadecimal.Upcase %}
1 change: 1 addition & 0 deletions concepts/bit-manipulation/.meta/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% $bit-manipulation %}
1 change: 1 addition & 0 deletions concepts/bools/.meta/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% $bools \ $bools."Truthy and falsey" \ $bools."Method naming conventions with booleans" %}
1 change: 1 addition & 0 deletions concepts/case/.meta/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% $case \ $case."Exhaustive case" %}
1 change: 1 addition & 0 deletions concepts/char/.meta/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% $char \ $char.Escaping %}
1 change: 1 addition & 0 deletions concepts/classes/.meta/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% $classes \ $classes."Shorthand to initialize instance variables" %}
2 changes: 2 additions & 0 deletions concepts/conditionals/.meta/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% $conditionals \ $conditionals."Spaceship operator" \ $conditionals."Ternary Operator" \ $conditionals."if and unless as suffix" %}
{% $conditionals."Ternary Operator"%}
1 change: 1 addition & 0 deletions concepts/modules/.meta/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% $modules %}
1 change: 1 addition & 0 deletions concepts/nil/.meta/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% $nil \ $nil."not_nil!" %}
1 change: 0 additions & 1 deletion concepts/nil/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ This can be used to make if the value is `nil` it will be falsey and thereby the
```

[nil]: https://crystal-lang.org/reference/syntax_and_semantics/literals/nil.html
[null-pointer]: https://en.wikipedia.org/wiki/Null_pointer
[truthy-falsey]: https://crystal-lang.org/reference/latest/syntax_and_semantics/truthy_and_falsey_values.html
[nil?]: https://crystal-lang.org/api/latest/Object.html#nil?:Bool-instance-method
[string-index]: https://crystal-lang.org/api/latest/String.html#%5B%5D%3F%28index%3AInt%29%3AChar%7CNil-instance-method
Expand Down
1 change: 1 addition & 0 deletions concepts/number-types/.meta/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% $number-types \ $number-types."Type after an operation" \ $number-types."Dig Deeper: unsigned integers vs signed integers" %}
1 change: 1 addition & 0 deletions concepts/numbers/.meta/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% $numbers \ $numbers."Integer division" \ $numbers."Exponentiation" \ $numbers."Rounding up and down" %}
1 change: 1 addition & 0 deletions concepts/ranges/.meta/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% $ranges \ $ranges."Custom objects in ranges" %}
1 change: 1 addition & 0 deletions concepts/return/.meta/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% $return %}
2 changes: 1 addition & 1 deletion concepts/return/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def speed_limit(road_number)
if road_number == 1
return 50
puts "This will not be executed"
end
elsif road_number == 2
return 80
puts "This will not be executed"
Expand All @@ -26,3 +25,4 @@ p speed_limit(3) # => 100
~~~~exercism/note
The `return` keyword should be omitted when the last expression in a method is the value that should be returned.
~~~~

1 change: 1 addition & 0 deletions concepts/string-methods/.meta/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% $string-methods \ $string-methods.String#reverse \ $string-methods."String#capitalize & String#camelcase & String#underscore & String#titleize" %}
1 change: 1 addition & 0 deletions concepts/strings/.meta/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% $strings \ $strings."Substring test" \ $strings."Unicode" %}
1 change: 1 addition & 0 deletions concepts/strings/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,4 @@ World"
```

[strings]: https://crystal-lang.org/reference/latest/syntax_and_semantics/literals/string.html
[unicode]: https://en.wikipedia.org/wiki/Unicode
1 change: 1 addition & 0 deletions concepts/union-type/.meta/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% $union-type \ $union-type."Inferring union types" %}
1 change: 1 addition & 0 deletions concepts/while-loops/.meta/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% $while-loops \ $while-loops."Use while as an expression" %}
86 changes: 86 additions & 0 deletions document-generator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Crystal's Documentation Generator

⚠️ This tool is a work in progress, it is in production on the Crystal track but breaking changes **WILL** ocour without warning ⚠️

This is a documentation generator built 100% using Crystal.
It purpose is to create a [DSL][dsl] for creating syllabus docs for Exercism.
This tooling is not intended to be used outside of Exercism.

## Goal

The goal of this tool is to create a DSL that can be used to create syllabus docs for Exercism, in a more efficent way and with a system that ensures that the docs are synced.
The tool is designed to be able to create docs for any language track on Exercism and it is possible to create an excutable to make Crystal not a requirement for the end user.
Its main purpose is to be able to have a single source of text and then through templating being able to create other docs like the introduction.
This tool differs from the already existing documentation generator bundled with configlet in that it will have more features and be more flexible and thereby allow for more complex docs to be created.

## Installation

### From source

To install this tool from source you need to have Crystal installed.
Then you can run the following command:

```bash
cd document-generator
crystal build ./src/cli.cr -o ./bin/document-generator
mv ./bin/document-generator ../bin/document-generator
```

## Usage

### Using the CLI

```bash
# To get all the available commands
./bin/document-generator --help

# To generate all docs
./bin/document-generator -all

# To generate docs for a specific concept
./bin/document-generator -d <concept_name>

# To generate docs for a specific exercise
./bin/document-generator -e <exercise_name>
```

### Writing templates

This library uses a DSL to write templates, but as of writing this so is the dsl rather limited and is subject to change.
The DSL is only able to grab text from the `about.md` files thereby all the text that is used in the docs should be put in the `about.md` files.
The template should be put under the `.meta` folder with the name `template.md`.

To include the complete content of a concept, use the `{% $concept %}` syntax, the concepts name needs to have a `$` in front of it to highlight that it is a variable and not a command.

```markdown
{% $strings %}
```

To include a specific header from a concept, use the `{% $concept.header %}` syntax, the concept and the header needs to be separated by a `.`.
If the header has a space in it, then the header needs to be sorounded by `""`.

```markdown
{% $strings.introduction %}
{% $strings."about strings" %}
```

To exclude a specific header from a concept, use the `{% $concept exclude $concept.header %}`, allternativly `exclude` have a shorthand which is `\`.

```markdown
{% $strings exclude $strings.introduction %}
{% $strings \ $strings."about strings" %}
```

## Roadmap

- [x] Create a DSL for creating syllabus docs
- [x] Create a CLI to work with the DSL
- [x] Automatic link handling system
- [x] Add a CI script to run tests on the generated docs
- [ ] Fully extensive test suite
- [ ] Fully documented code & Usage
- [ ] Add support to exclude multiple heading easier from the docs
- [ ] Add support to exclude all children from a heading
- [ ] Add support to reuse the introduction docs
- [ ] Add support for changing `#` level of headings
- [ ] Add syntax when working inside certain concept to refer to that concept
58 changes: 0 additions & 58 deletions document-generator/generator.cr

This file was deleted.

31 changes: 31 additions & 0 deletions document-generator/src/cli.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require "option_parser"
require "./interface.cr"

OptionParser.parse do |parser|
parser.banner = "Welcome to The Crystal Doc Generator"

parser.on "-v", "--version", "Show version" do
puts "version 0.1.0"
exit
end
parser.on "-h", "--help", "Show help" do
puts parser
exit
end

parser.on "--all", "Generate all docs" do

Generator.new().generate_all
exit
end

parser.on "-d [DOC]", "--doc [DOC]", "Generate doc for a specific file" do |doc|
Generator.new().generate_doc(doc)
exit
end

parser.on "-e [EXERCISE]", "--exercise [EXERCISE]", "Generate doc for a specific exercise" do |exercise|
Generator.new().generate_exercise_doc(exercise)
exit
end
end
Loading

0 comments on commit a4c942b

Please sign in to comment.