Module: Card::Set::All::ReferenceEditor::NestEditor::HtmlFormat

Extended by:
Card::Set::AbstractFormat
Defined in:
card/tmpsets/set/mod037-card-mod-tinymce_editor/all/reference_editor/nest_editor.rb,
card/tmpsets/set/mod038-card-mod-tinymce_editor/all/reference_editor/nest_editor.rb

Instance Method Summary collapse

Instance Method Details

#default_active_tabObject



59
60
61
# File 'card/tmpsets/set/mod037-card-mod-tinymce_editor/all/reference_editor/nest_editor.rb', line 59

def default_active_tab
  voo.show?(:content_tab) ? :content : :options
end

#default_nest_editor_item_optionsObject



115
116
117
# File 'card/tmpsets/set/mod037-card-mod-tinymce_editor/all/reference_editor/nest_editor.rb', line 115

def default_nest_editor_item_options
  [[:view, default_item_view]]
end

#empty_nest_name_alert(show) ⇒ Object



87
88
89
90
91
92
# File 'card/tmpsets/set/mod037-card-mod-tinymce_editor/all/reference_editor/nest_editor.rb', line 87

def empty_nest_name_alert show
  alert :warning, false, false,
        class: "mb-0 _empty-nest-name-alert #{'d-none' unless show}" do
    "nest name required" # LOCALIZE
  end
end

#known_nest_contentObject



165
166
167
168
169
170
171
172
173
174
175
# File 'card/tmpsets/set/mod037-card-mod-tinymce_editor/all/reference_editor/nest_editor.rb', line 165

def known_nest_content
  voo.hide! :cancel_button
  add_name_context
  with_nest_mode :edit do
    frame do
      [
        render_edit_inline
      ]
    end
  end
end


94
95
96
97
98
# File 'card/tmpsets/set/mod037-card-mod-tinymce_editor/all/reference_editor/nest_editor.rb', line 94

def modal_nest_editor
  wrap_with :modal do
    nest_editor :modal
  end
end

#name_dependent_slotObject



76
77
78
79
80
81
82
83
84
85
# File 'card/tmpsets/set/mod037-card-mod-tinymce_editor/all/reference_editor/nest_editor.rb', line 76

def name_dependent_slot
  result = [empty_nest_name_alert(nest_snippet.name.blank?)]
  result <<
    if nest_snippet.name.blank?
       :div, "", class: "card-slot" # placeholder
    else
      yield
    end
  result
end

#nest_apply_optsObject



153
154
155
# File 'card/tmpsets/set/mod037-card-mod-tinymce_editor/all/reference_editor/nest_editor.rb', line 153

def nest_apply_opts
  apply_tm_snippet_data nest_snippet
end

#nest_content_tabObject



63
64
65
66
67
68
# File 'card/tmpsets/set/mod037-card-mod-tinymce_editor/all/reference_editor/nest_editor.rb', line 63

def nest_content_tab
  name_dependent_slot do
    @nest_content_tab || nest(card.name.field(nest_snippet.name),
                              view: :nest_content, hide: :guide)
  end
end

#nest_editor(editor_mode) ⇒ Object



38
39
40
41
42
43
44
# File 'card/tmpsets/set/mod037-card-mod-tinymce_editor/all/reference_editor/nest_editor.rb', line 38

def nest_editor editor_mode
  @tm_snippet_editor_mode = editor_mode
  voo.hide :content_tab unless show_content_tab?
  haml :reference_editor, ref_type: :nest, editor_mode: @tm_snippet_editor_mode,
                          apply_opts: nest_apply_opts,
                          snippet: nest_snippet
end

#nest_editor_tabsObject



46
47
48
49
50
51
52
53
# File 'card/tmpsets/set/mod037-card-mod-tinymce_editor/all/reference_editor/nest_editor.rb', line 46

def nest_editor_tabs
  tab_hash = {}
  tab_hash[:content] = nest_content_tab if voo.show? :content_tab
  tab_hash.merge! options: haml(:_options, snippet: nest_snippet),
                  rules: nest_rules_tab,
                  help: haml(:_help)
  tabs tab_hash, default_active_tab
end

#nest_option_name_disabled(selected, level) ⇒ Object



138
139
140
141
142
143
# File 'card/tmpsets/set/mod037-card-mod-tinymce_editor/all/reference_editor/nest_editor.rb', line 138

def nest_option_name_disabled selected, level
  disabled = nest_option_name_disabled_options level
  disabled = disabled&.map(&:first)
  disabled&.delete selected if selected
  disabled
end

#nest_option_name_disabled_options(level) ⇒ Object



145
146
147
148
149
150
151
# File 'card/tmpsets/set/mod037-card-mod-tinymce_editor/all/reference_editor/nest_editor.rb', line 145

