Skip to content
This repository was archived by the owner on Sep 30, 2020. It is now read-only.

14652 frontpage style #35

Merged
merged 8 commits into from
Jun 17, 2014
Merged

Conversation

jasonkliu
Copy link
Contributor

The issues addressed are rust-lang/rust#14651 and rust-lang/rust#14652.

Relative to 14651 (coding style of the frontpage), the println! line spacing was off. In addition, I updated the comments to make them more clear, since the current version doesn't seem intuitive to a new reader.

Relative to 14652, I added a button link to the playground. This repository seems to be the source for the main website; is the source for the playground also available on Github? Ideally, linking to the playground would copy the current code in the editor and paste it into the playground, but I'm not exactly sure how to do this without looking at the playground source. I would also like to implement different programs (such as Hello World) with a selector on the main page so additional code examples can be seen.

jasonkliu added 2 commits June 5, 2014 21:26
The '+'/'-' usage was confusing so I split the lines. In addition,
I amended println! to conform to the 4 spaces for indentation as
stated in the style guide.
@adrientetar
Copy link
Contributor

For the comments, maybe the point was to keep it short? I think assuming people know about the primitive arithmetic operations shouldn't be much unclear.

@SergioBenitez
Copy link
Contributor

To make it easy to see the changes, here's a screenshot:
screen shot 2014-06-06 at 7 08 55 am

I think the playground button is too large (and too blue) and it looks a bit odd there. It can easily get in the way of user's code; the run button is small enough that I don't think this is a big issue for it. Further, I'm not sure expanding the comments in this way adds much information. I think we can assume our users will understand the previous comments. If anything, we could simply add ", respectively" to make it clear, so that the commentary becomes:

// A simple integer calculator:
// `+` or `-` means add or sub by 1, respectively
// `*` or `/` means mul or div by 2, respectively

As for resolving rust-lang/rust#14652, perhaps we could add a small "open external" icon next to the result that, when clicked, opens up the playpen with the code already in place. Like this:

screen shot 2014-06-06 at 7 14 51 am

@adrientetar
Copy link
Contributor

@SergioBenitez Awesome. Do we need the respectively through? cc @brson

@jasonkliu
Copy link
Contributor Author

@adrientetar @SergioBenitez Thank you for the feedback. I think I was trying to change the wording of the comments, but upon taking a second look at it, it doesn't seem as off as I thought. I don't think I've seen the usage of mul to abbreviate multiply, though. What about unabbreviating the (add/subtract/multiply/divide) expressions and removing respectively? This would keep the two-line format and make it more readable.

I think the "open external" icon makes a lot of sense - is the playground also hosted here? It seems you can send json requests to it but I'm not sure how to load the playground with an existing code sample.

@brson
Copy link
Contributor

brson commented Jun 6, 2014

@jasonkliu This rustdoc PR uses the playpen API to open code on play.rust-lang.org: rust-lang/rust#14700

I agree with @SergioBenitez's suggestion about how to link to the playpen from the main example unobtrusively.

@SergioBenitez
Copy link
Contributor

@jasonkliu You can just append it as a query string, like this:

http://play.rust-lang.org/?code=fn+main()+%7B%20println!(%22foo%22)%20%7D&run=1

Thus, grab the code from the editor, URL encode it, and append it to http://play.rust-lang.org/?code=. You can add &run=1 to the end so that it runs on load.

@jasonkliu
Copy link
Contributor Author

I've implemented the output button by taking the current input in the editor and putting it into the playground, running automatically. I've also fixed the comment text.

screen shot 2014-06-06 at 4 36 59 pm

