Class: Roebe::Menu::Generator

Inherits:
Base show all
Defined in:
lib/roebe/classes/menu_generator/constants.rb,
lib/roebe/classes/menu_generator/append_to.rb,
lib/roebe/classes/menu_generator/menu_generator.rb

Overview

Roebe::Menu::Generator

Constant Summary collapse

N =
"\n"
SHALL_WE_DEBUG =
#

SHALL_WE_DEBUG

#
false
HOME_DIR =
'/Users/jana/'
MY_TEMP =
#

MY_TEMP

#
ENV['MY_TEMP'].to_s+'/'
SUPERUSER_DIR =
#

SUPERUSER_DIR

A trailing ‘/’ must be used for the SUPERUSER_DIR constant.

#
HOME_DIR
DEFAULT_INPUT =
#

DEFAULT_INPUT

#
'all'
"#{ENV['LINUX_YAML']}/menu.yml"
CREATE_DESKTOP_FILES_FOR_XFCE =
#

CREATE_DESKTOP_FILES_FOR_XFCE

#
false
ICEWM_DIR =
#

ICEWM_DIR

#
HOME_DIR+'.icewm'
LINUX =
#

LINUX

#
"#{ENV['LINUX']}/"
FLUXBOX_FILE =
#

FLUXBOX_FILE

#
LINUX+'FLUXBOX/menu_file'
TABBLE_FILE =
#

TABBLE_FILE

#
LINUX+'TABBLE/tabble'
ICEWM_FILE =
#

ICEWM_FILE

#
ICEWM_DIR+'menu'

Constants inherited from Base

Base::COLOURS, Base::HOME_DIRECTORY_OF_USER_X, Base::NAMESPACE

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#actions, #append_this_onto_that_file, #append_what_into, #be_silent, #be_verbose?, #beautiful_url, #burlywood, #call_next, #chdir, #cheerful_guy, #cliner, #complex_esystem, #convert_global_env, #copy_directory, #copy_file, #cornflowerblue, #crimson, #current_month?, #current_time?, #current_year?, #cyan, #darkcyan, #darkgreen, #darkkhaki, #darkslateblue, #deeppink, #delete_symlink, #do_not_use_the_base_colours, #do_use_the_base_colours, #e, #ecomment, #editor_to_use?, #efancy, #eimp, #emphasis, #ensure_main_encoding, #ensure_utf_encoding, #eparse, #erev, #esteelblue, #etomato, #ewarn, #exit_program, #firebrick, #get_current_day, #get_current_month, #get_files_and_directories, #get_files_from, #get_german_name_for_this_weekday, #gold, #green, #grey, #hh_mm_ss, #hh_mm_ss_day_month_year, #home_dir?, #home_directory_of_user_x?, #infer_the_namespace, #internal_hash?, #is_a_directory?, #is_a_file?, #is_a_jpg_file?, #is_an_image_file?, #is_archive?, #is_audio_file?, #is_in_studium_dir?, #is_multimedia_file?, #is_on_roebe?, #is_on_windows?, #is_studium_available?, #is_symlink?, #is_this_a_ruby_file?, #is_video_file?, #iso_encoding?, #le, #left_colour, #lightblue, #lightgreen, #lightseagreen, #lightsteelblue, #lime, #limegreen, #localhost_to_data, #log_directory?, #main_encoding?, #mediumorchid, #mediumpurple, #mediumseagreen, #mediumslateblue, #mediumspringgreen, #mediumturquoise, #mkdir_p, #mv, #n_days_in_this_month, #n_pages_in_this_pdf_file?, #namespace?, #no_file_exists_at, #ogrey, #olive, #olivedrab, #open_in_browser, #opne, #opnesystem, #opnn, #orange, #orchid, #orev, #palegoldenrod, #palevioletred, #pink, #powderblue, #programs_dir?, #project_base_dir?, #random_html_colour, #rds, #read_file_in_iso_encoding, #read_file_via_the_default_encoding, #read_lines_via_iso_encoding, #readlines_with_main_encoding, #red, #register_sigint, #remove_directory, #remove_file, #rename_kde_konsole_tab, #replace_localhost_with_data, #report_pwd, #require_rescue, #reset_the_internal_hash, #return_all_directories_from_this_directory, #return_all_files_from_this_directory, #return_current_directory, #return_dd_mm_yyyy, #return_file_or_directory_of, #return_files_from_pwd, #return_last_part_of_the_current_directory, #return_utc, #rev, #right_arrow?, #right_colour, #roebe_log_directory?, #rosybrown, #royalblue, #ruby_base_directory?, #run_in_background, #run_rcfiles_then_run_ata_via_qdbus, #sandybrown, #sdir, #seagreen, #set_be_verbose, #set_xorg_buffer, #sfancy, #sfile, #silent_redirection?, #simp, #simple_esystem, #skyblue, #slateblue, #slategray, #springgreen, #steelblue, #string_italic, #swarn, #symlink, #teal, #temp_dir?, #to_camelcase, #to_counted_hash, #tomato, #touch, #try_to_require_the_beautiful_url_gem, #try_to_require_the_html_template, #try_to_require_the_open_gem, #try_to_require_the_program_information_gem, #try_to_require_the_xorg_buffer, #use_colours?, #verbose_truth, #weekday?, #word_wrap, #write_what_into, #yellow