def nest_option_name_disabled_options level
  if level == 0
    nest_snippet.options
  else
    nest_snippet.item_options[level - 1] || default_nest_editor_item_options
  end
end

#nest_option_name_select(selected = nil, level = 0) ⇒ Object



119
120
121
122
123
124
125
126
127
# File 'card/tmpsets/set/mod037-card-mod-tinymce_editor/all/reference_editor/nest_editor.rb', line 119

def nest_option_name_select selected=nil, level=0
  classes = "form-control form-control-sm _nest-option-name"
  classes += " _new-row" unless selected
  select_tag "nest_option_name_#{unique_id}",
             nest_option_name_select_options(selected, level),
             class: classes, id: nil
  # id: nil ensures that select2 generates its own unique identifier
  # that ensures that we can clone this tag without breaking select2
end

#nest_option_name_select_options(selected, level) ⇒ Object



129
130
131
132
133
134
135
136
# File 'card/tmpsets/set/mod037-card-mod-tinymce_editor/all/reference_editor/nest_editor.rb', line 129

def nest_option_name_select_options selected, level
  options = selected ? [] : ["--"]
  options += Card::Reference::NestParser::NEST_OPTIONS
  options_for_select(
    options, disabled: nest_option_name_disabled(selected, level),
             selected: selected
  )
end

#nest_option_value_select(value = nil) ⇒ Object



157
158
159
160
161
162
163
# File 'card/tmpsets/set/mod037-card-mod-tinymce_editor/all/reference_editor/nest_editor.rb', line 157

def nest_option_value_select value=nil
  # select_tag "nest_option_value_#{unique_id}"
  text_field_tag "value", value,
                 class: "_nest-option-value form-control form-control-sm",
                 disabled: !value,
                 id: nil
end

#nest_rules_tabObject



70
71
72
73
74
# File 'card/tmpsets/set/mod037-card-mod-tinymce_editor/all/reference_editor/nest_editor.rb', line 70

def nest_rules_tab
  name_dependent_slot do
    nest(set_name_for_nest_rules, view: :nest_rules)
  end
end

#nest_snippetObject



100
101
102
103
104
# File 'card/tmpsets/set/mod037-card-mod-tinymce_editor/all/reference_editor/nest_editor.rb', line 100

def nest_snippet
  @nest_snippet ||=
    Card::Reference::NestParser.new params[:tm_snippet_raw],
                                    default_nest_view, default_item_view
end

#set_name_for_nest_rulesObject



106
107
108
109
110
111
112
113
# File 'card/tmpsets/set/mod037-card-mod-tinymce_editor/all/reference_editor/nest_editor.rb', line 106

def set_name_for_nest_rules
  nest_name = nest_snippet.name
  if (type_name = card.left_type_for_nest_editor_set_selection)
    [type_name, nest_name, :type_plus_right]
  else
    [nest_name, :right]
  end
end

#show_content_tab?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'card/tmpsets/set/mod037-card-mod-tinymce_editor/all/reference_editor/nest_editor.rb', line 55

def show_content_tab?
  !card.is_structure?
end

#unknown_nest_contentObject



177
178
179
180
181
182
# File 'card/tmpsets/set/mod037-card-mod-tinymce_editor/all/reference_editor/nest_editor.rb', line 177

def unknown_nest_content
  voo.hide! :guide
  voo.show! :new_type_formgroup
  new_view_frame_and_form buttons: new_image_buttons,
                          success: { tinymce_id: Env.params[:tinymce_id] }
end


25
26
27
28
# File 'card/tmpsets/set/mod037-card-mod-tinymce_editor/all/reference_editor/nest_editor.rb', line 25

view :modal_nest_editor, cache: :never, unknown: true,
                         wrap: { slot: { class: "nodblclick" } } do
  modal_nest_editor
end

#view: nest_contentObject



30
31
32
33
34
35
36
# File 'card/tmpsets/set/mod037-card-mod-tinymce_editor/all/reference_editor/nest_editor.rb', line 30

view :nest_content, perms: :create, cache: :never, unknown: true, wrap: :slot do
  if card.known?
    known_nest_content
  else
    unknown_nest_content
  end
end

#view: nest_editorObject

Card::View::Options.shark_keys - %i[nest_syntax nest_name items cache] TODO: connect to Card::View::Options (that way a mod can add an option that becomes available to nests)



18
19
20
21
22
23
# File 'card/tmpsets/set/mod037-card-mod-tinymce_editor/all/reference_editor/nest_editor.rb', line 18

view :nest_editor, cache: :never, unknown: true,
                   wrap: {
                     slot: { class: "_overlay d0-card-overlay card nodblclick" }
                   } do
  nest_editor :overlay
end