Class: Cyberweb::Objectified::HtmlTags::Table

Inherits:
Base
  • Object
show all
Defined in:
lib/cyberweb/objectified/html_tags/table.rb

Overview

Cyberweb::Objectified::HtmlTags::Table

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#+, #add_css_rules, #add_this_to_javascript, #add_to_pre_content, #append_css_manager, #append_onto_the_css_class, #append_onto_the_result, #append_this_to_the_css_style, #attach, #batch_append_css_class_then_the_ID_and_then_the_css_style, #bblack1, #bblack2, #bblack3, #bblack4, #bblack5, #bblack6, #center, #consider_adding_the_pre_content, #consider_adding_the_script_entry_from_the_internal_hash, #content?, #content_as_string, #css_class?, #css_manager, #css_style?, #display, #do_not_load_lazily, #ee, #enable_lazy_loading, #evaluate_this_block, #font=, #id?, #is_an_objectified_html_tag?, #is_draggable?, #lazy_loading?, #make_bold, #modify_the_css_style_based_on_the_alignment, #name=, #name?, #on_click_select, #on_clicked, #on_hover_colour, #on_hover_pulse_increase, #on_mouse_hover, #pad, #pad10px, #pad1px, #pad2px, #pad3px, #pad4px, #pad5px, #pad6px, #pad7px, #pad8px, #pad9px, #path_to_internal_javascript_file, #pre_content?, #raw_result?, report, #report, #report?, #reset_the_content, #reset_the_result, #return_appendable_content, #return_css_class, #return_css_style, #return_javascript, #script?, #set_content, #set_css_class, #set_css_style, #set_id, #set_is_draggable, #set_title, #set_width, #title?, #to_str, #try_to_register_this_tag, #use_this_on_click_function=, #very_light_yellowish_background, #width_height, #yellow_background

Methods included from BaseModule

#attach_these_constants, #base_dir?, #beautiful_url, #cd, #create_the_internal_hash, #doctype?, #ee, #ensure_main_encoding, #esystem, #html_templates, #initialize_the_config_if_the_config_hash_is_empty, #internal_hash?, #log_dir?, #no_http, #random_alphabet_characters, #rarrow?, #rds, #remove_comments_from_this_string, #remove_numbers, #require_the_html_templates, #require_these, #return_file_size_in_kb_of, #return_html_comment, #ruby_sitelib_dir?, #sanitize_this_id, #server_base_directory?, #string_remote_image, #today?, #try_to_require_rack, #try_to_require_the_open_gem, #write_what_into

Methods included from BaseModule::ContentType

#content_type_is_html, #content_type_is_jpeg, #content_type_is_json, #content_type_is_plain_text

Methods included from BaseModule::CommandlineArguments

#append_to_the_commandline_arguments, #commandline_arguments?, #first_argument?, #parse_these_commandline_arguments, #second_argument?, #set_commandline_arguments

Methods included from BaseModule::Colours

#all_html_colours, #lightgreen, #rev, #sdir, #sfancy, #sfile, #simp, #steelblue, #tomato

Constructor Details

#initialize(use_this_text = '', optional_css_class = Table.css_class?, optional_id = nil, optional_css_style = nil) ⇒ Table

#

initialize

Usage example:

Cyberweb::Objectified::HtmlTags::Table.new(i)
#


62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/cyberweb/objectified/html_tags/table.rb', line 62

def initialize(
    use_this_text      = '',
    optional_css_class = Table.css_class?,
    optional_id        = nil,
    optional_css_style = nil
  )
  try_to_register_this_tag(self)
  reset
  set_content(use_this_text) # This should be an Array really.
  set_CSS_class(optional_css_class) if optional_css_class
  set_id(optional_id)               if optional_id
  set_CSS_style(optional_css_style) if optional_css_style
end

Class Method Details

.alternate_backgrounds(array, optional_css_class = '') ⇒ Object

#

Cyberweb::Table.alternate_backgrounds

Next, define the method Table.alternate_backgrounds().

The first argument to this method must be an Array.

Usage examples:

Cyberweb::Table.alternate_backgrounds(%w( one two three four ), 'bblack1 pad0_5em')
Table.alternate_backgrounds(%w( one two three four ), 'bblack1 pad0_5em')
#


