# -*- encoding : utf-8 -*- class Card; module Set; class Type # Set: All "Image" cards # module Image; extend Card::Set def self.source_location; "/Users/ethan/dev/decko/gem/card/mod/carrierwave/set/type/image.rb"; end attachment :image, uploader: CarrierWave::ImageCardUploader include File::SelectedAction def create_versions? new_file new_file.extension != "svg" end def svg? image&.extension == ".svg" end module Format; parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat include File::Format view :closed_content do _render_core size: :icon end def short_content render_core size: :icon end view :source do return card.content if card.web? image = selected_version return "" unless image.valid? contextualize_path image.url end def selected_version size = determine_image_size if size && size != :original card.image.versions[size] else card.image end end def handle_source super end def closed_size :icon end def main_size :large end def default_size :medium end def determine_image_size voo.size = case when nest_mode == :closed then closed_size when voo.size then voo.size.to_sym when main? then main_size else default_size end voo.size = :original if voo.size == :full voo.size end end module HtmlFormat; parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat include File::HtmlFormat # core HTML image view. view :core do return card.attachment.read if card.svg? with_valid_source do |source| image_tag source, alt: card.name end end def with_valid_source handle_source do |source| if source.blank? || source == "missing" # FIXME: these images should be "broken", not "missing" invalid_image source else yield source # consider title.. end end end view :full_width do with_valid_source do |source| image_tag source, alt: card.name, class: "w-100" end end def invalid_image source # ("missing" is the view for "unknown" now, so we shouldn't further confuse things) "" end def preview return if card.new_card? && !card.preliminary_upload? wrap_with :div, class: "attachment-preview", id: "#{card.attachment.filename}-preview" do _render_core size: :medium end end def show_action_content_toggle? _action, _view_type true end view :content_changes do content_changes card.last_action, :expanded end def content_changes action, diff_type, hide_diff=false voo.size = diff_type == :summary ? :icon : :medium [old_image(action, hide_diff), new_image(action)].compact.join end def old_image action, hide_diff return if hide_diff || !action return unless (last_change = card.last_change_on(:db_content, before: action)) card.with_selected_action_id last_change.card_action_id do Card::Content::Diff.render_deleted_chunk _render_core end end def new_image action card.with_selected_action_id action.id do Card::Content::Diff.render_added_chunk _render_core end end end module Format; parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat view :inline do _render_core end end module EmailHtmlFormat; parent.send :register_set_format, Card::Format::EmailHtmlFormat, self; extend Card::Set::AbstractFormat view :inline, cache: :never do handle_source do |source| return source unless (mail = inherit :active_mail) && ::File.exist?(path = selected_version.path) url = attach_image mail, path image_tag url end end def attach_image mail, path mail.attachments.inline[path] = ::File.read path mail.attachments[path].url end end module CssFormat; parent.send :register_set_format, Card::Format::CssFormat, self; extend Card::Set::AbstractFormat view :core do handle_source end view :content do # why is this necessary? render_core end end module FileFormat; parent.send :register_set_format, Card::Format::FileFormat, self; extend Card::Set::AbstractFormat include File::FileFormat end end;end;end;end; # ~~ generated from /Users/ethan/dev/decko/gem/card/mod/carrierwave/set/type/image.rb ~~