Module: SUMD_Guide

Defined in:
lib/su_info/sumd_guide.rb

Overview

Purpose:

Creates the 'Constants Guide' md file.

Required files:

File name Information / Notes
Template_Guide.md markdown template
template_code.rb contains long code snippets shown in md file.
send_action.txt
 
contains list of send_action text parameters
scraped from SketchUp.com.
su??_constants_tab_md.txt
 
contains the constant list that is parsed and
inserted into md template file.

Code Process:

  1. _run:
    1. Loads text data from the files listed above.
    2. Loads code samples into md template. When finished --
  2. rendering_options_poke:
    1. Load an array with RenderingOptions keys.
    2. Starts a UI timer and loops thru the keys, changing the respective key's value. This generates a RenderingOptionsObserver callback. This allows the code to map RenderingOptions keys to the RenderingOptionsObserver callback 'type' parameter. This takes a litle while. When finished --
  3. rendering_options_done:
    1. Processes data and places it in the md template. When finished --
  4. _run2:
    1. Mostly pulls data from the constants file, there is some special code for the send_action section, which has its own method.

All files need to be located in the hiearchy used at https://github.com/MSP-Greg/SketchUp

Constant Summary collapse

@@i =
-1

Class Method Summary collapse

Class Method Details

._run

Main entry point

Loads files, inserts code samples, starts rendering_options_poke



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/su_info/sumd_guide.rb', line 68

def self._run()
  # get required files
  return unless ( @text_md   = SUMD.sumd_file_read('Template_Guide.md') )
  return unless ( @text_code = SUMD.sumd_file_read('template_code.rb') )
  return unless ( @constants =
            SUMD.sumd_file_read("su#{@su_major}_constants_tab_md.txt") )

  insert_code_sample('face_1')
  insert_code_sample('len_1')
  insert_code_sample('ro_1')
  insert_code_sample('ro_2')
  insert_code_sample('tool_1')
  puts "-------------------------------------------------\n" \
       "#{name} starting rendering_options loops"
  rendering_options_poke()
end

._run2

Runs after rendering_options timer finishes



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/su_info/sumd_guide.rb', line 87

