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

Built on compound-block demo #66

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions lib/imagegallery-block.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
require 'asciidoctor'
require 'asciidoctor/extensions'
counter = 'a'

Asciidoctor::Extensions.register do
block do
named :gallery
on_context :open
# A bit hacky. Each image gallery needs a unique string:
# http://stackoverflow.com/questions/88311/how-best-to-generate-a-random-string-in-ruby#88341
o = [('a'..'z'), ('A'..'Z')].map { |i| i.to_a }.flatten
process do |parent, reader, attrs|
lines = []
wrapper = create_open_block parent, [], {}
parse_content wrapper, reader
counter = (0...50).map { o[rand(o.length)] }.join
wrapper.find_by(context: :image).each do |img|
src = img.attr 'target'
alt = img.attr 'alt'
thumb_src = src.sub(/\.[^.]+$/, '-thumb\0')
#lines << %(image:#{thumb_src}[#{alt}, title="#{img.attr 'title'}", role=fancybox-effects, link=#{parent.image_uri src}])
lines << %(<a class="fancybox" rel="fancybox-#{counter}" href="#{parent.image_uri src}" title="#{img.attr 'title'}"><img src="#{parent.image_uri thumb_src}" alt="#{alt}"></a>)
end
create_paragraph parent, lines, {}, subs: nil
end
end

docinfo_processor do
at_location :head
process do |doc|
result = []
backend = doc.backend
if backend == 'html5'
result << %(
Copy link
Contributor

Choose a reason for hiding this comment

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

The result Array is not needed here. You can just remove it and replace

result << %(

with

%(

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.min.css" type="text/css" media="screen" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.pack.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/helpers/jquery.fancybox-buttons.css" type="text/css" media="screen" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/helpers/jquery.fancybox-buttons.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/helpers/jquery.fancybox-media.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/helpers/jquery.fancybox-thumbs.css" type="text/css" media="screen" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/helpers/jquery.fancybox-thumbs.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".fancybox").fancybox();
});
</script>)
elsif backend == 'xhtml5'
result << %(
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.min.css" type="text/css" media="screen" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.pack.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/helpers/jquery.fancybox-buttons.css" type="text/css" media="screen" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/helpers/jquery.fancybox-buttons.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/helpers/jquery.fancybox-media.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/helpers/jquery.fancybox-thumbs.css" type="text/css" media="screen" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/helpers/jquery.fancybox-thumbs.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".fancybox").fancybox();
});
</script>)
end
end
end

end
Binary file added lib/imagegallery-block/a-thumb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/imagegallery-block/a.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/imagegallery-block/b-thumb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/imagegallery-block/b.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/imagegallery-block/c-thumb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/imagegallery-block/c.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/imagegallery-block/d-thumb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/imagegallery-block/d.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions lib/imagegallery-block/sample.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[gallery]
--
image::a.jpg[title="This is the title of image a"]
image::b.jpg[title="This is the title of image b"]
--


[gallery]
--
image::c.jpg[title="This is the title of image c"]
image::d.jpg[title="This is the title of image d"]
--
453 changes: 453 additions & 0 deletions lib/imagegallery-block/sample.html

Large diffs are not rendered by default.