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



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

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



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

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

#debug_slot?Boolean

Returns:

  • (Boolean)


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

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

#debug_slot_wrapObject



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

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



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

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



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

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)


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

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



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

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



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

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

#slot_options_jsonObject



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

def slot_options_json
  html_escape_except_quotes JSON(slot_options)
end

#with_slot_data(slot) ⇒ Object



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

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



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

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

#wrap_classes(slot) ⇒ Object



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

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
# 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-link-name": card.name.url_key,
      "slot-id": SecureRandom.hex(10)
    }
  end
end

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



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

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



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

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



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

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