everyday-menu 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +45 -15
- data/examples/basic_main_menu/app_delegate.rb +11 -12
- data/examples/basic_main_menu/main_menu.rb +5 -5
- data/lib/everyday-menu/everyday_command.rb +50 -0
- data/lib/everyday-menu/menu_item.rb +15 -6
- data/lib/everyday-menu/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da6d30cd6c8e784123bf3c01669eb99c27c29b82
|
4
|
+
data.tar.gz: 351d736ce3c8d45269d1432ad0573641e9346786
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4deb36dd997d2e87e0bdad716a60ea03b79f5a359ecc765e29353a04dcb011d4a2ccfb948a5ac4283c303fc57de7728dff3c7cb4453682169f8afabecd8d4046
|
7
|
+
data.tar.gz: 1b3401db78117dfedf598c2f48f6feae52c598da6c7a2b88e05ab8b6b61cdfa2edfb9114e7f1ca17aec716ddc9e8a17abe601e5b1a1d889735d2f9813324f9e2
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# EverydayMenu
|
2
2
|
|
3
|
+
## Issue Tracking
|
4
|
+
Please use <https://everydayprogramminggenius.atlassian.net/browse/EM> for issue tracking.
|
5
|
+
|
3
6
|
## Credit
|
4
7
|
Please note that this gem is strongly based off of Joe Fiorini's `drink-menu` gem (with a little code copy-paste and lots of test and readme copy-paste), which I couldn't get to work for me.
|
5
8
|
|
@@ -28,35 +31,62 @@ Everyday Menu separates menu layout from menu definition. Menu definition looks
|
|
28
31
|
class MainMenu
|
29
32
|
extend EverydayMenu::MenuBuilder
|
30
33
|
|
31
|
-
menuItem :create_site, 'Create Site'
|
32
|
-
menuItem :export, 'Export to Folder...'
|
33
|
-
menuItem :import, 'Import Folder as Site...'
|
34
|
-
menuItem :force_rebuild, 'Force Rebuild'
|
35
|
-
menuItem :about, 'About Staticly'
|
36
34
|
menuItem :quit, 'Quit', key_equivalent: 'q'
|
35
|
+
|
36
|
+
menuItem :open, 'Open', key_equivalent: 'o'
|
37
|
+
menuItem :new, 'New'
|
38
|
+
menuItem :close, 'Close', key_equivalent: 'w'
|
37
39
|
end
|
40
|
+
|
38
41
|
```
|
39
42
|
|
40
|
-
|
43
|
+
Layout is as simple as:
|
41
44
|
|
42
45
|
```ruby
|
43
|
-
|
44
46
|
class MainMenu
|
45
47
|
extend EverydayMenu::MenuBuilder
|
46
48
|
|
47
|
-
mainMenu
|
48
|
-
create_site
|
49
|
-
___
|
50
|
-
export
|
51
|
-
import
|
52
|
-
force_rebuild
|
53
|
-
___
|
54
|
-
about
|
49
|
+
mainMenu(:app, 'Blah') {
|
55
50
|
quit
|
51
|
+
}
|
52
|
+
|
53
|
+
mainMenu(:file, 'File') {
|
54
|
+
new
|
55
|
+
open
|
56
|
+
___
|
57
|
+
close
|
58
|
+
}
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
And actions are as simple as:
|
63
|
+
```ruby
|
64
|
+
class AppDelegate
|
65
|
+
def applicationDidFinishLaunching(notification)
|
66
|
+
@has_open = false
|
67
|
+
MainMenu.build!
|
68
|
+
|
69
|
+
MainMenu[:app].subscribe(:quit) { |_, _| NSApp.terminate(self) }
|
70
|
+
|
71
|
+
MainMenu[:file].subscribe(:new) { |_, _|
|
72
|
+
@has_open = true
|
73
|
+
puts 'new'
|
74
|
+
}
|
75
|
+
|
76
|
+
MainMenu[:file].subscribe(:close) { |_, _|
|
77
|
+
@has_open = false
|
78
|
+
puts 'close'
|
79
|
+
}.canExecuteBlock { |_| @has_open }
|
80
|
+
|
81
|
+
MainMenu[:file].subscribe(:open) { |_, _|
|
82
|
+
@has_open = true
|
83
|
+
puts 'open'
|
84
|
+
}
|
56
85
|
end
|
57
86
|
end
|
58
87
|
```
|
59
88
|
|
89
|
+
|
60
90
|
## Running the Examples
|
61
91
|
|
62
92
|
To run our example apps:
|
@@ -1,24 +1,23 @@
|
|
1
1
|
class AppDelegate
|
2
|
-
|
3
2
|
def applicationDidFinishLaunching(notification)
|
3
|
+
@has_open = false
|
4
4
|
MainMenu.build!
|
5
5
|
|
6
|
-
MainMenu[:app].subscribe
|
7
|
-
NSApp.terminate(self)
|
8
|
-
end
|
6
|
+
MainMenu[:app].subscribe(:quit) { |_, _| NSApp.terminate(self) }
|
9
7
|
|
10
|
-
MainMenu[:file].subscribe
|
8
|
+
MainMenu[:file].subscribe(:new) { |_, _|
|
9
|
+
@has_open = true
|
11
10
|
puts 'new'
|
12
|
-
|
11
|
+
}
|
13
12
|
|
14
|
-
MainMenu[:file].subscribe
|
13
|
+
MainMenu[:file].subscribe(:close) { |_, _|
|
14
|
+
@has_open = false
|
15
15
|
puts 'close'
|
16
|
-
|
16
|
+
}.canExecuteBlock { |_| @has_open }
|
17
17
|
|
18
|
-
MainMenu[:file].subscribe
|
18
|
+
MainMenu[:file].subscribe(:open) { |_, _|
|
19
|
+
@has_open = true
|
19
20
|
puts 'open'
|
20
|
-
|
21
|
-
|
21
|
+
}
|
22
22
|
end
|
23
|
-
|
24
23
|
end
|
@@ -2,19 +2,19 @@ class MainMenu
|
|
2
2
|
extend EverydayMenu::MenuBuilder
|
3
3
|
|
4
4
|
menuItem :quit, 'Quit', key_equivalent: 'q'
|
5
|
+
|
5
6
|
menuItem :open, 'Open', key_equivalent: 'o'
|
6
7
|
menuItem :new, 'New'
|
7
|
-
|
8
8
|
menuItem :close, 'Close', key_equivalent: 'w'
|
9
9
|
|
10
|
-
mainMenu
|
10
|
+
mainMenu(:app, 'Blah') {
|
11
11
|
quit
|
12
|
-
|
12
|
+
}
|
13
13
|
|
14
|
-
mainMenu
|
14
|
+
mainMenu(:file, 'File') {
|
15
15
|
new
|
16
16
|
open
|
17
17
|
___
|
18
18
|
close
|
19
|
-
|
19
|
+
}
|
20
20
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module EverydayMenu
|
2
|
+
class EverydayCommand
|
3
|
+
attr_reader :label
|
4
|
+
attr_writer :canExecute
|
5
|
+
|
6
|
+
def initialize(label, canExecute = true, &block)
|
7
|
+
@label = label
|
8
|
+
@block = block
|
9
|
+
@canExecute = canExecute
|
10
|
+
@canExecuteBlock = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def canExecuteBlock(&block)
|
14
|
+
@canExecuteBlock = block
|
15
|
+
end
|
16
|
+
|
17
|
+
def canExecute
|
18
|
+
@canExecuteBlock.nil? ? @canExecute : @canExecuteBlock.call(self)
|
19
|
+
end
|
20
|
+
|
21
|
+
def execute(sender)
|
22
|
+
@block.call(self, sender)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class CommandList
|
27
|
+
attr_accessor :label
|
28
|
+
|
29
|
+
def initialize(label)
|
30
|
+
@label = label
|
31
|
+
@items = []
|
32
|
+
end
|
33
|
+
|
34
|
+
def add(&block)
|
35
|
+
@items << EverydayCommand.new(@label, &block)
|
36
|
+
end
|
37
|
+
|
38
|
+
def last
|
39
|
+
@items.last
|
40
|
+
end
|
41
|
+
|
42
|
+
def execute(sender)
|
43
|
+
@items.each { |item| item.execute(sender) }
|
44
|
+
end
|
45
|
+
|
46
|
+
def canExecute
|
47
|
+
@items.any? { |item| item.canExecute }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -98,7 +98,7 @@ module EverydayMenu
|
|
98
98
|
alias :tag= :setTag
|
99
99
|
|
100
100
|
def subscribe(&block)
|
101
|
-
@menuItem.subscribe(&block)
|
101
|
+
@menuItem.subscribe(self.label, &block)
|
102
102
|
end
|
103
103
|
|
104
104
|
def execute
|
@@ -108,16 +108,25 @@ module EverydayMenu
|
|
108
108
|
end
|
109
109
|
|
110
110
|
class NSMenuItem
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
111
|
+
attr_reader :commands
|
112
|
+
|
113
|
+
def subscribe(label, &block)
|
114
|
+
@commands ||= EverydayMenu::CommandList.new(label)
|
115
|
+
@commands.add &block
|
116
|
+
command = @commands.last
|
117
|
+
self.enabled = @commands.canExecute
|
118
|
+
unless @boundEnabled
|
119
|
+
@boundEnabled = true
|
120
|
+
self.bind(NSEnabledBinding, toObject: self.commands, withKeyPath: 'canExecute', options: nil)
|
121
|
+
end
|
122
|
+
return command if (self.target = self && self.action == :'runBlocks:')
|
115
123
|
@original_target = self.target
|
116
124
|
self.target = self
|
117
125
|
self.action = :'runBlock:'
|
126
|
+
command
|
118
127
|
end
|
119
128
|
|
120
129
|
def runBlock(sender)
|
121
|
-
@
|
130
|
+
@commands.execute(sender) unless @commands.nil?
|
122
131
|
end
|
123
132
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: everyday-menu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Henderson
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- examples/basic_main_menu/app_delegate.rb
|
56
56
|
- examples/basic_main_menu/main_menu.rb
|
57
57
|
- lib/everyday-menu.rb
|
58
|
+
- lib/everyday-menu/everyday_command.rb
|
58
59
|
- lib/everyday-menu/menu.rb
|
59
60
|
- lib/everyday-menu/menu_builder.rb
|
60
61
|
- lib/everyday-menu/menu_item.rb
|