Class: AGRenderer

Inherits:
Object
  • Object
show all
Defined in:
ext/ae-rad/ae-rad-libs.rb

Direct Known Subclasses

AGTkRenderer

Constant Summary collapse

INDENT_UNIT =

INDENT_UNIT = “t”

"\s"*2

Instance Method Summary collapse

Constructor Details

#initialize(_agobj = nil) ⇒ AGRenderer

Returns a new instance of AGRenderer.



175
176
177
178
179
180
181
# File 'ext/ae-rad/ae-rad-libs.rb', line 175

def initialize(_agobj=nil)
  if _agobj
    @agobj = _agobj
  else
    exit
  end
end

Instance Method Details

#class_begin(_ind = 0, _args = nil) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'ext/ae-rad/ae-rad-libs.rb', line 188

def class_begin(_ind=0, _args=nil)
  code = INDENT_UNIT*_ind,'class ', @agobj.getInstanceClass,  ' < ', @agobj.getObjClass
  code_attr=''
  code_hinner_class=''
  @agobj.sons.each {|value|
    if (value.sons.length > 0)
      code_hinner_class = code_hinner_class,"\n", value.renderer.class_code(_ind+1)
    end
    code_attr = code_attr,"\n",INDENT_UNIT*(_ind+1),'attr_reader :', value.i_name
  }
  code = code,code_attr if (code_attr.length >0)
  code = code,code_hinner_class,"\n" if (code_hinner_class.length >0)
  code = code,"\n", INDENT_UNIT*(_ind+1),"def initialize(parent=nil, *args)\n"
  if _args
    code = code, INDENT_UNIT*(_ind+2),"super(parent, "+_args+")\n"
  else
    code = code, INDENT_UNIT*(_ind+2),"super(parent, *args)\n"
  end
end

#class_code(_ind = 0, _args = nil) ⇒ Object



183
184
185
186
# File 'ext/ae-rad/ae-rad-libs.rb', line 183

def class_code(_ind=0, _args=nil)
  args = render_on_create_properties(_args) 
  return class_begin(_ind, args), class_hinner_begin(_ind+1), class_hinner_end(_ind+1), class_end(_ind)
end

#class_end(_ind = 0) ⇒ Object



228
229
230
231
# File 'ext/ae-rad/ae-rad-libs.rb', line 228

def class_end(_ind=0)
  code = code, "\n", INDENT_UNIT*(_ind+1),"end\n",INDENT_UNIT*(_ind),"end"
  return code.flatten.join
end

#class_hinner_begin(_ind = 0) ⇒ Object



208
209
210
# File 'ext/ae-rad/ae-rad-libs.rb', line 208

def class_hinner_begin(_ind=0)
  return render_family(_ind+1,'property','default')
end

#class_hinner_end(_ind = 0) ⇒ Object



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'ext/ae-rad/ae-rad-libs.rb', line 212

def class_hinner_end(_ind=0)
  code = ''
  @agobj.sons.each {|value|
    if (value.sons.length > 0)
      code = code, value.renderer.obj_begin(_ind+1),"\n"
    else
      code = code, value.renderer.obj_code(_ind+1),"\n"
    end
  }
  if code.kind_of?(Array)
    code.flatten.join
  else  
    code
  end
end

#obj_begin(_ind = 0) ⇒ Object



237
238
239
240
241
242
243
244
245
246
247
248
# File 'ext/ae-rad/ae-rad-libs.rb', line 237

def obj_begin(_ind=0)
  _s_ind = INDENT_UNIT*_ind
  if _s_ind == nil
    _s_ind = ''
  end
  if @agobj.sons.length > 0
    _class = @agobj.getInstanceClass
  else
    _class = @agobj.class.class_wrapped.to_s
  end
  return "\n",_s_ind+'@'+@agobj.i_name+' = '+_class+'.new(self)'
end

#obj_code(_ind = 0) ⇒ Object



233
234
235
# File 'ext/ae-rad/ae-rad-libs.rb', line 233

def obj_code(_ind=0)
  return obj_begin(_ind), "{ ",obj_hinner_begin(_ind+1), obj_hinner_end(_ind+1), obj_end(_ind),"}"
end

#obj_end(_ind = 0) ⇒ Object



271
272
273
274
275
276
277
# File 'ext/ae-rad/ae-rad-libs.rb', line 271

def obj_end(_ind=0)
  _s_ind = INDENT_UNIT*_ind
  if _s_ind == nil
    _s_ind = ''
  end
  _s_ind
end

#obj_hinner_begin(_ind = 0) ⇒ Object



250
251
252
# File 'ext/ae-rad/ae-rad-libs.rb', line 250

def obj_hinner_begin(_ind=0)
  return class_hinner_begin(_ind)
end

#obj_hinner_end(_ind = 0) ⇒ Object



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'ext/ae-rad/ae-rad-libs.rb', line 254

def obj_hinner_end(_ind=0)
  code = ''
  _s_attr_reader = ''
  _s_ind = INDENT_UNIT*_ind
  _s_attr_reader = ''
  @agobj.sons.each{|son|
    code = code , "\n", son.renderer.obj_code(_ind)
    _s_attr_reader = _s_attr_reader, "\n", _s_ind,INDENT_UNIT*2 ,':',son.i_name
  }
  if code.length > 0 then
    code = code , "\n",_s_ind,"class << self"
    code = code , "\n",_s_ind,"  attr_reader",_s_attr_reader
    code = code , "\n",_s_ind,"end"
  end
  return code