Methods included from Base::CommandlineArguments

#append_onto_the_commandline_arguments, #clear_commandline_arguments, #commandline_arguments?, #commandline_arguments_as_string?, #commandline_arguments_without_leading_hyphens?, #first_argument?, #first_argument_without_leading_hyphens?, #has_an_argument_been_passed?, #remove_hyphened_arguments_from_the_commandline_arguments, #return_commandline_arguments_with_leading_hyphens, #second_argument?, #set_commandline_arguments

Constructor Details

#initialize(optional_this = nil, run_already = true) ⇒ Generator

#

initialize

#


37
38
39
40
41
42
43
44
45
# File 'lib/roebe/classes/menu_generator/menu_generator.rb', line 37

def initialize(
    optional_this = nil,
    run_already   = true
  )
  set_input(optional_this)
  reset # This should come before any other method.
  load_yaml_dataset
  run if run_already
end

Class Method Details

.[](i = '') ⇒ Object

#

Menu::Generator[]

#


619
620
621
# File 'lib/roebe/classes/menu_generator/menu_generator.rb', line 619

def self.[](i = '')
  new(i)
end

Instance Method Details

#append_to(what = '', where_to = :tabble) ⇒ Object

#

append_to

This method appends to a file. First argument what holds the content, second argument where_to denotes where we will store.

#


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/roebe/classes/menu_generator/append_to.rb', line 19

def append_to(
    what     = '',
    where_to = :tabble
  )
  case where_to
  when :tabble
    save_what_into(what, TABBLE_FILE,'a+')
  when :fluxbox
    save_what_into(what, FLUXBOX_FILE,'a+')
  when :icewm
    save_what_into(what, ICEWM_FILE,'a+')
  else
    save_what_into(what, where_to.to_s,'a+')
  end
end

#create_a_new_menu_file_for(i) ⇒ Object

#

create_a_new_menu_file_for

#


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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/roebe/classes/menu_generator/menu_generator.rb', line 158

