Class: Utopia::Gallery::Tags
- Inherits:
-
Object
- Object
- Utopia::Gallery::Tags
- Defined in:
- lib/utopia/gallery/tags.rb
Constant Summary collapse
- DEFAULT_PROCESSES =
[ ResizeImage.new(:small, [400, 400], :resize_to_fill), ResizeImage.new(:medium, [800, 800], :resize_to_fill), ResizeImage.new(:large, [1600, 1600], :resize_to_fit), ]
Instance Method Summary collapse
- #call(name, node) ⇒ Object
- #container(document, state) ⇒ Object
-
#initialize(media_root: Utopia.default_root, cache_root: Utopia.default_root('public/_gallery'), cache_path: '/_gallery', processes: DEFAULT_PROCESSES, container_class: 'gallery') ⇒ Tags
constructor
A new instance of Tags.
Constructor Details
#initialize(media_root: Utopia.default_root, cache_root: Utopia.default_root('public/_gallery'), cache_path: '/_gallery', processes: DEFAULT_PROCESSES, container_class: 'gallery') ⇒ Tags
Returns a new instance of Tags.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# 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 |
Instance Method Details
#call(name, node) ⇒ Object
81 82 83 84 |
# 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) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# 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]] = {} if filetypes = state[:filetypes] [:filter] = Regexp.new("(#{filetypes})$", Regexp::IGNORECASE) elsif filter = state[:filter] [:filter] = Regexp.new(filter, Regexp::IGNORECASE) end # Where should we get this from? container = Container.new(@media_root, path, **) 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 |