mynu 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGES ADDED
@@ -0,0 +1 @@
1
+ None yet!
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
@@ -0,0 +1,17 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mynu (0.1.0)
5
+ bundler (~> 1.0.0)
6
+ rake
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ rake (0.9.0)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ mynu!
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2011 by Robert Lowe <rob[!]iblargz.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,23 @@
1
+ Mynu
2
+ =====
3
+
4
+ A simple DSL to create a systembar menu with macruby in OSX
5
+
6
+
7
+ 1. `gem install mynu`
8
+ 2. `macruby examples/hello-mynu.rb`
9
+
10
+ Or if your feeling bohemian:
11
+
12
+ `macruby examples/queen.rb`
13
+
14
+ Todo
15
+ =====
16
+ * Lots
17
+ * Reloading
18
+ * Crash Handling
19
+ * FileMenuItem
20
+ * Improved API
21
+ * Simple Dialogs?
22
+
23
+ # Copyright (C) 2011 by Robert Lowe <rob[!]iblargz.com> - MIT
@@ -0,0 +1,40 @@
1
+ require 'rake/clean'
2
+ require 'rake/testtask'
3
+ require 'fileutils'
4
+ require 'date'
5
+
6
+ require 'lib/mynu/version.rb'
7
+
8
+ # task :default => :test
9
+ # task :spec => :test
10
+
11
+ # PACKAGING ============================================================
12
+
13
+ if defined?(Gem)
14
+ # Load the gemspec using the same limitations as github
15
+ def spec
16
+ require 'rubygems' unless defined? Gem::Specification
17
+ @spec ||= eval(File.read('mynu.gemspec'))
18
+ end
19
+
20
+ def package(ext='')
21
+ "pkg/mynu-#{spec.version}" + ext
22
+ end
23
+
24
+ desc 'Build packages'
25
+ task :package => %w[.gem].map {|e| package(e)}
26
+
27
+ desc 'Build and install as local gem'
28
+ task :install => package('.gem') do
29
+ `gem install #{package('.gem')}`
30
+ end
31
+
32
+ directory 'pkg/'
33
+ CLOBBER.include('pkg')
34
+
35
+ file package('.gem') => %w[pkg/ mynu.gemspec] + spec.files do |f|
36
+ `gem build mynu.gemspec`
37
+ mv File.basename(f.name), f.name
38
+ end
39
+
40
+ end
@@ -0,0 +1,69 @@
1
+ unless RUBY_ENGINE =~ /macruby/
2
+ raise NotImplementedError, "Mynu only runs on macruby! ;)"
3
+ end
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+
7
+ framework 'AppKit'
8
+
9
+ class Mynu
10
+ autoload :Version, 'mynu/version'
11
+
12
+ autoload :Menu, 'mynu/menu' # wrapping NSMenu
13
+ autoload :Dsl, 'mynu/dsl' # dsl modules
14
+
15
+ include Dsl::Block
16
+
17
+ attr_accessor :app # the sharedApplication
18
+ attr_accessor :status_item # the new bar icon
19
+ attr_accessor :menu # menu container
20
+ attr_accessor :items # root items
21
+
22
+ # Prepare the application
23
+ def initialize(icon = nil, menu_title = 'Mynu')
24
+ @app = NSApplication.sharedApplication
25
+
26
+ icon = File.join(File.dirname(__FILE__), '..', 'lib') + '/mynu/assets/logo.png' if icon.nil?
27
+
28
+ @status_item = status_bar.statusItemWithLength(NSVariableStatusItemLength)
29
+ @status_item.setImage NSImage.new.initWithContentsOfFile(icon)
30
+
31
+ @menu = Menu.new
32
+ @menu.initWithTitle menu_title
33
+ @menu.setAutoenablesItems false
34
+
35
+ @items = []
36
+ end
37
+
38
+ def run
39
+ @status_item.setMenu loadMenu
40
+ @app.run
41
+ end
42
+
43
+ def quit(sender)
44
+ puts "Quitting :: Mynu"
45
+ @app.terminate(self)
46
+ end
47
+
48
+ protected
49
+
50
+ def status_bar
51
+ NSStatusBar.systemStatusBar
52
+ end
53
+
54
+ def loadMenu
55
+ @items.each do |item|
56
+ @menu.addItem item
57
+ end
58
+
59
+ quit = Menu::MenuItem.new
60
+ quit.title = 'Quit'
61
+ quit.action = 'quit:'
62
+ quit.target = self
63
+ @menu.addItem quit
64
+
65
+ @menu
66
+ end
67
+
68
+ end
69
+
Binary file
@@ -0,0 +1,5 @@
1
+ class Mynu
2
+ module Dsl
3
+ autoload :Block, 'mynu/dsl/block'
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ class Mynu
2
+ module Dsl
3
+ module Block
4
+ def item(title, &block)
5
+ if block_given?
6
+ item = Menu::BlockMenuItem.new(title, block)
7
+ @items << item
8
+ item
9
+ else
10
+ raise
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,6 @@
1
+ class Mynu
2
+ class Menu < NSMenu
3
+ autoload :MenuItem, 'mynu/menu/menu_item'
4
+ autoload :BlockMenuItem, 'mynu/menu/block_menu_item'
5
+ end
6
+ end
@@ -0,0 +1,53 @@
1
+ class Mynu
2
+ module Menu
3
+ class BlockMenuItem < MenuItem
4
+ include Dsl::Block
5
+
6
+ def execute(&block)
7
+ self.action = 'call:'
8
+ self.target = block
9
+ end
10
+
11
+ def initialize(title, block)
12
+ super # thanks for asking
13
+
14
+ self.title = title
15
+
16
+ case block.arity
17
+ when 0
18
+ # regular item
19
+ self.action = 'call:'
20
+ self.target = block
21
+ when 1
22
+ block.call(self)
23
+
24
+ if @items.length > 0
25
+ menu = Menu.new
26
+ menu.setAutoenablesItems false
27
+
28
+ self.setSubmenu menu
29
+
30
+ @items.each do |item|
31
+ menu.addItem item
32
+ end
33
+ end
34
+ else
35
+ raise
36
+ end
37
+ end
38
+
39
+ def disabled
40
+ self.setEnabled(false)
41
+ self.isEnabled
42
+ end
43
+
44
+ def enabled
45
+ self.setEnabled(true)
46
+ self.isEnabled
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+ end
53
+
@@ -0,0 +1,12 @@
1
+ class Mynu
2
+ module Menu
3
+ class MenuItem < NSMenuItem
4
+ attr_accessor :items
5
+ # def initialize; @items = []; end # replacement
6
+ define_method(:initialize) do |*params|
7
+ @items = []
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,10 @@
1
+ class Mynu
2
+ module Version
3
+ MAJOR = 0
4
+ MINOR = 2
5
+ PATCH = 4
6
+ BUILD = nil
7
+
8
+ STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
9
+ end
10
+ end
@@ -0,0 +1,56 @@
1
+ require 'lib/mynu/version'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{mynu}
5
+ s.version = "#{Mynu::Version::STRING}"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Rob Lowe"]
9
+ s.date = %q{2011-05-29}
10
+ s.description = %q{A simple DSL to create a systembar menu with macruby in OSX}
11
+ s.email = %q{rob@iblargz.com}
12
+ s.extra_rdoc_files = [
13
+ "LICENSE",
14
+ "CHANGES",
15
+ "README.md"
16
+ ]
17
+ s.files = [
18
+ "Gemfile",
19
+ "Gemfile.lock",
20
+ "LICENSE",
21
+ "README.md",
22
+ "Rakefile",
23
+ "mynu.gemspec",
24
+ "lib/mynu.rb",
25
+ "lib/mynu/assets/logo.png",
26
+ "lib/mynu/menu.rb",
27
+ "lib/mynu/menu/menu_item.rb",
28
+ "lib/mynu/menu/block_menu_item.rb",
29
+ "lib/mynu/dsl.rb",
30
+ "lib/mynu/dsl/block.rb",
31
+ "lib/mynu/version.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/RobertLowe/mynu}
34
+ s.licenses = ["MIT"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.4.2}
37
+ s.summary = %q{Opinionated tool for creating and managing a system menu in osx}
38
+
39
+ if s.respond_to? :specification_version then
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
+ s.add_runtime_dependency(%q<rake>, [">= 0"])
44
+ s.add_runtime_dependency(%q<bundler>, ["~> 1.0.0"])
45
+ # s.add_development_dependency(%q<shoulda>, [">= 0"])
46
+ else
47
+ s.add_dependency(%q<rake>, [">= 0"])
48
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
49
+ # s.add_dependency(%q<shoulda>, [">= 0"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<rake>, [">= 0"])
53
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
54
+ # s.add_dependency(%q<shoulda>, [">= 0"])
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mynu
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.2.4
6
+ platform: ruby
7
+ authors:
8
+ - Rob Lowe
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-05-29 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ prerelease: false
18
+ requirement: !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - '>='
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - '>='
29
+ - !ruby/object:Gem::Version
30
+ version: "0"
31
+ - !ruby/object:Gem::Dependency
32
+ name: bundler
33
+ prerelease: false
34
+ requirement: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: 1.0.0
40
+ type: :runtime
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 1.0.0
47
+ description: A simple DSL to create a systembar menu with macruby in OSX
48
+ email: rob@iblargz.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files:
52
+ - LICENSE
53
+ - CHANGES
54
+ - README.md
55
+ files:
56
+ - Gemfile
57
+ - Gemfile.lock
58
+ - LICENSE
59
+ - README.md
60
+ - Rakefile
61
+ - mynu.gemspec
62
+ - lib/mynu.rb
63
+ - lib/mynu/assets/logo.png
64
+ - lib/mynu/menu.rb
65
+ - lib/mynu/menu/menu_item.rb
66
+ - lib/mynu/menu/block_menu_item.rb
67
+ - lib/mynu/dsl.rb
68
+ - lib/mynu/dsl/block.rb
69
+ - lib/mynu/version.rb
70
+ - CHANGES
71
+ has_rdoc: true
72
+ homepage: http://github.com/RobertLowe/mynu
73
+ licenses:
74
+ - MIT
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: "0"
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: "0"
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 1.4.2
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: Opinionated tool for creating and managing a system menu in osx
97
+ test_files: []