def create_a_new_menu_file_for(i)
  case i
  # ======================================================================= #
  # === :icewm
  # ======================================================================= #
  when :icewm
    remove(ICEWM_FILE)
    create_directory(ICEWM_DIR)
    generate_file(i)
  # ======================================================================= #
  # === :all
  # ======================================================================= #
  when :all
    create_a_new_menu_file_for(:idesk)
    create_a_new_menu_file_for(:tabble)
    create_a_new_menu_file_for(:desktop)
    create_a_new_menu_file_for(:fluxbox)
    create_a_new_menu_file_for(:icewm)
  # ======================================================================= #
  # === :idesk
  # ======================================================================= #
  when :idesk
    # ===================================================================== #
    # Idesk is special, in that we need another way to create all
    # the various .lnk files. This is a bit messy, but here is the
    # jumper to the method which creates the .lnk files:
    # ===================================================================== #
    create_idesk_files
  # ======================================================================= #
  # === :tabble
  # ======================================================================= #
  when :tabble
    remove(TABBLE_FILE) # We must remove the old file first.
    generate_file(i)
  # ======================================================================= #
  # === :desktop
  # ======================================================================= #
  when :desktop,
       :desktop_files
    create_all_desktop_files
  # ======================================================================= #
  # === :fluxbox
  # ======================================================================= #
  when :fluxbox,
       :flux,
       :f
    remove(FLUXBOX_FILE)
    generate_file(i)
  else
    red "Invalid input: #{i}"
  end
end

#create_all_desktop_filesObject

#

create_all_desktop_files

This will create all .desktop file.

The format of a typical .desktop file is like this:

[Desktop Entry]
Encoding=UTF-8
GenericName=Advanced Text Editor
Name=GEdit
Exec=/opt/gnome/bin/gedit
Icon=/opt/gnome/share/icons/HighContrastLargePrint/48x48/apps/gedit-icon.png
Terminal=false
Type=Application
Categories=Qt;KDE;TextEditor;
#


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
# File 'lib/roebe/classes/menu_generator/menu_generator.rb', line 434

def create_all_desktop_files
  # @section is an array, containing stuff like:
  #  ["admin-applications", "editors", "ftp", "games","icq","internet","irc",
  #   "mail","mud","multimedia","office","p2p","standard-applications","terminal-shells"]
  @section.each { |subsection|
    @yaml_file[subsection].each { |tmp|
      content = tmp[1].to_hash
      content.each_pair { |key, value|
        key = key.to_s.dup.gsub(/_/,' ').gsub(/img_dir/,'icon dir')
        # wenn idesk: true is, dann erstellen wir die .lnk Dateien.
        if key == 'idesk' and value
          name = content['name'].tr('-','_').tr(' ','_')
          name << '.desktop'
          icon = content['img_dir'] + content['icon']
          target_file = MY_TEMP.dup # No need to append a '/' as we already make sure that it exists.
          target_file << name
          # Downcased is besser.
          # target_file = target_file.downcase
          # Clean possibly existing files with w+ mode
          create_desktop_file_at(target_file, name, content, icon)
          if @use_ede
            create_desktop_file_at(@ede_file+name, name, content, icon)
          end
          if CREATE_DESKTOP_FILES_FOR_XFCE
            create_desktop_file_at('/root/.config/autostart/'+name, name, content, icon)
          end
        end
      }
    }
  }
end

#create_desktop_file_at(target_file, name, content, icon) ⇒ Object

#

create_desktop_file_at

Use this method when you want to create a desktop file.

#


523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
# File 'lib/roebe/classes/menu_generator/menu_generator.rb', line 523

def create_desktop_file_at(target_file, name, content, icon)
  remove(target_file) # Better remove it, just in case.
  opn; e "Creating in this location: #{sfile(target_file)}"
  what = ''
  what << '[Desktop Entry]' << N
  what << '  Encoding=UTF-8' << N
  what << '  GenericName='+name.capitalize << N
  what << '  Name='+name.capitalize << N
  what << '  Exec='+content['cmd'].downcase << N
  what << '  Icon='+icon << N
  what << '  Terminal=false' << N
  what << '  Type=Application' << N
  what << '  Categories=Qt;KDE;TextEditor;' << N
  what << '  Categories=Qt;KDE;TextEditor;' << N
  what << '  X='+rand(5..1020).to_s << N
  what << '  Y='+rand(5..1020).to_s << N
  into = target_file
  write_what_into(what, into)
end

#create_directory(d) ⇒ Object Also known as: mkdir

#

create_directory

#


576
577
578
# File 'lib/roebe/classes/menu_generator/menu_generator.rb', line 576

