Module: Card::Set::All::HtmlWrapper::HtmlFormat

Extended by:
Card::Set::AbstractFormat
Defined in:
card/tmpsets/set/mod008-card-mod-format/all/html_wrapper.rb,
card/tmpsets/set/mod007-card-mod-format/all/html_wrapper.rb

Instance Method Summary collapse

Instance Method Details

#body_css_classesObject



112
113
114
115
116
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_wrapper.rb', line 112

def body_css_classes
  css_classes = ["d0-card-body"]
  css_classes += ["d0-card-content", card.safe_set_keys] if @content_body
  classy(*css_classes)
end

#debug_slot(&block) ⇒ Object



81
82
83
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_wrapper.rb', line 81

def debug_slot
  debug_slot? ? debug_slot_wrap { yield } : yield
end

#debug_slot?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_wrapper.rb', line 85

def debug_slot?
  params[:debug] == "slot"
end

#debug_slot_wrapObject



89
90
91
92
93
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_wrapper.rb', line 89

def debug_slot_wrap
  pre = "<!--\n\n#{'  ' * depth}"
  post = " SLOT: #{h card.name}\n\n-->"
  [pre, "BEGIN", post, yield, pre, "END", post].join
end

#haml_wrap(slot = true, slot_attr = {}, tag = :div, &block) ⇒ Object



24
25
26
27
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_wrapper.rb', line 24

def haml_wrap slot=true, slot_attr={}, tag=:div, &block
  attrib = slot_attributes slot, slot_attr
  method_wrap :haml_tag, tag, attrib, &block
end

#haml_wrap_body(&block) ⇒ Object



106
107
108
109
110
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_wrapper.rb', line 106

def haml_wrap_body
  wrap_body do
    capture_haml { yield }
  end
end

#method_wrap(method, tag, attrib, &block) ⇒ Object



29
30
31
32
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_wrapper.rb', line 29

def method_wrap method, tag, attrib, &block
  @slot_view = @current_view
  debug_slot { send method, tag, attrib, &block }
end

#name_context_slot_option(opts) ⇒ Object



75
76
77
78
79
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_wrapper.rb', line 75

def name_context_slot_option opts
  return unless initial_context_names.present?

  opts[:name_context] = initial_context_names.map(&:key) * ","
end

#no_main_wrap?Boolean

Returns:

  • (Boolean)


124
125
126
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_wrapper.rb', line 124

def no_main_wrap?
  Env.ajax? || params[:layout] == "none"
end

#slot_attributes(slot, slot_attr) ⇒ Object



34
35
36
37
38
39
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_wrapper.rb', line 34

def slot_attributes slot, slot_attr
  { id: slot_id, class: wrap_classes(slot), data: wrap_data }.tap do |hash|
    add_class hash, slot_attr.delete(:class)
    hash.deep_merge! slot_attr
  end
end

#slot_cardnameObject



51
52
53
54
55
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_wrapper.rb', line 51

def slot_cardname
  name = card.name
  name = card.new? && name.compound? ? name.url_key : name
  h name
end

#slot_idObject



41
42
43
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_wrapper.rb', line 41

def slot_id
  "#{card.name.safe_key}-#{@current_view}-view"
end

#slot_optionsObject



69
70
71
72
73
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_wrapper.rb', line 69

def slot_options
  options = voo ? voo.slot_options : {}
  name_context_slot_option options
  options
end

#slot_options_jsonObject



65
66
67
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_wrapper.rb', line 65

def slot_options_json
  html_escape_except_quotes JSON(slot_options)
end

#with_slot_data(slot) ⇒ Object



57
58
59
60
61
62
63
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_wrapper.rb', line 57

def with_slot_data slot
  hash = yield
  # rails helper convert slot hash to json
  # but haml joins nested keys with a dash
  hash[:slot] = slot_options_json if slot
  hash
end

#wrap(slot = true, slot_attr = {}, tag = :div, &block) ⇒ Object

Does two main things: (1) gives CSS classes for styling and (2) adds card data for javascript - including the “card-slot” class, which in principle is not supposed to be in styles



13
14
15
16
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_wrapper.rb', line 13

def wrap slot=true, slot_attr={}, tag=:div, &block
  attrib = slot_attributes slot, slot_attr
  method_wrap :wrap_with, tag, attrib, &block
end

#wrap_body(&block) ⇒ Object



102
103
104
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_wrapper.rb', line 102

def wrap_body
  wrap_with(:div, class: body_css_classes) { yield }
end

#wrap_classes(slot) ⇒ Object



95
96
97
98
99
100
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_wrapper.rb', line 95

def wrap_classes slot
  list = slot ? ["card-slot"] : []
  list += ["#{@current_view}-view", card.safe_set_keys]
  list << "STRUCTURE-#{voo.structure.to_name.key}" if voo&.structure
  classy list
end

#wrap_data(slot = true) ⇒ Object



45
46
47
48
49
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_wrapper.rb', line 45

def wrap_data slot=true
  with_slot_data slot do
    { "card-id": card.id, "card-name": slot_cardname, "slot-id": SecureRandom.hex(10) }
  end
end

#wrap_each_with(tag, content_or_args = {}, args = {}, &block) ⇒ Object



133
134
135
136
137
138
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_wrapper.rb', line 133

def wrap_each_with tag, content_or_args={}, args={}, &block
  tag_args = block_given? ? content_or_args : args
  content_items_within_wrap(content_or_args, args, &block).map do |item|
    wrap_with(tag, tag_args) { item }
  end.join "\n"
end

#wrap_mainObject



118
119
120
121
122
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_wrapper.rb', line 118

def wrap_main
  return yield if no_main_wrap?

  wrap_with :div, yield, id: "main"
end

#wrap_with(tag, content_or_args = {}, html_args = {}, &block) ⇒ Object



128
129
130
131
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_wrapper.rb', line 128

def wrap_with tag, content_or_args={}, html_args={}, &block
  tag_args = block_given? ? content_or_args : html_args
  (tag, tag_args) { content_within_wrap content_or_args, &block }
end