def self._run2()
  #
  length_constants()

  #
  send_action()

  # Geom:: constants
  find_regex('[^\r\n\f]+?Geom::', 'geometry')

  # UI.messagebox type
  a2 = find_regex('MB_')

  # UI.messagebox return
  a1 = find_regex('ID')

  hdr_row = ['status return', 'value', '', 'type parameter', 'value']
  table = create_table2(a1, hdr_row, %w[L C L L C], a2)
  @text_md.sub!(/<%= ui_mb %>/, table)

  # UI.layer.page_behavior
  find_regex('LAYER_', 'layer_page_behavior') { |a,b|
    (a[1].rjust(3, '0') + a[0]) <=> (b[1].rjust(3, '0') + b[0]) }

  # Command.set_validation
  find_regex('MF_', 'command_set_validation_proc', 'cmd_status')

  # Behavior # snap_to
  find_regex('SnapTo_', 'snap_to', 'snap_to')

  # Dimension #arrow_type #arrow_type=
  find_regex('Sketchup::Dimension::ARROW_', 'dim_arrow', 'arrow_type')

  # Dimension #aligned_text_position
  find_regex('Sketchup::DimensionLinear::ALIGNED_', 'dim_aligned_text', 'at_pos')

  # Dimension #text_position
  find_regex('Sketchup::DimensionLinear::TEXT_', 'dim_text_pos', 'text_pos')

  # Entities add_faces_from_mesh
  find_regex('Geom::PolygonMesh::', 'from_mesh', 'smooth_flags')

  # Page#update Pages#add
  find_regex('(PAGE_USE_|PAGE_NO_)', 'page_use', 'flag parameter')

  # Sketchup::Face::
  find_regex('Sketchup::Face::', 'face_classify_point', 'pt_location')

  # Sketchup::Importer::
  find_regex('Sketchup::Importer::', 'importer', 'status_code return')

  # Sketchup::Model::
  find_regex('Sketchup::Model::', 'model_save', 'version') { |a, b|
    a[1].to_i <=> b[1].to_i }

  # .set_status_text
  find_regex('SB_', 'status_text', 'position')

  # Text #leader_type
  find_regex('ALeader', 'leader_type', 'leader')

  # Texturewriter.write
  find_regex('FILE_WRITE_', 'texture_writer_write', 'status return')

  # Tool Keyboard
  find_regex('VK_', 'tool_key', 'key cb<br/>parameter')

  # Tool Mouse
  find_regex('MK_', 'tool_mse', 'flags cb<br/>parameter')

  # Toolbar
  find_regex('TB_', 'toolbar', 'state return')

  # View.draw(mode, pts)
  find_regex('GL_', 'view_draw', "mode parameter")

  # Vew.draw_text
  find_regex('TextAlign', 'view_draw_text', ":align value")

  # RUBY_
  find_regex('(RUBY_|PLATFORM|RELEASE_DATE|VERSION)', 'RUBY_')

  # Other Object
  find_regex('SKETCHUP_CONSOLE', 'other_object')

  # Old key constants
  find_regex('(ALT_MODIFIER|CONSTRAIN_MODIFIER|COPY_MODIFIER)','depreciated_constants_1')

  # now namespaced
  find_regex('DimensionArrow','depreciated_constants_2')

  unclassified_constants()

  @text_md.sub!(/<%= hdr %>/, SUMD.sumd_generated_by(name, @version))

  files = []
  files << SUMD.sumd_file_write('Constants Guide.md', @text_md)
  puts "-------------------------------------------------\n" \
       "#{name} wrote the following files:\n#{files.join(10.chr)}\n"

  UI.messagebox('Finished!')
end

.create_table(array, hdr_row, alignment) ⇒ string

Creates an html table from an array

Parameters:

  • array (Array< Array<String, String, String> >)
  • hdr_row (Array<String>)

    table row 1

  • alignment (Array<String>)

Returns:

  • (string)

    table element html string



554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
# File 'lib/su_info/sumd_guide.rb', line 554

def self.create_table(array, hdr_row, alignment)
  rows = array.length - 1
  columns = hdr_row.length - 1
  al = []
  0.upto(columns) { |j|
    case alignment[j]
    when "L" then al[j] = ( j != columns ? " class='l1'" : "" )
    when "C" then al[j] = ( j != columns ? " class='c1'" : " class='c'" )
    when "R" then al[j] = " class='r1'"
    end
  }
  # create md header row
  table = "<table class='sumd'><thead><tr>\n"
  0.upto(columns) { |j| table << "<th#{al[j]}>#{hdr_row[j]}</th>" }
  table << "\n</tr></thead><tbody>\n"
  # create table
  0.upto(rows) { |i|
    table << "<tr>"
    0.upto(columns) { |j|
      table << "<td#{al[j]}>#{array[i][j]}</td>"
    }
    table << "</tr>\n"
    if (i+1) % 5 == 0 && i != rows
      table << "<tr class='t' ><td colspan='#{columns + 1}'></td></tr>\n" \
               "<tr class='b1'><td colspan='#{columns + 1}'></td></tr>\n"
    end
  }
  table << "</tbody></table>\n"
end

.create_table2(a1, hdr_row, alignment, a2, wid = nil) ⇒ string

Creates a 'two up' html table from an array

Parameters:

  • a1 (Array< Array<String, String, String> >)

    left array

  • hdr_row (Array<String>)

    table row 1

  • alignment (Array<String>)
  • a2 (Array< Array<String, String, String> >)

    right array

  • wid (Float) (defaults to: nil)

    name column em width

Returns:

  • (string)

    table element html string