def create_directory(d)
  Dir.mkdir(d) unless File.exist?(d)
end

#create_idesk_filesObject

#

create_idesk_files (idesk tag)

Use this method to generate .idesk files.

It will create the various .ln files in ~/.idesktop, which is currently hardcoded. It also must check whether .idesktop exists, because if not, we must create it.

These .lnk files are our various idesk files.

#


477
478
479
480
481
482
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
# File 'lib/roebe/classes/menu_generator/menu_generator.rb', line 477

def create_idesk_files
  report_generating_file(:idesk)
  _ = @idesk_location
  create_directory(_)
  # traverse the section
  @section.each { |tmp_section|
    @yaml_file[tmp_section].each { |tmp|
      content = tmp[1].to_hash
      content.each_pair { |key, value|
        key = key.to_s.dup.gsub(/_/,' ').gsub(/img_dir/,'icon dir')
        # wenn idesk: true is, dann erstellen wir die .lnk Dateien.
        if key == 'idesk' and value
          # is der name
          _name = content['name'].tr('-','_').tr(' ','_')
          icon = content['img_dir'] + content['icon']
          target_file = @idesk_location+_name+'.lnk'
          opn; e "Creating `#{sfile(target_file)}` now."
          remove(target_file)
          # 2 Spaces schaut recht gut aus
          append_to('table Icon', target_file)
          append_to('  Caption: '+_name.capitalize,target_file)
          append_to('  ToolTip.Caption: '+_name.capitalize,target_file)
          append_to('  Icon: '+icon, target_file)
          # Hmm lowercase or downcase, is the question. Downcase the answer!
          append_to('  Command[0]: '+content['name'].downcase, target_file)
          append_to('  Command[1]: '+content['name'].downcase, target_file)
          append_to('  Width: 48', target_file)
          append_to('  Height: 48',target_file)
          # Here we position it. This is a little bit tricky.
          # pos_array will have numbers from 0 5 10 up to 500
          pos_array = []
          0.step(500, 5) { |i| pos_array << i }
          append_to('  X: '+rand(50..300).to_s,target_file)
          append_to('  Y: '+(rand(50..300)+(rand(50..300)/2) ).to_s,target_file)
          append_to('end',target_file)
        end
      }
    }
  }
end

#create_menu_for(i) ⇒ Object

#

create_menu_for

#


144
145
146
# File 'lib/roebe/classes/menu_generator/menu_generator.rb', line 144

def create_menu_for(i) # This bundles the necessary steps.
  create_a_new_menu_file_for(i)
end

#debugObject

#

debug

#


81
82
83
84
85
# File 'lib/roebe/classes/menu_generator/menu_generator.rb', line 81

def debug # Gimme some debug info here.
  opn; e @yaml_file.class
  opn; e 'Its keys are:'
  pp @section
end

#generate_commentObject Also known as: make_comment

#

generate_comment

#


90
91
92
# File 'lib/roebe/classes/menu_generator/menu_generator.rb', line 90

def generate_comment # Generate a comment via this method.
  '# '+'=' * 75+' #' # +N # Hmm. Not great to append a newline here.
end

#generate_file(input = :tabble) ⇒ Object

#

generate_file

This method contains all required code to create the target file, be it fluxbox or tabble or whatever. Also see the helper function append_to

#


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
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
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
341
342
343
344
345
346
347
348
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
406
407
408
409
410
411
412
413
414
415
416
# File 'lib/roebe/classes/menu_generator/menu_generator.rb', line 217

def generate_file(input = :tabble)
  report_generating_file(input)
  case input
  # ================================================================== #
  # === Generate a new IceWM menu
  #
  # Here we generate our icewm menu.     (icewm tag, ice tag)
  # ================================================================== #
  when :icewm
    icewm_header = "# ============================================================== #
# This is an example for IceWM's menu definition file for use
# on HiveOS.
# Place them under:
# $HOME/.icewm
#
# Syntax:
#
# prog  Program_Name  icon-name  executable -with -options
#
# Examples:
#
#   prog Xterm xterm xterm
#   prog Gimp gimp gimp
#

