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

Rough draft for Kazari JS plugin for code decoration #52

Merged
merged 3 commits into from
Oct 10, 2016

Conversation

jdesiloniz
Copy link

This PR introduces "Kazari", a Scala.JS-powered plugin that will allow developers to add Scala Exercises-like abilities to their documentations. Basically it will traverse the DOM of any site which includes the generated JS script, decorate any Scala code block by adding an "evaluate" button (which will send requests to our Scala remote evaluator) and also allow live code edition and evaluation.

Right now the plugin just decorates the code with a button to allow calls to the remote evaluator, sending basic requests to the remote evaluator. Refactoring of the network code is also needed, as now it's using JQuery simple Ajax calls. Plans to integrate the remote evaluator client are in motion!

This PR is partly dependant on scala-exercises/evaluator#31, which allows the Scala evaluator to receive CORS calls (like the ones produced by the plugin).

Could you please review @raulraja @dialelo @rafaparadela? Thanks!!

@jdesiloniz
Copy link
Author

@raulraja @dialelo: @juanpedromoreno and I have added support to use the evaluator-client to establish connection with the remote evaluator. Could you please review?

Copy link
Member

@juanpedromoreno juanpedromoreno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff! I've added some minor suggestions and a couple of questions though.

@@ -38,12 +38,24 @@ lazy val micrositeSettings = Seq(
includeFilter in makeSite := "*.html" | "*.css" | "*.png" | "*.jpg" | "*.gif" | "*.js" | "*.swf" | "*.md"
)

val circeVersion = "0.5.2"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This val is not being used. We could remove it.

client.api.evaluates(
dependencies = getDependenciesList(),
resolvers = getResolversList(),
code = snippet.getOrElse("")).exec
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to skip the evaluation if the code snippet is empty.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to a foreach on the option (as it's a side effect really!)

val resolversMetaName = "scala-resolvers"

@JSExport
def main(): Unit = { }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this method required by ScalaJS?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, it's needed when defining a "JSApp" object, even if it's empty :/

object KazariPlugin extends JSApp with DOMHelper {
val codeExcludeClass = "code-exclude"
lazy val codeSnippets = document.querySelectorAll(s"code.language-scala:not(.$codeExcludeClass)")
val dependenciesMetaName = "scala-dependencies"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest changing these meta-tags for evaluator-dependencies and evaluator-resolvers. What do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree!

"org.scala-js" %%% "scalajs-dom" % "0.9.0",
"be.doeraene" %%% "scalajs-jquery" % "0.9.0",
"com.lihaoyi" %%% "upickle" % "0.4.1",
"org.scala-exercises" %%% "evaluator-client" % "0.1.0-SNAPSHOT"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could change the evaluator client to 0.1.1-SNAPSHOT, now that it's available ;)

@jdesiloniz jdesiloniz merged commit 84c6bfb into 0.3.0-version Oct 10, 2016
@jdesiloniz jdesiloniz deleted the javi-include-rough-draft-of-js-plugin branch October 10, 2016 14:11
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.

None yet

2 participants