Skip to content

Added html board#30

Closed
rgerkin wants to merge 3 commits intoniklasf:masterfrom
rgerkin:master
Closed

Added html board#30
rgerkin wants to merge 3 commits intoniklasf:masterfrom
rgerkin:master

Conversation

@rgerkin
Copy link
Contributor

@rgerkin rgerkin commented May 19, 2015

You can display the board in an Ipython notebook with:
from IPython import display

If you have a game running, you can continuously display the moves in one output cell with:

display.display(display.HTML(board.__html__()))

@landscape-bot
Copy link

Code Health
Repository health decreased by 0.04% when pulling 16dc4b0 on rgerkin:master into 417cb51 on niklasf:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.42%) to 90.82% when pulling 16dc4b0 on rgerkin:master into 417cb51 on niklasf:master.

@niklasf
Copy link
Owner

niklasf commented May 19, 2015

I am on the fence about this once. Is having an __html__ magic method (with double underscores) a common thing (like __str__ or __unicode__)? Maybe an IPython convention?

@rgerkin
Copy link
Contributor Author

rgerkin commented May 19, 2015

Are you on the fence about the value of the method, or just the naming convention? I'm happy to have it changed to just html(). I find it useful to watch the games while I interactively code in the IPython notebook, without having to connect to some other GUI frontend.

@niklasf
Copy link
Owner

niklasf commented May 19, 2015

Both.

First: Clearly if __html__ is not a widely used convention, we shouldn't mark it as a magic method. So html would be fine.

Then: Something about the CSS and HTML seams so arbitrary to me.

I guess I don't fully appreciate the usefulness because I never used IPython notebooks. Then again having such an html method shouldn't hurt. Do you know some other libraries that provide a similar HTML feature to look at for reference?

@rgerkin
Copy link
Contributor Author

rgerkin commented May 20, 2015

It's used somewhat frequently in web development libraries, e.g. here. But I'll change it to .html() if that's your vote.

For the arbitrariness of the CSS and HTML, an alternative implementation would be to have a static template (a board.html file in the project) with tags like {{A1}, {{A2}}, and so on, and then the html method would use a template engine (jinja or Mako, or simply string.Template) to substitute the corresponding pieces (their unicode representations) or lack thereof. This keeps content and style separate.

As for the utility of it, it goes beyond an IPython notebook. Any web interface using python-chess as part of the backend will want to have a board rendered in HTML.

@niklasf
Copy link
Owner

niklasf commented May 20, 2015

Oh, so __html__ is a thing. I didn't come up with anything useful when searching without the quotes. Let's get the simplest version in and maybe improve on it, later.

Edit: Added some more nitpicking.

Copy link
Owner

Choose a reason for hiding this comment

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

Let's avoid eval.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, I fixed this before but it reverted somehow... I think I branched from before the fix. I'll take care of it.

@landscape-bot
Copy link

Code Health
Code quality remained the same when pulling 089cc10 on rgerkin:master into 417cb51 on niklasf:master.

@niklasf niklasf closed this in 006f6a0 May 21, 2015
@niklasf
Copy link
Owner

niklasf commented May 21, 2015

Thank you! Committed and pushed. I took the liberty to remove the remaining trailing spaces.

niklasf pushed a commit that referenced this pull request Nov 30, 2016
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.

4 participants