# Syntax for submenus:
# menu Submenu_Name  folder {}
# ============================================================== #"
    append_to(icewm_header, input)
    @section.each { |tmp_section|
      # Make a separator
      append_to(N+'separator '+N, input)
      append_to('menu '+tmp_section+' folder { ', input)
      @yaml_file[tmp_section].each { |tmp| 
        # We could do this:
        # menuprog Gnome folder icewm-menu-gnome1 --list
        # menufile Programs folder programs
        # Submenus gehen so:
        # menu Editor folder {
        #   Abiword
        # }
        _tmp = tmp[1].to_hash
        append_to(
          '  prog '+_tmp['name'].to_s.tr(' ','_')+
          ' '+_tmp['cmd'].to_s+
          ' '+_tmp['cmd'].to_s+N,
          input
        )
      }
      append_to('} ', input)
    }
  # ======================================================================= #
  # === :tabble
  # ======================================================================= #
  when :tabble, :t
    append_to(make_comment, input)
    append_to('# Autogenerated tabble file for HiveOS.', input)
    append_to('# Generated from: bl menu_generator.rb at '+get_time, input)
    append_to(make_comment+N, input) # Add extra newline.
    begin
      @tabble_entry = @tabble_entry.dup.to_hash
      @tabble_entry.each_pair { | key, value |
        append_to(key.to_s + ': ' + value.to_s, input)
      }
    rescue Exception => error
      pp error
    end
    # ===================================================================== #
    # Ok nun müssen wir die einträge abbarbeiten
    #
    #   tab: Applications
    #   name: Firefox
    #   cmd: firefox
    #   icon dir: /home/x/DATA/IMG/FF
    #   icon: FIREFOX_FAVICON.png
    #   x pos: 0
    #   y pos: 0
    #
    # ===================================================================== #
    @section.each { |tmp_section|
      # puts "tmp section war #{tmp_section}"
      append_to(N+'tab: '+tmp_section+N, input)
      @yaml_file[tmp_section].each { |tmp|
        begin
          content = tmp[1].to_hash
          content.each_pair { | key, value |
            next if key == 'idesk'
            key = key.to_s.dup.gsub(/_/,' ').gsub(/img_dir/,'icon dir')
            value = value.capitalize if key == 'name'
            append_to(key+': '+value.to_s, input)
          } 
          # Trennzeichen: 1 newline
          append_to(N, input)
        rescue Exception => error
          pp error
        end
      }
    }
  # ================================================================== #
  # Hier nun fluxbox. flux tag, fluxbox tag.
  # ================================================================== #
  when :fluxbox
    #append_to(input, N ) # zu beginn nit newline rein...
    fluxbox_header = generate_comment+N
    fluxbox_header << '# If you read this it probably means you want to edit this 
# (autogenerated from std_menu_generator.rb) file manually, so here are 
# some useful tips, and a bit of a guidance help now:
#
#   - You can add your own menu-entries to ~/.fluxbox/usermenu
#   - If you miss apps please let me know and I will add them for the next
#     release.
#   - The -r option prevents removing of empty menu entries and lines which
#     makes things much more readable.
#   - To prevent any other app from overwriting your menu
#     you can change the menu name in .fluxbox/init to:
#       session.menuFile: /home/you/.fluxbox/my-menu
# To copy it:
#   cp $LINUX/FLUXBOX/menu_file ~/.fluxbox
#
# bl $LINUX/FLUXBOX/menu_file
#
# To generate it anew, do this command:
#   genmenu
#
# Location of the file:
#   '+ENV['LINUX']+'/FLUXBOX/menu_file
# Generated when:
#   '+get_time+'
'+generate_comment+'