320
321
322
323
324
# File 'lib/cyberweb/objectified/html_tags/table.rb', line 320

def Table.alternate_backgrounds(
    array, optional_css_class = ''
  )
  ee ::Cyberweb::Table.return_alternate_backgrounds(array, optional_css_class)
end

.clearObject

#

Cyberweb::Objectified::HtmlTags::Table.clear

#


36
37
38
# File 'lib/cyberweb/objectified/html_tags/table.rb', line 36

def self.clear
  Table.set_css_class('')
end

.css_class?Boolean

#

Cyberweb::Objectified::HtmlTags::Table.css_class?

#

Returns:

  • (Boolean)


50
51
52
# File 'lib/cyberweb/objectified/html_tags/table.rb', line 50

def self.css_class?
  @css_class
end

.enable_paddingObject

#

Cyberweb::Table.enable_padding

#


303
304
305
# File 'lib/cyberweb/objectified/html_tags/table.rb', line 303

def Table.enable_padding # This is supposed to enable padding.
  Table.set_css_class 'pad15px'
end

.padding=(i) ⇒ Object

#

Cyberweb::Table.padding=

This is an alias towards “bspace”, aka the “border-spacing” property.

#


245
246
247
# File 'lib/cyberweb/objectified/html_tags/table.rb', line 245

def Table.padding=(i)
  Table.set_css_class('bspace'+i.to_s)
end

.parse(*i) ⇒ Object

#

Table.parse

#


236
237
238
# File 'lib/cyberweb/objectified/html_tags/table.rb', line 236

def Table.parse(*i)
  ::Cyberweb.parse_table(i)
end

.reset_css_classObject

#

Cyberweb::Objectified::HtmlTags::Table.reset_css_class

#


29
30
31
# File 'lib/cyberweb/objectified/html_tags/table.rb', line 29

def self.reset_css_class
  @css_class = nil
end

.return_alternate_backgrounds(array = [], optional_css_class = '', &block) ⇒ Object

#

Cyberweb::Table.return_alternate_backgrounds

This table will use alternative backgrounds.

#


254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'lib/cyberweb/objectified/html_tags/table.rb', line 254

def Table.return_alternate_backgrounds(
    array              = [],
    optional_css_class = '',
    &block
  )
  _use_this_class_for_even_rows = 'dark_background'
  _use_this_class_for_odd_rows  = 'light_background'
  # ===================================================================== #
  # === Handle blocks next
  # ===================================================================== #
  if block_given?
    yielded = yield
    if array.empty? and !yielded.empty?
      array = yielded
    end
  end
  table = Cyberweb::Objectified::HtmlTags::Table.new(optional_css_class)
  table.alternate_backgrounds(
    array,
    optional_css_class
  )
  # ========================================================================= #
  # The old code in October 2021 was the following:
  #   _ = '<table'.dup
  #   _ << ::Cyberweb.return_css_class(optional_css_class)
  #   _ << '>'
  #   array.each_with_index {|entry, index|
  #     _ << "<tr>#{N}"
  #     case index % 2
  #     when 0
  #       _ << '<td class="'+use_this_class_for_even_rows+'">'+N
  #     when 1
  #       _ << '<td class="'+use_this_class_for_odd_rows+'">'+N
  #     end
  #     _ << entry+N
  #     _ << '</td>'+N
  #     _ << '</tr>'+N
  #   }
  #   _ << '</table>'+N
  #   return _
  #
  # It will be retained for a bit longer in the comment above.
  # ========================================================================= #
  return table.to_s
end

.set_css_class(i = DEFAULT_CSS_CLASS) ⇒ Object

#

Cyberweb::Objectified::HtmlTags::Table.set_css_class

#


43
44
45
# File 'lib/cyberweb/objectified/html_tags/table.rb', line 43

def self.set_css_class(i = DEFAULT_CSS_CLASS)
  @css_class = i
end

Instance Method Details

#alternate_backgrounds(array = [], optional_css_class = 'bblack3 pad0_5em', &block) ⇒ Object

#

alternate_backgrounds

#


127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/cyberweb/objectified/html_tags/table.rb', line 127

