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

Extended by:
AbstractFormat
Includes:
File::HtmlFormat
Defined in:
platypus/tmp/set/gem-defaults/mod016-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



60
61
62
63
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/type/image/html_views.rb', line 60

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

#goto_autocomplete_iconObject



87
88
89
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/type/image/html_views.rb', line 87

def goto_autocomplete_icon
  render :core, size: :small
end

#invalid_image(source) ⇒ Object



38
39
40
41
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/type/image/html_views.rb', line 38

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



81
82
83
84
85
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/type/image/html_views.rb', line 81

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



65
66
67
68
69
70
71
72
73
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/type/image/html_views.rb', line 65

def old_image action, hide_diff
  return if hide_diff || !action

  old_image_change action do |old_action_id|
    card.with_selected_action_id old_action_id do
      Card::Content::Diff.render_deleted_chunk _render_core
    end
  end
end

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

Yields:

  • (change.card_action_id)


75
76
77
78
79
# File 'platypus/tmp/set/gem-defaults/mod016-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



43
44
45
46
47
48
49
50
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/type/image/html_views.rb', line 43

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)


52
53
54
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/type/image/html_views.rb', line 52

def show_action_content_toggle? _action, _view_type
  true
end

#view: content_changesObject



56
57
58
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/type/image/html_views.rb', line 56

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

#view: coreObject

core HTML image view.



12
13
14
15
16
17
18
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/type/image/html_views.rb', line 12

view :core do
  return card.attachment.read.html_safe if svg?

  with_valid_source do |source|
    image_tag source, alt: card.name
  end
end

#view: full_widthObject



32
33
34
35
36
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/type/image/html_views.rb', line 32

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

#with_valid_sourceObject



20
21
22
23
24
25
26
27
28
29
30
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/type/image/html_views.rb', line 20

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