npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gitbook-plugin-scalafiddle

v1.0.0

Published

ScalaFiddle integration for GitBook

Downloads

5

Readme

Gitbook ScalaFiddle

Integrate ScalaFiddle easily into your Gitbook documentation using this plugin.

Install

Add the below to your book.json file, then run gitbook install :

{
  "plugins": ["scalafiddle"]
}

Usage

The ScalaFiddle plugin provides a tag scalafiddle which you can use to convert a code block in your documentation into an editable and runnable fiddle. Simply surround a code block with the tag as shown below.

Before:

```scala
def sum(a: Int, b: Int) = a + b

println(sum(2, 2))
```

After:

{% scalafiddle %}
```scala
def sum(a: Int, b: Int) = a + b

println(sum(2, 2))
```
{% endscalafiddle %}

This will instruct the plugin to generate a special <div> around your code which will turn it into an editable fiddle when the viewer clicks the Run button.

Code block with a Run button

Parameters

Each fiddle can be further customized with parameters. These parameters are described in more detail in the main integration documentation. For example:

{% scalafiddle prefix="import scala.util.Random", theme="dark" %}

Templates

Each ScalaFiddle consists of a "user visible" part and of a template that is hidden from the user. You can use this template code to provide additional or common functionality without cluttering each of your fiddles. A template can contain code that comes before the user code, or also code that comes afterwards (separated by a line starting with four slashes ////).

The example template below wraps the user's code into a {} block, assigns it to a val and prints the result at the end.

val result = {
////
}
println(result)

Templates are stored by default under the templates directory (which can be changed via configuration). Each template must have a .scala extension. For the example above, the correct file name would be templates/Result.scala

Use the template in documentation

{% scalafiddle template="Result" %}
```scala
def sum(a: Int, b: Int) = a + b
sum(2, 2)
```
{% endscalafiddle %}

You will see only the user defined code in the fiddle. The result pane, however, shows you that the template code was also run.

Using a template

The final code executed will actually be:

val result = {
def sum(a: Int, b: Int) = a + b
sum(2, 2)
}
println(result)

Configuration

The ScalaFiddle plugin can be configured the same as any other Gitbook plugin via book.json. For example:

{
  "gitbook": "3.2.x",
  "plugins": ["scalafiddle"],
  "pluginsConfig": {
    "scalafiddle": {
      "dependency": "io.suzaku %%% boopickle % 1.2.6",
      "scalaFiddleUrl": "http://localhost:8880/"
    }
  }
}

In the configuration you can provide default values for fiddle parameters such as dependency, minheight, theme etc. Typically you would use the dependency configuration in a library documentation where each code example has the same dependency to your library.

You can also configure the location of templates with templateDir and the URL for the ScalaFiddle service (if you want to run your own ScalaFiddle server, for example locally) using scalaFiddleUrl.