class Boilerplate def initialize @values = nil @markers = { dataset: { sub: "<--dataset-->", value: nil }, x: { sub: "<--x-->", value: nil }, y: { sub: "<--y-->", value: nil }, options: { sub: '<--options-->', value: {} } } @boilerplate = nil @boilerplate_raw = <<'STATOSIOOOO'
STATOSIOOOO @options_allow_list = set_options_allow_list() end def get_boilerplate_raw @boilerplate_raw end def set_boilerplate @boilerplate = @boilerplate_raw.clone @markers.keys.each do | key | case key when :dataset tmp = { data: @markers[ key ][:value] } value = JSON.pretty_generate( tmp ) when :x value = @markers[ key ][:value].to_s when :y value = @markers[ key ][:value].to_s when :options value = @markers[ key ][:value].to_json end @boilerplate.gsub!( @markers[ key ][:sub], value ) end end def get_boilerplate @boilerplate end def get_markers @markers end def set_markers_value( _values ) _values.keys.each do | key | @markers[ key ][:value] = _values[ key ] end end def set_options_allow_list g = { start: 'let default_values = ', end: 'const params_create' } html = @boilerplate_raw tmp = html[ html.index( g[:start] ) + g[:start].length, html.length ] tmp = tmp[ 0, tmp.index( g[:end] ) ] tmp = tmp .strip! .gsub( "'", '"' ) .split( "\n" ) .map { | ss | ss.include?( '//' ) ? ss[ 0, ss.index( '//' )] : ss } .join() options = JSON.parse( tmp ) keys = { alias: [], camel_case: [], allow_list: [] } options.keys.each do | lvl1 | if options[ lvl1 ].class.to_s == 'Hash' options[ lvl1 ].keys.each do | lvl2 | if options[ lvl1 ][ lvl2 ].class.to_s == 'Hash' options[ lvl1 ][ lvl2 ].keys.each do | lvl3 | if options[ lvl1 ][ lvl2 ][ lvl3 ].class.to_s == 'Hash' options[ lvl1 ][ lvl2 ][ lvl3 ].keys.each do | lvl4 | if !options[ lvl1 ][ lvl2 ][ lvl3 ][ lvl4 ].nil? keys[:alias].push( lvl1.to_s + '__' + lvl2.to_s + '__' + lvl3.to_s + '__' + lvl4.to_s ) end end else if !options[ lvl1 ][ lvl2 ][ lvl3 ].nil? keys[:alias].push( lvl1.to_s + '__' + lvl2.to_s + '__' + lvl3.to_s ) end end end else if !options[ lvl1 ][ lvl2 ].nil? keys[:alias].push( lvl1.to_s + '__' + lvl2.to_s ) end end end else if !options[ lvl1 ].nil? keys[:alias].push( lvl1.to_s ) end end end keys[:alias].each do | key | tmp = key .gsub('__', '_') .split('_') one = tmp[ 0 ] two = tmp .drop(1) .map { | d | d[ 0, 1 ].upcase + d[ 1, d.length] } .join() keys[:camel_case].push( one + two ) end keys[:allow_list] = keys[:alias].concat( keys[:camel_case] ) return keys[:allow_list] end end