function handleSuccess(message) {
resultDiv.style.backgroundColor = successColor;
resultDiv.innerHTML = escapeHTML(message);
var program = encodeURIComponent(editor.getValue());
var output = "<a href=\"http://play.rust-lang.org/?code=" + program +
Copy link
Contributor

Choose a reason for hiding this comment

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

Mixing in HTML with JS isn't good style. Instead, place the HTML with the rest of the markup and simply change the HREF when the result is changed. Note: What do you do when there is an error, or when the result pane is open but the code in the editor has changed and hasn't been rerun?

@jasonkliu
Copy link
Contributor Author

@SergioBenitez: Thank you very much for the comments.

I moved the html to the index file and used JS to replace the href of the link. I'm attempting to check whether the editor contents are the same as the generated HTML link as the link is clicked, but am running into issues. Using the window.location method doesn't seem to work consistently and I don't seem to be able to easily change the navigation to a page while the onclick method is happening without using jQuery. This is the function I was attempting to try:

// When clicking on the playground link, check if editor code is modified
function f1() {
  var program1 = encodeURIComponent(editor.getValue());       
  var program2 = "http://play.rust-lang.org/?code=" + program1 + "&run=1"
  if (program2 !== playLink.href) {  
    //playLink.href = program2
    //window.location =  program2
    console.log(program2);
  }
}

@brson
Copy link
Contributor

brson commented Jun 16, 2014

@jasonkliu Sorry I've been away for a few days. What's left to do here?

@jasonkliu
Copy link
Contributor Author

@brson Most of the functionality is done, with one small exception. The current workflows are:

  1. User has a program in the editor → hits Run → Success → Output button shows (linked to playground with current editor text).
  2. User has a program in the editor → hits Run → Failure → Error message shows and Output button shows (linked to playground with current editor text).
  3. User has a program in the editor → Modifies it → hits Run → Success/Failure → Output button shows and error message shows if necessary.
  4. User has a program in the editor → hits Run → modifies it → hits Output button → Links to playground with previous output.

In short, the method of processing involves taking the editor text and encoding it into a html link embedded in an icon. However, it is only updated when the "Run" button is clicked, so in case 4 above, the output button won't have an updated link when the user clicks on it. I tried to implement a function to check if the link href is not the same as the editor text (see above comment), but it doesn't work consistently since it is calling a function while the browser is navigating to a link.
Here are a few possible solutions:

  • Use jQuery with something like $("a.mylink").attr("href", "http://new-link-to-playground.com");. The clear disadvantage is loading the whole jQuery library for a simple function.
  • Update the html link every time the editor is changed. This may cause additional browser overhead.
  • Simply ignore the case. Assuming the user continuously clicks on "Run" to re-run a modified version of the code, this isn't a problem at all. Otherwise, if the modifications to the program in the editor are small, it would be trivial for the user to recreate them.

brson added a commit that referenced this pull request Jun 17, 2014
@brson brson merged commit 9a7f57f into rust-lang:gh-pages Jun 17, 2014
@brson
Copy link
Contributor

brson commented Jun 17, 2014

@jasonkliu Thanks for the debrief. I've merged on the notion that this is a bug we can live with for a little while, but I would like to get it fixed. Can you try your first solution, and if that doesn't work, the second?

@brson
Copy link
Contributor

brson commented Jun 17, 2014

@jasonkliu After merging the new code, when I click 'Run', the icon is just a unicode placeholder, not the desired icon. Can you investigate?

@jasonkliu
Copy link
Contributor Author

@brson Regarding the icon issue, it happens to be fontello/fontello#156. Interestingly, the bug only appears in Firefox. I've switched the svg font to a woff font and tested with these browsers, which seem to work: 3135402
Chrome 37.0.2041.4 dev
Firefox Aurora 31.0a2 (2014-05-28)
Safari Version 7.0.2 (9537.74.9)
Opera 22.0.1471.50
Sadly, I don't have IE to test at the moment. Do I have to create a new pull request for this change and the other change? Does Github support reopening pull requests?

@brson
Copy link
Contributor

brson commented Jun 17, 2014

@jasonkliu Thanks for looking into it so quickly. You'll need to create a new PR.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants