Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Fischer committed Jan 14, 2012
0 parents commit 0c0adcd
Show file tree
Hide file tree
Showing 12 changed files with 178 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
*.gem
.bundle
Gemfile.lock
pkg/*
*.gem
*.rbc
.bundle
.config
coverage
InstalledFiles
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp

# YARD artifacts
.yardoc
_yardoc
doc/
.DS_Store

# Thumbnails
._*

# Files that might appear on external disk
.Spotlight-V100
.Trashes
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--format progress
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source "http://rubygems.org"

# Specify your gem's dependencies in very_nice_menu.gemspec
gemspec
12 changes: 12 additions & 0 deletions README.textile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
h1. Very Nice Menu

This is a Ruby lib to create a tree of menus. Very nice. Really!
BTW this document is written with a certain portion of humor (insanity).

h2. Test

Before your dirty hands touch a single line of code be sure to run the tests by invoking

bc. rspec

Otherwise we'll find and punish you! Promised.
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'bundler/gem_tasks'
9 changes: 9 additions & 0 deletions lib/very_nice_menu.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "very_nice_menu/version"
require "very_nice_menu/menu"
require "very_nice_menu/entry"

module VeryNiceMenu
def self.build(name, options = {})
VeryNiceMenu::Menu.new(name, options)
end
end
10 changes: 10 additions & 0 deletions lib/very_nice_menu/entry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module VeryNiceMenu
class Entry
attr_accessor :name, :options

def initialize(name, options = {})
@name = name
@options = options
end
end
end
24 changes: 24 additions & 0 deletions lib/very_nice_menu/menu.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module VeryNiceMenu
class Menu
attr_accessor :name, :options
attr_reader :submenus
attr_reader :entries

def initialize(name, options = {})
@name = name
@options = options
@submenus = []
@entries = []
end

def submenu(name, options = {}, &block)
menu = Menu.new(name, options)
yield(menu)
@submenus << menu
end

def entry(name, options = {})
@entries << VeryNiceMenu::Entry.new(name, options)
end
end
end
3 changes: 3 additions & 0 deletions lib/very_nice_menu/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module VeryNiceMenu
VERSION = "0.0.1"
end
13 changes: 13 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'very_nice_menu'

# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# Require this file using `require "spec_helper.rb"` to ensure that it is only
# loaded once.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.run_all_when_everything_filtered = true
config.filter_run :focus
end
48 changes: 48 additions & 0 deletions spec/very_nice_menu/menu_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require 'spec_helper'

describe VeryNiceMenu::Menu do

context "Basics" do
it "should create a single menu instance" do
main_menu = VeryNiceMenu.build('Main Menu')
main_menu.should be_instance_of(VeryNiceMenu::Menu)
main_menu.name.should eql("Main Menu")
end

it "should create a single menu instance" do
main_menu = VeryNiceMenu.build('Main Menu', :description => "This is a very nice menu")
main_menu.should be_instance_of(VeryNiceMenu::Menu)
main_menu.options[:description].should eql("This is a very nice menu")
end

it "should create a menu with a single menu entry" do
main_menu = VeryNiceMenu.build('Main Menu')
main_menu.entry("Nice Entry")
main_menu.entries.should have(1).item
main_menu.entries.first.should be_instance_of(VeryNiceMenu::Entry)
end
end

context "Simple Nesting" do
it "should create a simple nested menu" do
main_menu = VeryNiceMenu.build('Main Menu')

main_menu.submenu("Main Menu - Submenu 1") do |submenu|
end

main_menu.submenus.should have(1).item
main_menu.submenus.first.should be_instance_of(VeryNiceMenu::Menu)
end

it "should create a simple nested menu with a menu entry at submenu level" do
main_menu = VeryNiceMenu.build('Main Menu')

main_menu.submenu("Main Menu - Submenu 1") do |submenu|
submenu.entry("Nice Entry")
end

main_menu.submenus.first.entries.should have(1).items
main_menu.submenus.first.entries.first.should be_instance_of(VeryNiceMenu::Entry)
end
end
end
22 changes: 22 additions & 0 deletions very_nice_menu.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "very_nice_menu/version"

Gem::Specification.new do |s|
s.name = "very_nice_menu"
s.version = VeryNiceMenu::VERSION
s.authors = ["Julian Fischer"]
s.email = ["[email protected]"]
s.homepage = ""
s.summary = %q{TODO: Write a gem summary}
s.description = %q{TODO: Write a gem description}

s.rubyforge_project = "very_nice_menu"

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

s.add_development_dependency "rspec"
end

0 comments on commit 0c0adcd

Please sign in to comment.