Module: Utopia::Tags::Gallery

Defined in:
lib/utopia/tags/gallery.rb,
lib/utopia/tags/gallery/version.rb,
lib/utopia/tags/gallery/container.rb,
lib/utopia/tags/gallery/thumbnail.rb

Defined Under Namespace

Modules: Processes Classes: Container, Metadata, Path

Constant Summary collapse

VERSION =
"1.2.0"
CACHE_DIR =
"_cache"

Class Method Summary collapse

Class Method Details

.call(transaction, state) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/utopia/tags/gallery.rb', line 47

def self.call(transaction, state)
	container = Container.new(transaction.end_tags[-2].node, Utopia::Path.create(state[:path] || "./"))
	 = container.
	.default = {}

	tag_name = state[:tag] || "img"
	container_class = state[:class] || "gallery"

	options = {}
	options[:process] = state[:process]
	
	if filetypes = state[:filetypes]
		options[:filter] = Regexp.new("(#{filetypes})$", "i")
	end
	
	if filter = state[:filter]
		filter = Regexp.new(filter, Regexp::IGNORECASE)
	end

	transaction.tag("div", class: container_class) do |node|
		items = container.each(options).sort do |a, b|
			if [a.original.last]["order"] and [b.original.last]["order"]
				[a.original.last]["order"] <=> [b.original.last]["order"]
			else
				a.original.last <=> b.original.last
			end
		end

		items.each do |path|
			next if filter and !filter.match(path.original.last)
	
			alt = Metadata.new([path.original.last])
			
			transaction.tag(tag_name, src: path, alt: alt)
		end
	end
end