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

implement Snippet mechanism like Paradox #508

Merged
merged 1 commit into from
Oct 4, 2017
Merged

Conversation

eed3si9n
Copy link
Member

@eed3si9n eed3si9n commented Oct 2, 2017

This implements low-tech solution for compiled documentation, inspired by Lightbend Paradox's snippet feature. It's low tech because this feature itself just grabs the referenced file as a code block and includes it, and assumes compile or other validation is done elsewhere. (In our case we are using scripted) This low tech approach is nice because it's fast.

// This includes the entire file as Scala code snippet
@@snip [build.sbt]($root$/src/sbt-test/ref/basic/build.sbt) {}

or

// This includes snippet between a line containing #example another line with #example
@@snip [build.sbt]($root$/src/sbt-test/ref/basic/build.sbt) { #example }

or

// This specifies syntax highlight
@@snip [build.sbt]($root$/src/sbt-test/ref/basic/build.sbt) { #example type=text }

There's a hard-coded treatment for $root$, which is interpreted to be the root of the build. Otherwise, the path is treated to the relative path from the markdown file.

This implements low-tech solution for compiled documentation, inspired by Lightbend Paradox's snippet feature.
It's low tech because this feature itself just grabs the referenced file as code block and includes it, and asusmes the compiles validation is done elsewhere. This approach is nice because it's fast.

```
// This includes the entire file as Scala code snippet
@@snip [build.sbt]($root$/src/sbt-test/ref/basic/build.sbt) {}

or

// This includes snippet between a line containing #example another line with #example
@@snip [build.sbt]($root$/src/sbt-test/ref/basic/build.sbt) { #example }

or

// This specifies syntax highlight
@@snip [build.sbt]($root$/src/sbt-test/ref/basic/build.sbt) { #example type=text }
```

There's a hard-coded treatment for `$root$`, which is interpretted to be the root of the build. Otherwise, the path is treated to the relative path from the markdown file.
@dwijnand
Copy link
Member

dwijnand commented Oct 2, 2017

Oh the dilemma.. not having these code blocks inline is a major pain, but enforcing that they're absolutely correct is a great benefit..

Any chance we can refine this to leave them inline?

@eed3si9n
Copy link
Member Author

eed3si9n commented Oct 2, 2017

@dwijnand Well, if we are compatible with Paradox behavior this is how it works.

If we leave anything in but not sync it, then it's confusing.

So a way it work might be:

@@snip [build.sbt]($root$/src/sbt-test/ref/basic/build.sbt) {}

<!-- SNIIPPET BEGIN. DO NOT EDIT MANUALLY -->
```
lazy val root ...
```
<!-- END SNIIPPET -->

and during the "compile"-time we just remove @@snip line and HTML-comment (Pamflet unfortunately doesn't support HTML-comment foundweekends/pamflet#70).

@dwijnand
Copy link
Member

dwijnand commented Oct 2, 2017

I was hoping to have the same behaviour as tut, where you can just write:

Here is how you add numbers:
```tut
1 + 1
```

So I guess ideally we'd have:

Use the following build definition:
```sbt
val root = project in file(".")
```

@eed3si9n
Copy link
Member Author

eed3si9n commented Oct 2, 2017

I've tried that approach with sbt-pamflet https://github.com/sbt/sbt-pamflet, and it's super slow. Besides, I am not sure if that makes sense for builds.

If you are suggesting that we go the opposite direction by generating scripted out of snippet, I don't think it would always work out since we often want part of the code, not the whole thing.

@eed3si9n
Copy link
Member Author

eed3si9n commented Oct 4, 2017

I think we should merge this as is for now, also for the Paradox compatibility.
If you were considering Paradox, then we should keep the snippet syntax the same.

I want to move on and focus my energy on actually documenting things using this feature.

@dwijnand dwijnand merged commit ac28c74 into sbt:1.x Oct 4, 2017
@eed3si9n eed3si9n mentioned this pull request Oct 5, 2017
@eed3si9n eed3si9n deleted the wip/snippet branch December 28, 2018 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants