-
Notifications
You must be signed in to change notification settings - Fork 32
Completed html renderer #137
Conversation
…hon-2017 Finished html renderer, and updating other files from the repo
|
Finished the circle class, too. I included subtraction, true division, floor division, modulo and reflective operators for add/subtract. I did not like the idea of circles with negative radii so I implemented the abs() unary operator, which I then used in the subtraction and r-sub operators. Question 1: do I really need to define a new radius and return a new circle with that radius? I wanted to just work with self, other, but odd things were happening I hope to attend office hours & during that time implement pow and other ones that make sense |
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 all looks great --nice work!
| newrad = self.radius - other.radius | ||
| return abs(Circle(newrad)) | ||
|
|
||
| def __mod__(self, other): |
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.
not sure how useful mod is for circles .. but what the heck for completeness' sake :;)
but couldn't you use the built-in mod operator: % ?
| close_tag = '{}</{}>'.format(current_ind, self.tag) | ||
| out_file.write(close_tag) | ||
|
|
||
| def render_open_tag(self, out_file, current_ind): |
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.
great idea to pull this out to a separate method.
but I think it's a bit cleaner to have this method return the entire tag as a string, and then actually write it to the out_file in the render method. That keeps all the actual file writing in one place.
| open_tag += ">" | ||
| return open_tag | ||
|
|
||
| def get_tag_attributes(self): |
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.
very nice!
|
|
||
| def render(self, out_file, current_ind=""): | ||
| # Render just a tag and any attributes, ignore contents | ||
| self.render_open_tag(out_file, current_ind) |
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.
since all this doing is calling render_open_tag(), and that is overidden this this subclass, you may as well put the code in there right in here.
unless you think there are other subclasses that might use this get_open_tag method.
| # Instructions said subclass from Element but we want it on one line | ||
| tag = 'a' | ||
|
|
||
| def __init__(self, link=None, content=None, **kwargs): |
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.
perfect! remarkably easy, isn't it?
| # render just one tag and any attributes | ||
|
|
||
| def render(self, out_file, current_ind=""): | ||
| # Render just a tag and any attributes, ignore contents |
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! but maybe you should raise an error if there are any contents -- probably in the init -- that would be better than simply ignoring it.
| return Circle(newrad) | ||
|
|
||
| def __rtruediv__(self, factor): | ||
| # reflective division... repeats code?? |
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.
it's reveresed -- is it giving the right answer? I woulndn't expect so!
but if it is repeated, you can re-use the previous definition:
def rtrudiv = truediv
pretty cool, eh?
|
|
||
| # ---------------- UNARY ARITHMETIC OPERATORS ----------------------- | ||
|
|
||
| def __abs__(self): |
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.
another one that may not make sense....
Completed all steps and am rendering lovely HTML. run_html_renderer.py produces great results, tests have I believe adequate coverage of relevant items, and in general I'm very happy with this. Oh and I refactored a few things to reduce repetition. If any review happens, it would be on the test coverage of steps 4-8 tasks. Thank you.