592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
# File 'lib/su_info/sumd_guide.rb', line 592

def self.create_table2(a1, hdr_row, alignment, a2, wid = nil)
  if wid
    wid1 = wid ; wid2 = wid
  else
    # header titles should be one row (no <br/>)
    puts hdr_row[0]
    puts hdr_row[3]
    wid1 = [SUMD.sumd_str_to_em(a1),
            1 + SUMD.sumd_str_to_em( [ hdr_row[0], '' ] ) ].max
    wid2 = [SUMD.sumd_str_to_em(a2),
            1 + SUMD.sumd_str_to_em( [ hdr_row[3], '' ] ) ].max
  end

  rows = [a1.length - 1, a2.length - 1].max
  columns = hdr_row.length - 1
  al = []

  0.upto(columns) { |j|
    case alignment[j]
    when "L" then al[j] = ">"
    when "C" then al[j] = " class='c'>"
    when "R" then al[j] = " class='r'>"
    end
  }
  split = ( [wid1, wid2].max > 15 ? '1.5em' : '3em' )
    2
  # create md header row
  table = "<table class='sumd'>" \
          "<colgroup>" \
          "<col style='width:#{wid1+1}em;' />" \
          "<col />" \
          "<col style='width:#{split};'/>" \
          "<col style='width:#{wid2+1}em;' />" \
          "<col />" \
          "</colgroup>" \
          "<thead><tr>\n"

  0.upto(columns) { |j|
    table <<  ( j != 2 ? "<th#{al[j]}#{hdr_row[j]}</th>" :
              "<th class='b'></th>" )
  }
  table << "\n</tr></thead><tbody>\n"
  # create table
  len1 = a1.length
  len2 = a2.length
  0.upto(rows) { |i|
    table << "<tr>"
    if i < len1
      table << "<td#{al[0]}#{a1[i][0]}</td><td#{al[1]}#{a1[i][1]}</td>"
    else
      table << "<td#{al[0]}</td><td#{al[1]}</td>"
    end
    table << "<td class='b'></td>"
    if i < len2
      table << "<td#{al[3]}#{a2[i][0]}</td><td#{al[4]}#{a2[i][1]}</td>"
    else
      table << "<td#{al[3]}</td><td#{al[4]}</td>"
    end
    table << "</tr>\n"
    if (i+1) % 5 == 0 && i != rows
      table << "<tr class='t' ><td></td><td></td><td></td>" \
                              "<td></td><td></td></tr>\n" \
               "<tr class='b1'><td></td><td></td><td class='b'></td>" \
                              "<td></td><td></td></tr>\n"
    end
  }
  table << "</tbody></table>\n"
end

.create_table_md(array, hdr_row, alignment) ⇒ String

Creates a markdown table text from an array

Not used since all tables are html

Parameters:

  • array (Array< Array<String, String, String> >)
  • hdr_row (Array<String>)

    table row 1

  • alignment (Array<String>)

Returns:

  • (String)

    md tabel string



670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
# File 'lib/su_info/sumd_guide.rb', line 670

def self.create_table_md(array, hdr_row, alignment)
  rows = array.length - 1
  columns = hdr_row.length - 1
  # column widths of header row
  col_widths = []
  0.upto(columns) { |j| col_widths[j] = hdr_row[j].length }

  # determine column widths of table
  0.upto(rows) { |i|
    0.upto(columns) { |j|
      col_widths[j] = [col_widths[j], array[i][j].length].max
    }
  }

  # create md header row
  table = '| '
  0.upto(columns) { |j| table << hdr_row[j].ljust(col_widths[j]) << ' | ' }
  table << "\n|"
  # create md justification row
  dash = '-'
  7.times { |k| dash += dash }
  0.upto(columns) { |j|
    table << case alignment[j]
             when 'L' then ":#{dash.slice(0, col_widths[j])}-|"
             when 'C' then ":#{dash.slice(0, col_widths[j])}:|"
             when 'R' then "-#{dash.slice(0, col_widths[j])}:|"
             end
  }
  table << "\n"
  # create md table
  0.upto(rows) { |i|
    table << '| '
    0.upto(columns) { |j|
      table << if (array[i][j] == '')
                               "".ljust(col_widths[j]) + ' | '
               else
                 array[i][j].to_s.ljust(col_widths[j]) + ' | '
               end
    }
    table << "\n"
  }
  table << "\n<br/>"
  table.gsub!(/[ \t]+$/, '')
  table
