Module: Card::Set::All::RichHtml::Wrapper::HtmlFormat
- Extended by:
- Card::Set::AbstractFormat
- Defined in:
- tmpsets/set/mod021-standard/all/rich_html/wrapper.rb
Instance Method Summary collapse
- #body_css_classes ⇒ Object
- #debug_slot ⇒ Object
- #debug_slot? ⇒ Boolean
- #debug_slot_wrap ⇒ Object
- #haml_wrap(slot = true, slot_attr = {}, tag = :div, &block) ⇒ Object
- #haml_wrap_body ⇒ Object
- #method_wrap(method, tag, slot, slot_attr, &block) ⇒ Object
- #name_context_slot_option(opts) ⇒ Object
- #no_main_wrap? ⇒ Boolean
- #slot_attributes(slot, slot_attr) ⇒ Object
- #slot_id ⇒ Object
- #slot_options ⇒ Object
- #slot_options_json ⇒ Object
- #with_slot_data(slot) ⇒ Object
-
#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.
- #wrap_body ⇒ Object
- #wrap_classes(slot) ⇒ Object
- #wrap_data(slot = true) ⇒ Object
- #wrap_each_with(tag, content_or_args = {}, args = {}) ⇒ Object
- #wrap_main ⇒ Object
- #wrap_with(tag, content_or_args = {}, html_args = {}) ⇒ Object
Instance Method Details
#body_css_classes ⇒ Object
108 109 110 111 112 |
# File 'tmpsets/set/mod021-standard/all/rich_html/wrapper.rb', line 108 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 ⇒ Object
77 78 79 |
# File 'tmpsets/set/mod021-standard/all/rich_html/wrapper.rb', line 77 def debug_slot debug_slot? ? debug_slot_wrap { yield } : yield end |
#debug_slot? ⇒ Boolean
81 82 83 |
# File 'tmpsets/set/mod021-standard/all/rich_html/wrapper.rb', line 81 def debug_slot? params[:debug] == "slot" end |
#debug_slot_wrap ⇒ Object
85 86 87 88 89 |
# File 'tmpsets/set/mod021-standard/all/rich_html/wrapper.rb', line 85 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 |
# File 'tmpsets/set/mod021-standard/all/rich_html/wrapper.rb', line 24 def haml_wrap slot=true, slot_attr={}, tag=:div, &block method_wrap :haml_tag, tag, slot, slot_attr, &block end |
#haml_wrap_body ⇒ Object
102 103 104 105 106 |
# File 'tmpsets/set/mod021-standard/all/rich_html/wrapper.rb', line 102 def haml_wrap_body wrap_body do capture_haml { yield } end end |
#method_wrap(method, tag, slot, slot_attr, &block) ⇒ Object
28 29 30 31 32 33 |
# File 'tmpsets/set/mod021-standard/all/rich_html/wrapper.rb', line 28 def method_wrap method, tag, slot, slot_attr, &block @slot_view = @current_view debug_slot do send method, tag, slot_attributes(slot, slot_attr), &block end end |
#name_context_slot_option(opts) ⇒ Object
71 72 73 74 75 |
# File 'tmpsets/set/mod021-standard/all/rich_html/wrapper.rb', line 71 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
120 121 122 |
# File 'tmpsets/set/mod021-standard/all/rich_html/wrapper.rb', line 120 def no_main_wrap? Env.ajax? || params[:layout] == "none" end |
#slot_attributes(slot, slot_attr) ⇒ Object
35 36 37 38 39 40 |
# File 'tmpsets/set/mod021-standard/all/rich_html/wrapper.rb', line 35 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_id ⇒ Object
42 43 44 |
# File 'tmpsets/set/mod021-standard/all/rich_html/wrapper.rb', line 42 def slot_id "#{card.name.safe_key}-#{@current_view}-view" end |
#slot_options ⇒ Object
65 66 67 68 69 |
# File 'tmpsets/set/mod021-standard/all/rich_html/wrapper.rb', line 65 def = voo ? voo. : {} name_context_slot_option end |
#slot_options_json ⇒ Object
61 62 63 |
# File 'tmpsets/set/mod021-standard/all/rich_html/wrapper.rb', line 61 def html_escape_except_quotes JSON() end |
#with_slot_data(slot) ⇒ Object
53 54 55 56 57 58 59 |
# File 'tmpsets/set/mod021-standard/all/rich_html/wrapper.rb', line 53 def with_slot_data slot hash = yield # rails helper convert slot hash to json # but haml joins nested keys with a dash hash[:slot] = 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 |
# File 'tmpsets/set/mod021-standard/all/rich_html/wrapper.rb', line 13 def wrap slot=true, slot_attr={}, tag=:div, &block method_wrap :wrap_with, tag, slot, slot_attr, &block end |
#wrap_body ⇒ Object
98 99 100 |
# File 'tmpsets/set/mod021-standard/all/rich_html/wrapper.rb', line 98 def wrap_body wrap_with(:div, class: body_css_classes) { yield } end |
#wrap_classes(slot) ⇒ Object
91 92 93 94 95 96 |
# File 'tmpsets/set/mod021-standard/all/rich_html/wrapper.rb', line 91 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
46 47 48 49 50 51 |
# File 'tmpsets/set/mod021-standard/all/rich_html/wrapper.rb', line 46 def wrap_data slot=true with_slot_data slot do { "card-id": card.id, "card-name": h(card.name), "slot-id": SecureRandom.hex(10) } end end |
#wrap_each_with(tag, content_or_args = {}, args = {}) ⇒ Object
130 131 132 133 134 135 136 |
# File 'tmpsets/set/mod021-standard/all/rich_html/wrapper.rb', line 130 def wrap_each_with tag, content_or_args={}, args={} content = block_given? ? yield(args) : content_or_args args = block_given? ? content_or_args : args content.compact.map do |item| wrap_with(tag, args) { item } end.join "\n" end |
#wrap_main ⇒ Object
114 115 116 117 118 |
# File 'tmpsets/set/mod021-standard/all/rich_html/wrapper.rb', line 114 def wrap_main return yield if no_main_wrap? wrap_with :div, yield, id: "main" end |
#wrap_with(tag, content_or_args = {}, html_args = {}) ⇒ Object
124 125 126 127 128 |
# File 'tmpsets/set/mod021-standard/all/rich_html/wrapper.rb', line 124 def wrap_with tag, content_or_args={}, html_args={} content = block_given? ? yield : content_or_args tag_args = block_given? ? content_or_args : html_args content_tag(tag, tag_args) { output(content).to_s.html_safe } end |