fluxbox_apps_menu 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,100 @@
1
+ module FluxboxAppsMenu
2
+
3
+ class Menu
4
+
5
+ def initialize(cfg = nil)
6
+ @cfg = cfg.nil? ? FluxboxAppsMenu::Config.new : cfg
7
+ end
8
+
9
+ def assign_menu(cat, label)
10
+ traverse_menu(@cfg.menu, cat, label)[0]
11
+ end
12
+
13
+ def render
14
+ render_menu(@cfg.menu)
15
+ end
16
+
17
+ def item_exec(label, icon, command)
18
+ menu_item(label, icon, 'exec', command)
19
+ end
20
+
21
+ def item_submenu(label, icon)
22
+ menu_item(label, icon, 'submenu')
23
+ end
24
+
25
+ def item_separator
26
+ menu_item('', '', 'separator')
27
+ end
28
+
29
+ # type = submenu, exec, separator
30
+ private
31
+
32
+ def menu_item(label, icon, type = 'exec', command = nil)
33
+ label = " (#{label})" unless label.to_s.empty?
34
+ icon = " <#{icon}>" unless icon.to_s.empty?
35
+ command = " {#{command}}" unless command.nil?
36
+
37
+ "[#{type}]#{label}#{command}#{icon}"
38
+ end
39
+
40
+ def traverse_menu(menu, cat, label, selected_index = nil)
41
+ #categories with smaller index are the favorites
42
+ selected_index ||= 10000
43
+ selected = nil
44
+
45
+ items = menu.select { |k, v| k.class == String }
46
+
47
+ items.each do |key, info|
48
+ if info.class == Hash
49
+ subitems = info.select { |k, v| k.class == String }
50
+
51
+ # when a label is set the path has high priority
52
+ return [info, 0] if info.has_key?(label)
53
+
54
+ unless subitems.to_hash.empty?
55
+ result, index = traverse_menu(subitems, cat, label, selected_index)
56
+ selected, selected_index = result, index unless result.nil?
57
+ end
58
+
59
+ cat.each do |c|
60
+ if info[:categories].include?(c.strip)
61
+ i = info[:categories].index(c)
62
+ if i < selected_index
63
+ selected = info
64
+ selected_index = i
65
+ end
66
+ end
67
+ end if info.has_key? :categories
68
+ end
69
+ end
70
+
71
+ [selected, selected_index]
72
+ end
73
+
74
+ def render_menu(menu, level = 0)
75
+ prefix = ' ' * (level)
76
+ text = ''
77
+
78
+ # sort the items but let menu folders at the top
79
+ menu = menu.select { |k, v| k.class == String }.sort_by { |k, v| v.class == String ? k.downcase : '' }
80
+ menu.each do |name, items|
81
+ if items.class.to_s == 'Hash'
82
+ text += prefix + item_submenu(name, @cfg.expand_icon(nil, items[:icon])) + "\n"
83
+
84
+ items = items.select { |k, v| k.class == String }
85
+
86
+ text += render_menu(items, level + 1)
87
+
88
+ text += "#{prefix}[end]\n"
89
+ elsif items.class.to_s == 'String'
90
+ text += prefix + items + "\n"
91
+ end
92
+ end
93
+
94
+ text
95
+
96
+ end
97
+
98
+ end
99
+
100
+ end
@@ -0,0 +1,21 @@
1
+ class String
2
+ def black; "\033[30m#{self}\033[0m" end
3
+ def red; "\033[31m#{self}\033[0m" end
4
+ def green; "\033[32m#{self}\033[0m" end
5
+ def yellow; "\033[33m#{self}\033[0m" end
6
+ def blue; "\033[34m#{self}\033[0m" end
7
+ def magenta; "\033[35m#{self}\033[0m" end
8
+ def cyan; "\033[36m#{self}\033[0m" end
9
+ def gray; "\033[37m#{self}\033[0m" end
10
+ def bg_black; "\033[40m#{self}\0330m" end
11
+ def bg_red; "\033[41m#{self}\033[0m" end
12
+ def bg_green; "\033[42m#{self}\033[0m" end
13
+ def bg_brown; "\033[43m#{self}\033[0m" end
14
+ def bg_blue; "\033[44m#{self}\033[0m" end
15
+ def bg_magenta; "\033[45m#{self}\033[0m" end
16
+ def bg_cyan; "\033[46m#{self}\033[0m" end
17
+ def bg_gray; "\033[47m#{self}\033[0m" end
18
+ def bold; "\033[1m#{self}\033[22m" end
19
+ def reverse_color; "\033[7m#{self}\033[27m" end
20
+ end
21
+
@@ -0,0 +1,3 @@
1
+ module FluxboxAppsMenu
2
+ VERSION = "1.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluxbox_apps_menu
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Fabio Mucciante
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-08-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.6'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.6'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: inifile
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '3.0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: thor
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: This script reads the .desktop files installed and build the application's
79
+ menu under the Fluxbox home folder.
80
+ email:
81
+ - fabio.mucciante@gmail.com
82
+ executables:
83
+ - fluxbox_apps_menu
84
+ extensions: []
85
+ extra_rdoc_files: []
86
+ files:
87
+ - Gemfile
88
+ - Gemfile.lock
89
+ - LICENSE
90
+ - README.md
91
+ - Rakefile
92
+ - bin/fluxbox_apps_menu
93
+ - fluxbox_apps_menu.gemspec
94
+ - lib/fluxbox_apps_menu.rb
95
+ - lib/fluxbox_apps_menu.yaml
96
+ - lib/fluxbox_apps_menu/cli.rb
97
+ - lib/fluxbox_apps_menu/config.rb
98
+ - lib/fluxbox_apps_menu/desktop_file.rb
99
+ - lib/fluxbox_apps_menu/menu.rb
100
+ - lib/fluxbox_apps_menu/utils.rb
101
+ - lib/fluxbox_apps_menu/version.rb
102
+ homepage: https://github.com/fabiomux/fluxbox_apps_menu
103
+ licenses:
104
+ - GPL v.3
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 1.8.23
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: Build the Fluxbox apps menu.
127
+ test_files: []