end

#render_family(_ind = 0, _family = '', _kind = nil, _default = false) ⇒ Object



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
406
407
408
409
410
411
412
413
414
# File 'ext/ae-rad/ae-rad-libs.rb', line 353

def render_family(_ind=0, _family='', _kind=nil, _default=false)
  if @agobj.props[_family] == nil
    return ''
  end
  _s_block = ''
  _s_ind = INDENT_UNIT*_ind

  render_group =  @agobj.props_def[_family] != nil
  if render_group
    @agobj.props_def[_family]['sep'] != nil ? render_group_sep = @agobj.props_def[_family]['sep']:render_group_sep = ''
    @agobj.props_def[_family]['default'] != nil ? render_group_default = @agobj.props_def[_family]['default']:render_group_default = proc{|nome,x| "'#{nome}' #{x}"}
  end
  if _kind == nil
    properties_list = Array.new
    @agobj.props_kinds[_family].each_value{|p|
      properties_list.concat(p)
    }
  else
    properties_list = @agobj.props_kinds[_family][_kind]
  end
  properties_list.each{|name|
    value = @agobj.props[_family][name]
    if _default
    		_val = render_value_default(value, _family)
    else
    		_val = render_value(value, _family)
    end
    if _val == nil
      next
    end
    
    if render_group
      if _s_block.length > 0
        _s_block = _s_block, render_group_sep
      end
      _s_block = _s_block,"\n",_s_ind, INDENT_UNIT
      if (value['def'] == '')||(value['def'] == nil) #significa che possiamo inserire nel blocco come chiave,valore
        _s_block = _s_block, render_group_default.call(value['name'] , _val)
      elsif (value['def'] != nil)&&(value['def'] != 'nodef')
        _s_block = _s_block, value['def'].call(_val)
      end
    else
      if (value['def'] == '')||(value['def'] == nil) #significa che possiamo inserire nel blocco come chiave,valore
        _s_block = _s_block, "\n",_s_ind , value['name'] ,INDENT_UNIT , _val
      elsif (value['def'] != nil)&&(value['def'] != 'nodef')
        _s_block = _s_block , "\n",  _s_ind ,value['def'].call(_val)
      end
    end
  }

  if render_group
    _ss_block =  "\n",_s_ind
    if @agobj.props_def[_family]['path'] != nil
      _ss_block = _ss_block, @agobj.props_def[_family]['path']
    end
    _ss_block = _ss_block, @agobj.props_def[_family]['before'],	_s_block, "\n",_s_ind, @agobj.props_def[_family]['after']
  else
    _ss_block = _s_block
  end
  #p _ss_block.to_s
  return _ss_block
end

#render_on_create_properties(_args = nil) ⇒ Object



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
# File 'ext/ae-rad/ae-rad-libs.rb', line 279

def render_on_create_properties(_args = nil)
  ret = nil
  if _args
    ret = ''
    _args.each{|k,v|
      if ret.strip.length > 0
        ret = ret + ', '
      end
      ret = ret + "'"+k+"' => '"+v+"'"
    }
  end
  aprop = @agobj.props_kinds['property']['on-create']
  if aprop 
    ret = '' if ret == nil
    aprop.each{|name|
      next if _args && _args.has_key?(name)
      prop = @agobj.props['property'][name]
     _val = render_value(prop, 'property')
      if _val == nil
        next
      end
      if ret.strip.length > 0
        ret = ret +', '
      end 
      #Tk.messageBox('message'=>_val.to_s)
      if (prop['def'] == '')||(prop['def'] == nil) #significa che possiamo inserire nel blocco come chiave,valore
        ret = ret + "'"+ prop['name'] +"' => "+ _val.to_s
      elsif (prop['def'] != nil)&&(prop['def'] != 'nodef')
        ret = ret + prop['def'].call(_val.to_s)
      end
    }
  end
  ret = nil if ret != nil && ret.strip.length == 0
  return ret 
end

#render_value(_prop, _family) ⇒ Object



315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'ext/ae-rad/ae-rad-libs.rb', line 315

def render_value(_prop, _family)
     #Tk.messageBox('message'=>_prop['name'])
     return nil if _prop == nil
     _val = _prop['get'].call
     
     if @agobj.defaults_values[@agobj.class][_family][_prop['name']]==_val
       return nil
     end

     _prop['def_string'] != nil && !_prop['def_string'] ? is_string = false : is_string = true

     if _val.kind_of?(String) && is_string
       _val = "'",_val,"'"
     elsif _val != nil
       _val = _val.to_s
     end
     #Tk.messageBox('message'=>_val)
     if _val.kind_of?(Array)
       _val.flatten.join
     else
       _val
     end
end

#render_value_default(_prop, _family) ⇒ Object



339
340
341
342
343
344
345
346
347
348
349
# File 'ext/ae-rad/ae-rad-libs.rb', line 339

def render_value_default(_prop, _family)
     return nil if _prop == nil
     _val = _prop['value']
     _prop['def_string'] != nil && !_prop['def_string'] ? is_string = false : is_string = true
     if _val.kind_of?(String) && is_string
       _val = "'",_val,"'"
     elsif _val != nil
       _val = _val.flatten.join
     end
     return _val
end