[begin] (Da Roebe Box)'
    append_to(fluxbox_header, input)
    # ok, arbeite die tmp_section einträge ab.
    @section.sort.each do |tmp_section|
      #puts "tmp section war #{tmp_section}"
      # Mandatory separator
      append_to("\n[separator]\n "+N+" ##########-- SEKTION: "+tmp_section.upcase+N, input)
      # tmpsection is zb multimedia
      append_to('[submenu] ('+tmp_section+")"+N, input)
      # gut nun, Arbeite den Scheiss ab, der in jeder Section
      # drinnen steht.
      @yaml_file[tmp_section].sort.each { |tmp|
        # [exec] (FireFox)   { firefox } </home/x/DATA/IMG/FF/FIREFOX_FAVICON.xpm>
        content = tmp[1].to_hash # bezieht sich auf den 2. entry
        append_to('    [exec] (' +
          content['name'] + ') '+'{'+ 
          content['cmd'] + '} <' + 
          content['img_dir'] +
          content['icon'] + '>',
            input)
        #content.each_pair do | key, value |
        #  # discard info we dont need
        #  next if key == 'x_pos'
        #  next if key == 'y_pos'
        #  key=key.to_s.dup.gsub(/_/,' ').gsub(/img_dir/,'icon dir')
        #  value = value.capitalize if key == 'name'
        # Trennzeichen: 1 newline
        #append_to(input, N )
      }
      append_to(N+'[end]'+N, input)
    end
    # nun kommt was anderes
    append_to(N, input)
    # Eigentlich sollte das mein yaml file 
    # automatisch machen. Die Info is auch drinnen,
    # nur bin ich jetz zu faul das alles noch 
    # im ruby script anzugeben. 
    # Daher hier ein quick hack
    append_to('[separator] # 1. Row
[submenu] (Fluxbox Menu)
 [config] (Configure)
 [workspaces]   (Workspace List)
 [submenu] (Tools) # 2. Row
    [exec] (Window name) {xprop WM_CLASS|cut -d \" -f 2|xmessage -file - -center}
    [exec] (gtk-theme-switch) {switch}
    [exec] (gtk2-theme-switch) {switch2}
    [exec] (Screenshot - JPG) {import screenshot.jpg && display -resize 45% screenshot.jpg}
    [exec] (Screenshot - PNG) {import screenshot.png && display -resize 45% screenshot.png}
 [end]
 [submenu] (WindowManager)
    [restart] (fluxbox) {fluxbox}
    #[restart] (icewm) {icewm}
    [restart] (kde) {startkde}
 [end]
 [commanddialog] (Fluxbox Command)
 [reconfig] (Reload config)
 [restart] (RestartFluxbox)
 #[exec] (About) {(fluxbox -v; fluxbox -info | sed 1d) 2> /dev/null | xmessage -file - -center}
 [separator]
 [exit] (Exit)# FLEE :)
 [separator]
 [submenu] (Styles) {Choose a style:}
    [stylesdir] (/Programs/Fluxbox/Current/styles/)
 [end] 
[end]
',input)
  else 
    opn; e "Not known: `#{simp(input)}!`"
  end
end

#get_timeObject

#

get_time

#


97
98
99
# File 'lib/roebe/classes/menu_generator/menu_generator.rb', line 97

def get_time # time tag
  Time.now.strftime '%d.%m.%Y'
end

#input?Boolean

#

input?

#

Returns:

  • (Boolean)


583
584
585
# File 'lib/roebe/classes/menu_generator/menu_generator.rb', line 583

def input?
  @input
end

#load_yaml_datasetObject

#

load_yaml_dataset (yaml tag)

This method will load our yaml files. It is basically a mandatory method that should be called before we invoke run(). This method will also invoke one other method, called sanitize_yaml(). The latter method will ensure that the YAML Dataset is proper and thus usable for us.

#


115
116
117
118
119
# File 'lib/roebe/classes/menu_generator/menu_generator.rb', line 115

def load_yaml_dataset # bl $LINUX/YAML/menu.yml
  @yaml_file = YAML.load_file(MENU_YAML)
  @section = @yaml_file.keys.sort
  sanitize_yaml # Here we delete useless entries, such as 'tabble'
end
#

menu (menu tag)

#


590
591
592
593
594
595
596
# File 'lib/roebe/classes/menu_generator/menu_generator.rb', line 590

def menu(i)
  case i # case tag
  when :"--help"
    show_help
    exit
  end
end

#remove(i) ⇒ Object

#

remove

#


151
152
153
# File 'lib/roebe/classes/menu_generator/menu_generator.rb', line 151

def remove(i) # General remove action. (remove tag)
  delete_file(i)
end

#report_generating_file(input = :tabble) ⇒ Object

#

report_generating_file

Reports that we are generating a new file, decision based on input. An exception is the keyword :all, which we will silently ignore.

#


549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
# File 'lib/roebe/classes/menu_generator/menu_generator.rb', line 549

def report_generating_file(input = :tabble)

  debug if SHALL_WE_DEBUG

  case input
  when :all # Pass through in this case.
  when :tabble
    opn; e '=> Generating '+palegoldenrod('tabble')+' file'\
           ' '+sfile(TABBLE_FILE)+' next.'
  when :fluxbox
    opn; e "=> Generating #{palegoldenrod('fluxbox')} "\
           "file #{sfile(FLUXBOX_FILE)} next."
  when :icewm
    opn; e '=> Generating '+palegoldenrod('icewm')+' file '+sfile(ICEWM_FILE)+' next.'
  when :idesk
    opn; e '=> Generating the various '+
           palegoldenrod('idesk')+' files '+sfile(@idesk_location)+' next.'
  when :desktop_files
    opn; e '=> Now generating various .desktop files.'
  else
    ewarn 'Error. We did not find `'+sfile(input.to_s)+'`'
  end
end

#resetObject

#

reset (reset tag)

#


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/roebe/classes/menu_generator/menu_generator.rb', line 50

def reset
  super()
  # ======================================================================= #
  # === @section
  # ======================================================================= #
  @section = [] # This array contains the keys, ie "Rubriken".
  @yaml_file = nil
  @use_ede = false # Whether to generate EDE desktop files as well.
  @section = nil
  @idesk_location = "#{SUPERUSER_DIR}.idesktop/"
  @fluxbox_entry = nil
  @ede_file = "#{SUPERUSER_DIR}.ede/desktop/"
  # Das geht auch für tabble:
  #   tabble -c /path/to/configuration/file
  #   tabble -c 
  # TABBLE_FILE = '/root/.tabble'
end

#runObject

#

run (run tag)

#


610
611
612
613
614
# File 'lib/roebe/classes/menu_generator/menu_generator.rb', line 610

def run
  _ = input?
  menu(_)
  create_menu_for(_)
end

#sanitize_yamlObject

#

sanitize_yaml

This will improve the YAML Dataset.

#


126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/roebe/classes/menu_generator/menu_generator.rb', line 126

def sanitize_yaml
  # ======================================================================= #
  # (1) Remove non-needed @section entries from
  # ======================================================================= #
  @section.delete('tabble')
  @section.delete('fluxbox')
  # ======================================================================= #
  # (2) assign the result of .delete these sections to vars, so we can use
  # them lateron. These are very specific, thus we delete them from our
  # general resource.
  # ======================================================================= #
  @tabble_entry  = @yaml_file.delete('tabble') # to remove this entry from our hash pointer
  @fluxbox_entry = @yaml_file.delete('fluxbox')
end

#set_input(i = DEFAULT_INPUT) ⇒ Object

#

set_input

#


71
72
73
74
75
76
# File 'lib/roebe/classes/menu_generator/menu_generator.rb', line 71

def set_input(i = DEFAULT_INPUT)
  i = i.first if i.is_a? Array
  i = DEFAULT_INPUT if i.nil?
  i = i.to_sym
  @input = i
end

#show_helpObject

#

show_help

#


601
602
603
604
605
# File 'lib/roebe/classes/menu_generator/menu_generator.rb', line 601

def show_help
  e
  e ' --fluxbox # generate a menu for fluxbox'
  e
end