Module: Card::Set::All::Html::Wrap::HtmlFormat

Extended by:
Card::Set::AbstractFormat
Defined in:
platypus/tmp/set/gem-defaults/mod004-format/all/html/wrap.rb

Instance Method Summary collapse

Instance Method Details

#body_css_classesObject



118
119
120
121
122
123
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/html/wrap.rb', line 118

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

#debug_slot(&block) ⇒ Object



87
88
89
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/html/wrap.rb', line 87

def debug_slot &block
  debug_slot? ? debug_slot_wrap(&block) : yield
end

#debug_slot?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/html/wrap.rb', line 91

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

#debug_slot_wrapObject



95
96
97
98
99
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/html/wrap.rb', line 95

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



23
24
25
26
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/html/wrap.rb', line 23

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



112
113
114
115
116
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/html/wrap.rb', line 112

def haml_wrap_body &block
  wrap_body do
    capture_haml(&block)
  end
end

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



28
29
30
31
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/html/wrap.rb', line 28

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



81
82
83
84
85
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/html/wrap.rb', line 81

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)


131
132
133
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/html/wrap.rb', line 131

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

#slot_attributes(slot, slot_attr) ⇒ Object



33
34
35
36
37
38
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/html/wrap.rb', line 33

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

#slot_cardnameObject



57
58
59
60
61
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/html/wrap.rb', line 57

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

#slot_idObject



40
41
42
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/html/wrap.rb', line 40

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

#slot_optionsObject



75
76
77
78
79
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/html/wrap.rb', line 75

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

#slot_options_jsonObject



71
72
73
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/html/wrap.rb', line 71

def slot_options_json
  html_escape_except_quotes JSON(slot_options)
end

#with_slot_data(slot) ⇒ Object



63
64
65
66
67
68
69
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/html/wrap.rb', line 63

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 'platypus/tmp/set/gem-defaults/mod004-format/all/html/wrap.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



108
109
110
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/html/wrap.rb', line 108

def wrap_body &block
  wrap_with(:div, class: body_css_classes, &block)
end

#wrap_classes(slot) ⇒ Object



101
102
103
104
105
106
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/html/wrap.rb', line 101

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 = false) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/html/wrap.rb', line 44

def wrap_data slot=false
  with_slot_data slot do
    {
      "card-id": card.id,
      "card-name": slot_cardname,
      "card-type-id": card.type_id,
      "card-type-name": card.type_name,
      "card-link-name": card.name.url_key,
      "slot-id": SecureRandom.hex(10)
    }
  end
end

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



140
141
142
143
144
145
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/html/wrap.rb', line 140

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



125
126
127
128
129
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/html/wrap.rb', line 125

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



135
136
137
138
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/html/wrap.rb', line 135

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