Skip to content

Commit

Permalink
Make default source with picture markup an img element, remove newline
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Wierzbowski committed Jul 15, 2013
1 parent 6faa014 commit 4df38be
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/output.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
<source src="/generated/portrait-675x456-28f3ea.jpg" media="(min-width: 30em) and (-webkit-min-device-pixel-ratio: 1.5), (min-width: 30em) and (min-resolution: 144dpi)">
<source src="/generated/portrait-450x304-28f3ea.jpg" media="(min-width: 30em)">
<source src="/generated/portrait-525x300-28f3ea.jpg" media="(-webkit-min-device-pixel-ratio: 1.5), (min-resolution: 144dpi)">
<source src="/generated/portrait-350x200-28f3ea.jpg">
<img src="/generated/portrait-350x200-28f3ea.jpg" alt="An example of picture markup">
<p>An example of picture markup</p>
</picture>
9 changes: 6 additions & 3 deletions picture_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,18 @@ def render(context)

source_tags = ''
source_keys.each { |source|
media = " media=\"#{preset[source]['media']}\"" unless source == 'source_default'
source_tags += "<source src=\"#{preset[source][:generated_src]}\"#{media}>\n"
if source == 'source_default'
source_tags += "<img src=\"#{preset[source][:generated_src]}\" alt=\"#{html_attr['alt']}\">\n"
else
source_tags += "<source src=\"#{preset[source][:generated_src]}\" media=\"#{preset[source]['media']}\">\n"
end
}

# Note: we can't indent html output because markdown parsers will turn 4 spaces into code blocks
picture_tag = "<picture #{html_attr_string}>\n"\
"#{source_tags}"\
"<p>#{html_attr['alt']}</p>\n"\
"</picture>\n"
"</picture>"
end

# Return the markup!
Expand Down

0 comments on commit 4df38be

Please sign in to comment.