class Utopia::Gallery::Tags

Constants

DEFAULT_PROCESSES

Public Class Methods

new(media_root: Utopia.default_root, cache_root: Utopia.default_root('public/_gallery'), cache_path: '/_gallery', processes: DEFAULT_PROCESSES, container_class: 'gallery') click to toggle source

@param media_root [String] Directory where media is stored. @param cache_root [String] Directory where media is cached. @param cache_root [String] The prefix path for the cached assets, served as static content.

# File lib/utopia/gallery/tags.rb, line 39
def initialize(media_root: Utopia.default_root, cache_root: Utopia.default_root('public/_gallery'), cache_path: '/_gallery', processes: DEFAULT_PROCESSES, container_class: 'gallery')
        @media_root = media_root
        @cache_root = cache_root
        @cache_path = cache_path
        @processes = {}
        
        @container_class = container_class
        
        processes.each do |process|
                name = process.name
                
                raise ArgumentError.new("Duplicate process #{name}") if @processes.include?(name)
                
                @processes[name] = process
        end
end

Public Instance Methods

call(name, node) click to toggle source
# File lib/utopia/gallery/tags.rb, line 81
def call(name, node)
        # TODO: Validate security implications/leaky abstraction.
        self.method(name)
end
container(document, state) click to toggle source
# File lib/utopia/gallery/tags.rb, line 56
def container(document, state)
        node = document.parent.node
        path = node.uri_path.dirname + Utopia::Path[state[:path]]
        
        options = {}
        if filetypes = state[:filetypes]
                options[:filter] = Regexp.new("(#{filetypes})$", Regexp::IGNORECASE)
        elsif filter = state[:filter]
                options[:filter] = Regexp.new(filter, Regexp::IGNORECASE)
        end
        
        # Where should we get this from?
        container = Container.new(@media_root, path, **options)
        
        media_tag_name = state[:tag] || 'img'
        container_class = state[:class] || @container_class
        
        document.tag('div', class: container_class) do
                container.sort.each do |media|
                        cache = Cache.new(@media_root, @cache_root, @cache_path, media, @processes).update
                        document.tag(media_tag_name, src: cache, alt: media)
                end
        end
end