mbr / flask-nav

Easily create navigation for Flask applications.
http://pythonhosted.org/flask-nav/
MIT License
62 stars 37 forks source link

Feature view img #5

Open nypgand1 opened 8 years ago

nypgand1 commented 8 years ago

New element "ViewImg" for link with a img tag.

Used by issue #2 and template "Logo Nav" of Start Bootstrap.

http://startbootstrap.com/template-overviews/logo-nav/

nypgand1 commented 8 years ago

@mbr Hello there?

mbr commented 8 years ago

Hey, I haven't forgotten this pull request and am looking into it.

mbr commented 8 years ago

I'm willing to merge this for now, but cannot guarantee that it stays; but I'll try to make it work next time I'm hacking on Flask-Nav.

One of the issues I've had with this is that there are essentially two sets of **kwargs one would like to pass; the ones for url_for and any extra attributes for the img tag. Currently, img_src and img_alt are provided, however what if at some point you want an id or extra class on there? This could get ugly somewhat fast - especially if having an id will prevent you from using id as a parameter for url_for. It then becomes img_id and I feel it all might go downhill from there =).

An alternative I've been considering has been passing around dominate-tags, this would mean passing in the img-tag as an object. In this case, it would probably be more flexible to put this logic into View and renamed text to content; having everything work slightly similar to how it works with the JS DOM.

But, as I said above, I'll merge this, provided you drop the .gitignore =)

nypgand1 commented 8 years ago

Thanks for your advice and your great work!

hstarmans commented 7 years ago

Hey @nypgand1 ,

Thanks for your code, I was also looking at how to implement a logo in my Navbar. The code you made works, but produces two <li></li> tags.

<li>
      <li>
      <a href="/" title="logo">
        <img alt="logo" src="/static/logo.png">
      </a>
    </li>
    </li>

where i think it should be

   <li>
      <a href="/" title="logo">
        <img alt="logo" src="/static/logo.png">
      </a>
    </li>

The following should be sufficient:

def visit_ViewImg(self, node):
        a = tags.a(href=node.get_url(), title=node.text)
        a.add(tags.img(src=node.img_src, alt=node.img_alt))
        return a
imakiro commented 7 years ago

Hello, I was wondering if the project was still alive and the feature present here could be merged. Regards!