def alternate_backgrounds(
    array              = [],
    optional_css_class = 'bblack3 pad0_5em',
     &block
  )
  use_this_class_for_even_rows = 'dark_background'
  use_this_class_for_odd_rows  = 'light_background'
  if optional_css_class
    set_css_class(optional_css_class)
  end
  # ======================================================================= #
  # This currently only works for tables with two entries per
  # row. At a later point this restrictions may be lifted.
  # ======================================================================= #
  reset_the_content
  array.each_with_index {|entry, index|
    append_onto_content "<tr>#{N}"
    case index % 2
    when 0
      append_onto_content '<td class="'+use_this_class_for_even_rows+'">'+N
    when 1
      append_onto_content '<td class="'+use_this_class_for_odd_rows+'">'+N
    end
    append_onto_content entry+N
    append_onto_content '</td>'+N
    case index % 2
    when 1
      append_onto_content '</tr>'+N
    end
  }
  @internal_hash[:shall_we_modify_the_content] = false
end

#append_the_content(content = content? ) ⇒ Object

#

append_the_content

This will append the content onto the :result variable.

In this context, content refers to <tr><td> entries,

#


167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/cyberweb/objectified/html_tags/table.rb', line 167

def append_the_content(
    content = content?
  )
  if @internal_hash[:shall_we_modify_the_content]
    content.each {|entry|
      append_onto_the_result '  <tr>' # Indent it a little bit - looks more elegant, in my opinion.
      if entry.is_a? Array
        entry.each {|inner_entry|
          append_onto_the_result '<td>'+inner_entry.to_s+'</td>'  
        }
      else
        append_onto_the_result '<td>'+entry.to_s+'</td>'
      end
      append_onto_the_result '</tr>'
      append_onto_the_result N
    }
  else
    # ===================================================================== #
    # In that case simply append the @content onto @result.
    # ===================================================================== #
    append_onto_the_result "#{content}#{N}"
  end
end

#fill_with_this_array(i) ⇒ Object

#

fill_with_this_array

#


120
121
122
# File 'lib/cyberweb/objectified/html_tags/table.rb', line 120

def fill_with_this_array(i)
  set_content(i)
end

#headers=(array) ⇒ Object

#

headers=

#


106
107
108
# File 'lib/cyberweb/objectified/html_tags/table.rb', line 106

def headers=(array)
  @internal_hash[:headers] = array
end

#headers?Boolean

#

headers?

#

Returns:

  • (Boolean)


99
100
101
# File 'lib/cyberweb/objectified/html_tags/table.rb', line 99

def headers?
  @internal_hash[:headers]
end

#rebuild_the_resultObject

#

rebuild_the_result

#


194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/cyberweb/objectified/html_tags/table.rb', line 194

def rebuild_the_result
  reset_the_result
  consider_adding_the_pre_content
  append_onto_the_result '<table'
  batch_append_css_class_then_the_ID_and_then_the_css_style
  # ========================================================================= #
  # Enable drag-support if specified
  # ========================================================================= #
  if is_draggable?
    append_onto_the_result ' draggable="true"'
  end
  append_onto_the_result ">\n"
  headers = headers?
  if headers
    # ======================================================================= #
    # Add table-headers in this case.
    # ======================================================================= #
    array = headers
    if !array.empty?
      append_onto_the_result "  <tr>\n"
      array.each {|this_header|
        append_onto_the_result "    <th>#{this_header}</th>\n"
      }
      append_onto_the_result "  </tr>\n"
    end
  end
  append_the_content
  # append_onto_the_result content?.to_s
  append_onto_the_result "</table>\n"
  return raw_result?
end

#resetObject

#

reset

#


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/cyberweb/objectified/html_tags/table.rb', line 79

def reset
  super()
  # ======================================================================= #
  # === :headers
  #
  # If we want to add table headers then this should be used.
  # ======================================================================= #
  @internal_hash[:headers] = nil
  # ======================================================================= #
  # === :shall_we_modify_the_content
  #
  # If the following variable is true then we will modify the @content
  # variable.
  # ======================================================================= #
  @internal_hash[:shall_we_modify_the_content] = true
end

#shall_we_modify_the_content?Boolean

#

shall_we_modify_the_content?

#

Returns:

  • (Boolean)


113
114
115
# File 'lib/cyberweb/objectified/html_tags/table.rb', line 113

def shall_we_modify_the_content?
  @internal_hash[:shall_we_modify_the_content]
end