Module: SUMD_List
- Defined in:
- lib/su_info/sumd_list.rb
Overview
Purpose:
Note - variable, parameter, and method names in this Module are done such that they do not add any new symbol names that aren't already used, otherwise it prefixes them with sumd_.
Creates three files (?? is two digit SketchUp version):
File name | Information / Notes |
---|---|
SketchUp_??_Constants_List.md | Markdown 'List' file |
su??_constants_tab.txt | Tab Delimited text |
su??_constants_tab_md.txt |
Tab Delimited text, used to make 'Guide' md file |
The three files list all classes, modules, and constants defined by SketchUp.
File layout:
- Root (or un-namespaced) constants defined by the SketchUp environment
- 'Namespaced' constants defined in SketchUp, starting with SketchUp
- List of SketchUp modules / classes that have no constants defined
Required files:
File name | Information / Notes |
---|---|
Template_List.md | markdown template |
native_ruby_cnsts.txt | contains 'root' constants native to Ruby |
Code Process:
- Creates array of root constants
- Loop thru array
- Removes constants that exist in native Ruby (h_native)
- Splits constants into constants and objects
- Adds constants to file text
- Calls .sumd_find_nested and processes namespaced constants
Lastly, remember to unload all of your extensions / plug-ins before runnning this.
Class Method Summary collapse
-
.sumd_done
Final processing, writes files, chains to SUMD_ConstantsGuide.
-
.sumd_find_nested(obj)
Finds all constants in object namespace, reentrant.
-
.sumd_found_txt ⇒ String
Returns the info about what was found.
-
.sumd_root(constants, ref = nil, cols = 2)
Parses constants, determines grouping and one or two layout, writes data to md file.
-
.sumd_run
Main entry point.
-
.sumd_write_1(constants, obj)
One column layout in the markdown file.
-
.sumd_write_2(constants, obj)
Two column layout in the markdown file.
Class Method Details
.sumd_done
Final processing, writes files, chains to SUMD_ConstantsGuide
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 |
# File 'lib/su_info/sumd_list.rb', line 415 def self.sumd_done() # create header and add to text h = SUMD.sumd_generated_by(name, @version) @text_md.sub!(/<%= hdr %>/, h) f = sumd_found_txt() @text_md.sub!(/<%= found %>/, f) @text_tab = "#{h}\n\n#{f.gsub(/  /, ' ')}#{@text_tab}" # write files, show done message box files = [] files << SUMD.sumd_file_write('Constants List.md' , @text_md) files << SUMD.sumd_file_write('constants_tab.txt' , @text_tab) files << SUMD.sumd_file_write('constants_tab_md.txt' , @text_tab_md) puts "-------------------------------------------------\n" \ "#{name} wrote the following files:\n#{files.join(10.chr)}\n" end |
.sumd_find_nested(obj)
Finds all constants in object namespace, reentrant.
Adds the info to file text strings by calling .write_constants
277 278 279 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 335 336 337 338 339 340 |
# File 'lib/su_info/sumd_list.rb', line 277 def self.sumd_find_nested(obj) constants = [] objs = [] sumd_bsc = obj.respond_to?(:superclass) sumd_sc = sumd_bsc ? obj.superclass : "na" # show as Class, then Module, then Object, then ??? sumd_type = if obj.is_a?(Class) ; "Class" elsif obj.is_a?(Module) ; "Module" elsif obj.is_a?(Object) ; "Object" else ; "???" end sumd_obj_str = obj.to_s # get constants, divide into object & constants obj.constants.sort.each { |c| next if (sumd_bsc && obj.superclass.const_defined?(c) ) o = obj.const_get(c) # note: assignment if o.is_a?(Module) objs << o else constants << [c.to_s, o, o.class] end } len = constants.length @ctr_su += len if (/(::)*([^:]+)$/ === sumd_obj_str) sumd_link = "<a href='#{@su_docs}#{$2.downcase}'>#{sumd_obj_str}" if $2 end if (len != 0) constants.sort! { |a,b| a[1] <=> b[1] } if obj == Sketchup::Model if @ctr_su_cls > 0 @text << @empty @text << @b_h_5 end # add object row @text << "<tr><td colspan='2'><strong>#{sumd_link}::</a></strong></td>" \ "<td colspan='2'><strong>#{sumd_sc}</strong></td>" \ "<td><strong>#{sumd_type}</strong></td></tr>\n" @text << @b_l_5 sumd_write_2(constants, obj) @ctr_su_cls += 1 @text_tab << "\n#{sumd_obj_str}::\t\t#{sumd_sc}\n" @text_tab << "\n" else # add information about object to no_constants strings @no_const << "<tr><td>#{sumd_link}</a></td><td>#{sumd_sc}" \ "</td><td>#{sumd_type}</td></tr>\n" @no_const_tab << "#{sumd_obj_str}\tno constants\t#{sumd_sc}\t#{sumd_type}\n" @ctr_su_no += 1 @no_const << @b_l_3 if (@ctr_su_no % 5 == 0) end # run child object constants of obj thru this objs.each { |o| sumd_find_nested(o) } if (objs.length > 0) end |
.sumd_found_txt ⇒ String
Returns the info about what was found
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
# File 'lib/su_info/sumd_list.rb', line 437 def self.sumd_found_txt() n = '  ' r = @ctr_root.to_s.rjust(3).gsub(/ /, n) s = @ctr_su.to_s.rjust(3).gsub(/ /, n) no = @ctr_su_no.to_s.rjust(3).gsub(/ /, n) t = (@ctr_root + @ctr_su).to_s t.gsub!(/(\d)(?=(\d{3})+(?!\d))/, "\\1,") "Found #{t} constants, as follows:\n\n" \ "* #{r } constants defined in Object (global)\n" \ "* #{s } constants defined in SketchUp objects (namespaced)\n" \ "* #{no} SketchUp objects with no defined constants\n\n" end |
.sumd_root(constants, ref = nil, cols = 2)
Parses constants, determines grouping and one or two layout, writes data to md file
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/su_info/sumd_list.rb', line 175 def self.sumd_root(constants, ref = nil, cols = 2) found = false idx = 0 # find first item that matches if ref constants.each_with_index { |r,i| if (r[0] =~ ref) found = true idx = i break end } else found = true idx = constants.length end if found # write items before 1st match sub = constants.slice!(0, idx) @ctr = 0 while (sub.length > 0) do len = sub.length - 1 if sub[0][2] == Fixnum 1.upto(len) { |i| if sub[i][2] != Fixnum s = sub.slice!(0, i) sumd_write_2(s, Object) @text << @empty + @b_h_5 @ctr = -1 break else @ctr = i end } if @ctr == len s = sub.slice!(0, @ctr + 1) sumd_write_2(s, Object) @text << @empty + @b_h_5 end else 1.upto(len) { |i| if sub[i][2] == Fixnum s = sub.slice!(0, i) sumd_write_1(s, Object) @text << @empty + @b_h_5 @ctr = -1 break else @ctr = i end } if @ctr == len s = sub.slice!(0, @ctr + 1) sumd_write_1(s, Object) @text << @empty + @b_h_5 end end if sub.length == 1 if sub[0][2] == Fixnum sumd_write_2(sub, Object) else sumd_write_1(sub, Object) end @text << @empty + @b_h_5 sub = [] end end # find last index that matches found = false idx = 0 constants.each_with_index { |r,i| if (r[0] =~ ref) found = true idx = i end } # write all matching items if found sub = constants.slice!(0, idx + 1) if cols == 2 sumd_write_2(sub, Object) @text << @empty + @b_h_5 else sumd_write_1(sub, Object) @text << @empty + @b_h_5 end end end end |
.sumd_run
Main entry point
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 |
# File 'lib/su_info/sumd_list.rb', line 108 def self.sumd_run() return unless (@text_md = SUMD.sumd_file_read('Template_List.md')) # get hash from file of native Ruby objects sumd_ruby_c_hash = {} return unless SUMD.sumd_get_ruby_hash(sumd_ruby_c_hash) sumd_re_incld = /^(Array|Numeric|String|RUBY_)/ objs = [] constants = [] # sort root constants into two arrays, constants and module objects Object.constants.sort.each { |c| str = c.to_s next if ( str =~ /^SUMD/ || (sumd_ruby_c_hash.key?(str) && !(str =~ sumd_re_incld)) ) o = Object.const_get(c) if ( o.is_a?(Module) ) next if (o.name =~ /^(Continuation|MatchData|Precision)/) objs << o else constants << [str, o, o.class] end } @ctr_root = constants.length # process root constants sumd_root(constants, /^CMD_/) if ( constants.length > 0) sumd_root(constants, /^GL_/) if ( constants.length > 0) sumd_root(constants, /^LAYER_/, 1) if ( constants.length > 0) if ( constants.length > 0) sumd_root(constants, /^RUBY_/, 1) end sumd_root(constants, /^VK_/) if ( constants.length > 0) sumd_root(constants) if ( constants.length > 0) @text_md.sub!(/<%= gc %>/, "<tbody>\n#{@text}</tbody>\n") @text = '' # process root modules / classes, sort SketchUp on top # then call sumd_find_nested if (objs.length > 0) objs.delete(Object) objs.delete(Sketchup) objs.sort! { |a,b| a.to_s <=> b.to_s } objs.insert(0, Sketchup) objs.each { |o| sumd_find_nested(o) } end @text_md.sub!(/<%= nsc %>/, "<tbody>\n#{@text}</tbody>\n") @text_md.sub!(/<%= noc %>/, "#{@no_const}</tbody>\n") @text = '' # write info on modules / classes with no constants @text_tab << "\n" @text_tab << @no_const_tab @text_tab_md << @no_const_tab sumd_done() end |
.sumd_write_1(constants, obj)
One column layout in the markdown file
Writes an array of constants to the three output files
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
# File 'lib/su_info/sumd_list.rb', line 349 def self.sumd_write_1(constants, obj) # cl = class text len = constants.length f = (obj == Object) ? '' : "#{obj.to_s}::" n = '' val = '' cl = '' constants.each { |c| n << "#{c[0]}<br/>" val << "#{c[1]}<br/>" cl << "#{c[2]}<br/>" t = "#{c[0]}\t#{c[1]}\t#{c[2]}\n" @text_tab << t @text_tab_md << "#{f}#{t}" } s = ( (constants[0][0] =~ /^RUBY_/) ? 'r' : 'n') @text << "<tr><td colspan='5'>" \ "<span class='#{s}'>#{n}</span>" \ "<span class='v'>#{val}</span>" \ "<span class='c'>#{cl}</span></td></tr>" end |
.sumd_write_2(constants, obj)
Two column layout in the markdown file
Writes an array of constants to the three output files
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 406 407 408 409 410 411 412 |
# File 'lib/su_info/sumd_list.rb', line 378 def self.sumd_write_2(constants, obj) # c = counter c1 = col 1 # f = fqn c2 = col 2 # sumd_tt1 = col 1 _tab.txt sumd_tmd1 = col 1 _tab_md.txt # sumd_tt2 = col 2 _tab.txt sumd_tmd2 = col 2 _tab_md.txt c = 0 f = (obj == Object) ? '' : "#{obj.to_s}::" len = constants.length split = ( 0.5 * (len + 1) ).floor sumd_tt1 = '' ; sumd_tt2 = '' ; sumd_tmd1 = '' ; sumd_tmd2 = '' 0.upto(split - 1) { |i| c1 = constants[i] t = "#{c1[0]}\t#{c1[1]}\t#{c1[2]}\n" sumd_tt1 << t sumd_tmd1 << "#{f}#{t}" if i + split < len c2 = constants[i + split] t = "#{c2[0]}\t#{c2[1]}\t#{c2[2]}\n" sumd_tt2 << t sumd_tmd2 << "#{f}#{t}" else c2 = [' ', ' ', ' '] end @text << "<tr><td>#{c1[0]}</td><td>#{c1[1]}</td><td></td>" \ "<td>#{c2[0]}</td><td>#{c2[1]}</td></tr>" c += 1 if (c % 5 == 0 && c != split) @text << @b_l_5_split end } @text_tab << sumd_tt1 + sumd_tt2 @text_tab_md << sumd_tmd1 + sumd_tmd2 end |