end

.find_regex(re_con, re_md = nil, cnst_name = nil) ⇒ Array<String>?

Called for constants that can be found with a RegEx match

If re_md is nil, array will be returned

Parameters:

  • re_con (String)

    used to create RegEx for constant match

  • re_md (String) (defaults to: nil)

    used to create RegEx for table insertion in md

  • cnst_name (String) (defaults to: nil)

    optional column name for constant name column

Returns:

  • (Array<String>, nil)


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
225
# File 'lib/su_info/sumd_guide.rb', line 199

def self.find_regex(re_con, re_md = nil, cnst_name = nil)
  re_full = /^#{re_con}.+?$/
  if (/^[A-Z]/ =~ re_con)
    re_trim = re_con.sub(/[^:]*$/,'')
    trim = (re_trim != '')
  end
  array = []
  while (match = @constants.slice!(re_full)) do
    array << match.split(/\t/)
  end
  if (array.length > 0)
    # trim namespace from constant name
    array.each { |row| row[0].sub!(re_trim, '') } if trim

    array.sort! { |a,b| yield(a,b) } if block_given?
    if (re_md)
      standard_table(array, re_md, cnst_name)
    else
      array
    end
  else
    # nothing found, insert text as such
    re_find_text = /<%= #{re_md} %>/
    @text_md.sub!(re_find_text, "<strong>** Constants not defined in SketchUp #{@toc_su} **</strong><br/><br/>") if re_md
    array
  end
end

.insert_code_sample(c_name)

Loads code snippets from Template_Guide_Code.rb into md string

Parameters:

  • c_name (String)

    name of section in file, also replacement string in template



231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/su_info/sumd_guide.rb', line 231

