Skip to content
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

Image rendering problem #2

Open
hrabalo opened this issue Mar 1, 2012 · 5 comments
Open

Image rendering problem #2

hrabalo opened this issue Mar 1, 2012 · 5 comments

Comments

@hrabalo
Copy link
Collaborator

hrabalo commented Mar 1, 2012

For some reason, images are not rendered in html... DIV with id, A with class and href and SPAN are rendered but image does not in all closures in the QrcodeTagLib class -> grails version 2.0.1 (possible incompatibility to resource 1.1.6 plugin)

def mkp = new MarkupBuilder(out)
mkp {
div('id':'qrcodebox') {
a('class':'qrcodeLink',href:"javascript:null",label) {
span('id':'qrcode') {
img(alt:url,src:src)
}
}
}
}

@hartsock
Copy link
Collaborator

hartsock commented Mar 1, 2012

The only criticism I'll make here initially is that any thing that renders an HTML fragment should never use hard-coded "id" since you are effectively dictating what page layout should be from the layer below the programmer creating the page.

I might also ask, where do "src" and "url" come from? I see nothing to suggest what they might be.

@hrabalo
Copy link
Collaborator Author

hrabalo commented Mar 1, 2012

"src" and "url" come from QrcodeTagLib.groovy by default:

def url = { attrs ->
def size = attrs.height?:attrs.width
String target = request.getRequestURL()
String src = createLink(controller:'qrcode',action:'url',params:[u:target,s:size])
def mkp = groovy.xml.new MarkupBuilder(out)
mkp {
div('id':'qrcodebox') {
a('class':'qrcodeLink',href:"javascript:null",label) {
span('id':'qrcode') {
img(alt:url,src:src)
}
}
}
}
}

when I print "src" and "url", they are OK, but only this is actualy rendered (without image):
< call>
< div id="qrcodebox">
< a class="qrcodeLink" href="javascript:null">
qrlink
< span class="qrcode"/>
< /a>
< /div>

when I try to render image directly in the QrcodeTagLib.groovy, like this

....
mkp {
div('class':'qrcodebox') {
a('class':'qrcodeLink',href:"javascript:null",label) {
span('class':'qrcode') {
img(alt:url,src:src)
}
}
}
}
out << "< img src="${src.encodeAsHTML()}"/>"

, everything works fine and output is:

< call>
< div class="qrcodebox">
< a class="qrcodeLink" href="javascript:null">
qrlink
< span class="qrcode"/>
< /a>
< /div>
< /call>
< img src="/myproject/qrcode/url?u=http%3A%2F%2Flocalhost%3A8080%2Fmyproject%2Fgrails%2Fhomepage.dispatch&s="/>

So I think maybe the implementation of the "img()" method has changed or as I wrote, there is maybe the incompatibility problem in the resource plugin. It uses "r.img()" method. Changing from : "ids" to "classes" attributes did not solve the problem.

@hartsock
Copy link
Collaborator

Please verify this has been fixed.

@hrabalo
Copy link
Collaborator Author

hrabalo commented Mar 15, 2012

The problem remains... It does not generate image. When I replace def mkp = new groovy.xml.MarkupBuilder(out) mkp { img(alt: text, src: src) } by out << "< img src="${src.encodeAsHTML()}"/>" in QrcodeTagLib.groovy everything works fine. I dont know why but maybe some problem with generating images in groovy.xml.MarkupBuilder

@hrabalo
Copy link
Collaborator Author

hrabalo commented Mar 15, 2012

Note: I am using Grails 2.0.1

@hartsock hartsock reopened this Mar 15, 2012
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

No branches or pull requests

2 participants