-
Notifications
You must be signed in to change notification settings - Fork 25
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
Client side play urls #10
Conversation
Files inside directory that is prefixed with underscore are not accessible for the server, and so cannot be fetched via xhr.
For clients that have js disabled?
It seems that sometimes event is not fired if script is loaded in asynchronous manner, and thus nothing will work.
But browsers will block windows opened this way.
This also triggers popup blocker :(
I think doing this in js is a bad idea, and console shouldn't be used in "production" (eslint doesn't like it). A bettter solution would be writing some Ruby script, that checks all source files for any problems with those special comments. The only drawback is that this *.rb script would need to be invoked manually.
var RUST_VERSION = "nightly"; | ||
var HOME_URL = window.location.protocol + "//" + window.location.host + "/"; | ||
|
||
document.addEventListener("DOMContentLoaded", function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fail in IE 8. Alternative solution would be putting whole script inline, inside main HTML file, just before closing </body>
tag. Not the nicest solution, but should work everywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meh. I think we can assume fairly modern browsers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Well, I guess we just need to put a call to playUrl()
inline, after the body
tag? (And export it out of the function, obviously.))
Still, I don't care much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, if anyone complains, it'll be easy to change.
} | ||
|
||
function addTransformations(text) { | ||
var solutionRegex = /\/\/ START SOLUTION\s*(.*)\s*\/\/ END SOLUTION/g; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't quite how start/end solution works. The idea is something like this:
fn foo() {
// PROMPT xxx
// START SOLUTION
yyy
// END SOLUTION
}
would get transformed to:
fn foo() {
xxx
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And it should work exactly that way. I can remove (.*)
here, but it will work anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, wait. Maybe I am wrong. =) I was assuming that .
in JS regexs doesn't match newlines, but maybe it does?
Regardless, this makes me nervous. In particular, you could have multiple sections:
// START SOLUTION
xxx
// END SOLUTION
yyy
// START SOLUTION
zzz
// END SOLUTION
and a regex engine using maximal matching (the typical default) would gobble up xxx
, yyy
, and zzz
. I suppose you could to (.*?)
, if JS engines support that, and it'd probably work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
in JS doesn't match newlines, that's why we need s+
. I am testing all regexes here: https://regex101.com/r/1nWjUL/1
I already added some modifications to the regex.
And it reminds me... https://www.xkcd.com/208/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the one you had I think didn't work if there was more than one line in the solution. I made a modified version \/\/ START SOLUTION(\s|.)*?\/\/ END SOLUTION
that seems to work though:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even better: https://regex101.com/r/1nWjUL/3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch about multiline solutions! I modify this line, but I don't understand why do you need /n?
at the end?
This looks pretty good! I left a few comments. |
} | ||
|
||
function addTransformations(text) { | ||
var solutionRegex = /\/\/ START SOLUTION\s+.*\s+\/\/ END SOLUTION/g; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as your whitespace formatting (new lines) is OK, there is (hopefully) nothing to worry about this expression.
As suggested by @nikomatsakis. Also requiring at least one character to exist between START END solution (even if it's empty line).
Argh, this fell off my radar. I admit I don't feel qualified to know if this is really The Right Way to go about things, but this seems like a good approach to me. @ests did you delete the original repo? I was going to poke about and try it locally, but I can't seem to figure out where to merge from. |
@nikomatsakis I was sure this won't be accepted so I was too quick to delete it - sorry. I also don't have it on my laptop. I don't know if this is (was) the right way to go. But now probably the only way to play with it, would be to somehow to generate diff file on github and apply it locally, but I don't know if this is possible (easily). |
@ests good thinking. https://patch-diff.githubusercontent.com/raw/nikomatsakis/intorust/pull/10.diff seems to work. |
Argh, I've let this sit for way too long! I'm inclined to merge it at this point =) Do these kinds of URLs still work? |
Assembly links to Play Rust out of source files fetched from the server. This is done just after DOM has loaded - every link with special data attribute will have its href replaced.
The other solution was to use various onclick events, but opening windows via javascript will almost always trigger popup blocking.
See #3 .