def self.insert_code_sample(c_name)
  code = @text_code.slice!(/^  def #{c_name}[\s\S]+?(^  end)/m)
  if (code)
    code.sub!(/^  def[^\r\n\f]+[\r\n\f]+/, '') # remove def line
    code.sub!(/  end\Z/, '')                  # remove end and comment marker
    code.gsub!(/^  / , '')                     # remove 2 spaces of indent
    code.gsub!(/^  /m, '')                     # remove 2 spaces of indent
    code.sub!(/[ \t\r\n\f]+\z/, '')            # extra blank lines at end
    @text_md.sub!(/<%= code_#{c_name} %>/, code)
  else
    puts "#{c_name} code snippet is missing or incorrectly formatted!"
  end
end

.length_constants

Creates the table with all of the OptionsManager & OptionsProvider keys



247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/su_info/sumd_guide.rb', line 247

def self.length_constants()
  options_manager = Sketchup.active_model.options
  array = []
  options_manager.each { |op|
    op_name = op.name
    op.each { |k, v|
      cls = v.class
      cls = (cls == TrueClass || cls == FalseClass) ? 'Boolean' : cls.to_s
      array << [op_name, k, v.to_s, cls]
    }
  }
  array.pop()
  len = array.length
  if (len > 0)
    array.sort! { |a,b| "#{a[0].ljust(40)}#{a[1]}" <=> "#{b[0].ljust(40)}#{b[1]}" }
    # remove dupicate 1st column
    (len-1).downto(1) { |i| array[i][0] = '' if array[i][0] == array[i-1][0] }
    # insert blank rows
    (len-1).downto(1) { |i| array.insert(i, ['&#160;', '', '', '']) if (array[i][0] != "") }
  end
  hdr_row = ['OptionsManager<br/>key', 'OptionsProvider<br/>key', 'OptionsProvider<br/>value', '<br/>class']
  alignment = %w[L L C L]
  table = create_table(array, hdr_row, alignment)
  @text_md.sub!(/<%= opts_mgr %>/, table)
  find_regex('Length::', '_length')
end

.rendering_options_del

Used to delete RenderingOptions constants in @constants string



338
339
340
341
342
343
344
# File 'lib/su_info/sumd_guide.rb', line 338

def self.rendering_options_del()
  cns = 'Sketchup::RenderingOptions::'
  @@a_ro_table.each { |row|
    next if row[2].match(/[^A-Za-z0-9_]/)
    @constants.sub!(/^#{cns}#{row[2]}.+?$/, '')
  }
end

.rendering_options_done

Writes data to md file after poke is finished, when this finishes, it runs _run2



349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# File 'lib/su_info/sumd_guide.rb', line 349

def self.rendering_options_done()
  @am_ro.remove_observer( @obs_ro )
  # remove found options from @constants string
  rendering_options_del()
  @@a_ro_table.sort! { |a,b|
    aa = "#{a[1].ljust(25)}#{a[0].ljust(30)}#{a[2].ljust(30)}"
    bb = "#{b[1].ljust(25)}#{b[0].ljust(30)}#{b[2].ljust(30)}"
    aa <=> bb
  }
  # bold duplicates
  h0 = Hash.new(0)
  h2 = Hash.new(0)
  @@a_ro_table.each { |row|
    h0[row[0]] += 1
    h2[row[2]] += 1
  }
  @@a_ro_table.each { |row|
    row[0] =  "<strong>#{row[0]}</strong>" if h0[row[0]] > 1
    row[2] =  "<strong>#{row[2]}</strong>" if h2[row[2]] > 1
  }

  hdr_row = ['RenderingOptions<br/>key', 'RenderingOptions<br/>value.class', '<br/>Observer constant (type)']
  alignment = %w[L L L]
  table = create_table(@@a_ro_table, hdr_row, alignment)
  @text_md.sub!(/<%= rendering_opts %>/, table)
  # check if any RenderingOption keys did not fire an observer event
  @a_no_fire = []
  @@a_ro.each { |r|
    if (r[2] == 0)
      @a_no_fire << r
    end
  }
  if (@a_no_fire.length > 0)
    hdr_row = ['R Opts key', 'R Opts value.class']
    alignment = %w[L L]
    table = create_table(@a_no_fire, hdr_row, alignment)
    t =  "The following table lists [RenderingOptions] keys that do not" \
         " fire the [onRenderingOptionsChanged] callback.\n\n#{table}"
    @text_md.sub!(/<%= rendering_opts_no_fire %>/, t)
  else
    @text_md.sub!(/<%= rendering_opts_no_fire %>[\r\n\f]{2}/, '')
  end
  array = find_regex('Sketchup::RenderingOptions::', nil)
  if (array.length > 0)
    hdr_row = ['Observer constant (type)', 'value']
    alignment = %w[L C]
    table = create_table(array, hdr_row, alignment)
    t = "The following RenderingOptions constants are not fired by any keys" \
        " in [RenderingOptions].  They may be returned for UI changes that" \
        " do not have API control.\n\n#{table}"
    @text_md.sub!(/<%= rendering_opts_no_cb %>/, t)
  else
    @text_md.sub!(/<%= rendering_opts_no_cb %>/, '')
  end
  # continue with the rest of md assembly
  _run2
end

.rendering_options_poke

This loops thru rendering options, then waits for the observer to fire.

Attaches a RenderingOptionsObserver, then pokes rendering_options using a UI timer, loads an array (@a_ro) from the keys of a rendering_options instance.



280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/su_info/sumd_guide.rb', line 280

def self.rendering_options_poke()
  @am = Sketchup.active_model
  @am_ro = @am.rendering_options

  # array holds table columns
  @@a_ro = []

  # load array with 1st 2 columns from @am_ro 'hash'
  @am_ro.each_pair { |key, value|
    tCls = value.class
    if (tCls == TrueClass || tCls == FalseClass)
      tCls = 'Boolean'
    else
      tCls = tCls.to_s
    end
    @@a_ro << [ key , tCls, 0]
  }
  @len_a_ro = @@a_ro.length

  # create constants array
  ro = Sketchup::RenderingOptions
  @@h_ro_c = {}
  ro.constants.each { |c|
    @@h_ro_c[ro.const_get(c)] = c.to_s
  }
  @@a_ro_table = []
  @obs_ro = Sketchup::RenderingOptionsObserver.new
  @obs_ro.instance_eval {
    def onRenderingOptionsChanged(rendering_options, type)
      # increment counter in @@a_ro, which shows that an observer
      # callback occurs when it is changed
      @@a_ro[@@i][2] += 1
      # create the callback name for the md table
      ro_c_name = @@h_ro_c[type] ||
        "<strong style='color:blue'>** Missing, type = #{type}</strong>"
      # add a row to the table
      @@a_ro_table << [@@a_ro[@@i][0], @@a_ro[@@i][1], ro_c_name]
    end
  }
  @am_ro.add_observer( @obs_ro )

  # Start timer to loop thru RenderingOptions
  @am.start_operation('Create Constants md', true)
  @@i = -1
  @timer = UI.start_timer(0.20, true) {
    @@i += 1
    if (@@i < @len_a_ro)
      ro_loop(@@i)
    else
      UI.stop_timer(@timer)
      @am.abort_operation
      rendering_options_done()
    end
  }
end

.ro_loop(i)

Changes a Rendering Option

Parameters:

  • i (Integer)

    loop counter that UI has processed



719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
# File 'lib/su_info/sumd_guide.rb', line 719

def self.ro_loop(i)
  ro_str = @@a_ro[i][0]
  case @@a_ro[i][1]
  when 'Boolean'
    @am_ro[ro_str] = !@am_ro[@@a_ro[i][0]]
  when 'Sketchup::Color'
    color = @am_ro[ro_str].to_a
    color[2] = case color[2]
               when 255 then 128
               when 128 then 192
               else          255
               end
    @am_ro[ro_str] = Sketchup::Color.new(color)
  when 'Fixnum'
    @am_ro[ro_str] = case @am_ro[ro_str]
                      when 1 then 2
                      when 2 then 1
                      else        1
                      end
  when 'Float'
    @am_ro[ro_str] = case @am_ro[ro_str]
                      when 0.5 then 0.6
                      else          0.5
                      end
  end
end

.send_action

Code to create table that links send_action text with constants



409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
# File 'lib/su_info/sumd_guide.rb', line 409

def self.send_action()
  return unless (sa_text = SUMD.sumd_file_read('send_action.txt'))

  # array of text commands
  a_text = sa_text.split(/\n/)
  a_text.sort!

  # array for constants / numeric commands
  a_number = []
  re_full = /^CMD_.+?$/
  while (match = @constants.slice!(re_full)) do
    a_number << match.split(/\t/)
  end

  #create hash from constant 'suffix names'
  h_number = {}
  a_number.each { |row|
    key = row[0].sub(/^CMD_/, '').gsub(/_/, '')
    h_number[key] = row
  }
  a_table = []
  a_text.each { |a|
    t = a.sub(/^(edit|render|select)/i, '').sub(/(Tool)?\:$/,'')
    # do a few matches that RegEx doesn't catch
    t = case t
      when  'FieldOfView'         then 'DisplayFOV'
      when  'openDocument'        then 'Open'
      when  'pageAdd'             then 'PageNew'
      when  'printDocument'       then 'Print'
      when  'SectionPlane'        then 'Section'

      when  'Selection'           then 'Select'
      when  'showRubyPanel'       then 'RubyConsole'
      when  'Textures'            then 'Textured'
      when  'Turn'                then 'Pan'
      when  'viewShowAxes'        then 'SketchAxes'

      when  'viewShowGuides'      then 'ShowGuides'
      when  'viewShowHidden'      then 'ShowHidden'
      when  'viewZoomExtents'     then 'ZoomExtents'
      when  'viewZoomToSelection' then 'SelectionZoomExt'
      else t
      end
    t.upcase!
    if h_number.key?(t)
      a_table << [a, h_number[t][0], h_number[t][1]]
      h_number.delete(t)
    else
      a_table << [a, '', '']
    end
  }
  hdr_row = ['action String',
             'action Constant',
             'Fixnum']
  alignment = %w[L L C]
  table = create_table(a_table, hdr_row, alignment)
  @text_md.sub!(/<%= cmd_alpha %>/, table)

  # now add remaining numberic constants
  array = []
  h_number.each { |k,v| array << v }
  if (array.length > 0)
    array.sort! { |a,b| a[0] <=> b[0] }
    sub = "The following constants do not have string equivalents.\n\n<%= cmd_numeric %>"
    @text_md.sub!(/<%= cmd_numeric %>/, sub)
    table = standard_table(array, 'cmd_numeric', 'action constant')
  end
end

.standard_table(array, re_md, col1 = nil)

Creates a table based on constant 3 column array, adds to md

Parameters:

  • array (array <array <String, String, String> >)
  • re_md (String)

    string to find in md template

  • col1 (String) (defaults to: nil)

    name of column 1 header



483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
# File 'lib/su_info/sumd_guide.rb', line 483

def self.standard_table(array, re_md, col1 = nil)
  re_find_text = /<%= #{re_md} %>/
  table = nil
  if array.length > 0
    # check to see if all constants are of the same class, if so,
    # change 2nd column heading, remove 3rd column
    len = array.length - 1
    col3_remove = true
    if (len > 1)
      cls = array[0][2]
      1.upto(len) { |row|
        if cls != array[row][2]
          col3_remove = false
          break
        end
      }
    end
    hdr_row = []

    hdr_row[0] = col1 || 'constant'
    hdr_row[1] =  ( hdr_row[0] =~ /<br\/>/ ?
                    "<br/>value" : "value" )
    if (col3_remove)
      if array.length > 6
        wid = SUMD.sumd_str_to_em(array)
        if wid < 18
          hdr_row[2] = ''
          hdr_row[3] = hdr_row[0]
          hdr_row[4] = hdr_row[1]
          alignment = %w[L C L L C]
          split = ( 0.5 * (len + 2) ).floor
          t = len - split + 1
          a2 = array.slice!(-t, t)
          table = create_table2(array, hdr_row, alignment, a2, wid)
        end
      end
      # two column single table
      alignment = %w[L C]
      table ||= create_table(array, hdr_row, alignment)
    else
      # three column single table
      hdr_row[2] = 'class'
      alignment = %w[L C L]
      table = create_table(array, hdr_row, alignment)
    end
  else
    table = "No matching constants!"
  end
  @text_md.sub!(re_find_text, table)
end

.unclassified_constants

Adds a table to the md file with what's left of the@constants string.



536
537
538
539
540
541
542
543
544
545
546
# File 'lib/su_info/sumd_guide.rb', line 536

def self.unclassified_constants()
  a_temp = @constants.split(/[\r\n\f]+/)
  if (a_temp && a_temp.length > 0)
    a_unclassified = []
    a_temp.each { |r|
      row = r.split(/\t/)
      a_unclassified << row if (row.length == 3)
    }
    standard_table(a_unclassified, 'yet_to_be_added')
  end
end