Module: Card::Set::Type::Image::HtmlViews::HtmlFormat

Extended by:
AbstractFormat
Includes:
File::HtmlFormat
Defined in:
card/tmpsets/set/mod014-card-mod-carrierwave/type/image/html_views.rb,
card/tmpsets/set/mod013-card-mod-carrierwave/type/image/html_views.rb

Instance Method Summary collapse

Methods included from File::HtmlFormat

#cached_upload_card_name, #file_chooser_action_text, #humanized_attachment_name, #preview_editor_delete_text, #view: input, #view: preview_editor

Instance Method Details

#content_changes(action, diff_type, hide_diff = false) ⇒ Object



58
59
60
61
# File 'card/tmpsets/set/mod014-card-mod-carrierwave/type/image/html_views.rb', line 58

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

#invalid_image(source) ⇒ Object



37
38
39
40
# File 'card/tmpsets/set/mod014-card-mod-carrierwave/type/image/html_views.rb', line 37

def invalid_image source
  # ("missing" is the view for "unknown" now, so we shouldn't further confuse things)
  "<!-- invalid image for #{safe_name}; source: #{source} -->"
end

#new_image(action) ⇒ Object



71
72
73
74
75
# File 'card/tmpsets/set/mod014-card-mod-carrierwave/type/image/html_views.rb', line 71

def new_image action
  card.with_selected_action_id action.id do
    Card::Content::Diff.render_added_chunk _render_core
  end
end

#old_image(action, hide_diff) ⇒ Object



63
64
65
66
67
68
69
# File 'card/tmpsets/set/mod014-card-mod-carrierwave/type/image/html_views.rb', line 63

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

#old_image_change(action) {|change.card_action_id| ... } ⇒ Object

Yields:

  • (change.card_action_id)


75
76
77
78
79
# File 'card/tmpsets/set/mod013-card-mod-carrierwave/type/image/html_views.rb', line 75

def old_image_change action
  return unless (change = card.last_change_on(:db_content, before: action))

  yield change.card_action_id
end

#previewObject



42
43
44
45
46
47
48
# File 'card/tmpsets/set/mod014-card-mod-carrierwave/type/image/html_views.rb', line 42

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

#show_action_content_toggle?(_action, _view_type) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'card/tmpsets/set/mod014-card-mod-carrierwave/type/image/html_views.rb', line 50

def show_action_content_toggle? _action, _view_type
  true
end

#view: content_changesObject



54
55
56
# File 'card/tmpsets/set/mod014-card-mod-carrierwave/type/image/html_views.rb', line 54

view :content_changes do
  content_changes card.last_action, :expanded
end

#view: coreObject

core HTML image view.



12
13
14
15
16
17
# File 'card/tmpsets/set/mod014-card-mod-carrierwave/type/image/html_views.rb', line 12

view :core do
  return card.attachment.read if card.svg?
  with_valid_source do |source|
    image_tag source, alt: card.name
  end
end

#view: full_widthObject



31
32
33
34
35
# File 'card/tmpsets/set/mod014-card-mod-carrierwave/type/image/html_views.rb', line 31

view :full_width do
  with_valid_source do |source|
    image_tag source, alt: card.name, class: "w-100"
  end
end

#with_valid_sourceObject



19
20
21
22
23
24
25
26
27
28
29
# File 'card/tmpsets/set/mod014-card-mod-carrierwave/type/image/html_views.rb', line 19

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