Skip to content

Commit

Permalink
change tabs_helper to menu_builder
Browse files Browse the repository at this point in the history
  • Loading branch information
danielvlopes committed Mar 6, 2010
1 parent 6578238 commit f8823cd
Show file tree
Hide file tree
Showing 43 changed files with 912 additions and 271 deletions.
2 changes: 1 addition & 1 deletion app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class HomeController < ApplicationController
current_tab :home
menu_item :home

def index
@next_meeting = Meeting.next(Date.today).first
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/meetings_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class MeetingsController < ApplicationController
load_and_authorize_resource
inherit_resources
current_tab :meetings
menu_item :meetings

def index
@next_meeting = Meeting.next(Date.today).first
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ProjectsController < ApplicationController
current_tab :projects
menu_item :projects

def index
@users = User.active.with_projects
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class UsersController < ApplicationController
load_and_authorize_resource
inherit_resources
current_tab :users
menu_item :users

respond_to :html, :xml, :json

Expand Down
10 changes: 5 additions & 5 deletions app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
= link_to 'rails<span>mg</span>', root_path

%nav#nav
- tabs :class=>"menu" do |tab|
= tab.home 'Home', root_path
= tab.users 'Membros', users_path
= tab.projects 'Projetos', projects_path
= tab.meetings 'Encontros', meetings_path
- menu :class=>"menu" do |m|
= m.home 'Home', root_path
= m.users 'Membros', users_path
= m.projects 'Projetos', projects_path
= m.meetings 'Encontros', meetings_path

#content{ :class => "#{controller.controller_name} #{controller.action_name}" }
= yield
Expand Down
1 change: 1 addition & 0 deletions config/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
config.gem 'cancan', :version => '1.0.2'
config.gem 'haml', :version => '2.2.15'
config.gem 'formtastic', :version => '0.9.7'
config.gem 'menu_builder', :version => '0.2.0'
config.gem 'paperclip', :version => '2.3.1.1'
config.gem 'inherited_resources', :version => '0.9.4'

Expand Down
5 changes: 5 additions & 0 deletions vendor/gems/menu_builder-0.0.2/.document
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
README.rdoc
lib/**/*.rb
bin/*
features/**/*.feature
LICENSE
21 changes: 21 additions & 0 deletions vendor/gems/menu_builder-0.0.2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## MAC OS
.DS_Store

## TEXTMATE
*.tmproj
tmtags

## EMACS
*~
\#*
.\#*

## VIM
*.swp

## PROJECT::GENERAL
coverage
rdoc
pkg

## PROJECT::SPECIFIC
76 changes: 76 additions & 0 deletions vendor/gems/menu_builder-0.0.2/.specification
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
--- !ruby/object:Gem::Specification
name: menu_builder
version: !ruby/object:Gem::Version
prerelease: false
segments:
- 0
- 0
- 2
version: 0.0.2
platform: ruby
authors:
- Daniel Lopes
autorequire:
bindir: bin
cert_chain: []

date: 2010-03-06 00:00:00 -03:00
default_executable:
dependencies: []

description: " Some helpers for define current tab (or item) of menu in controller and also create the menu in view. "
email: [email protected]
executables: []

extensions: []

extra_rdoc_files:
- LICENSE
- README.rdoc
files:
- .document
- .gitignore
- LICENSE
- README.rdoc
- Rakefile
- VERSION
- init.rb
- lib/menu_builder.rb
- lib/menu_builder/controller.rb
- lib/menu_builder/view.rb
- menu_builder.gemspec
- test/helper.rb
- test/test_menu_builder.rb
has_rdoc: true
homepage: http://github.com/danielvlopes/menu_builder
licenses: []

post_install_message:
rdoc_options:
- --charset=UTF-8
require_paths:
- lib
required_ruby_version: !ruby/object:Gem::Requirement
requirements:
- - ">="
- !ruby/object:Gem::Version
segments:
- 0
version: "0"
required_rubygems_version: !ruby/object:Gem::Requirement
requirements:
- - ">="
- !ruby/object:Gem::Version
segments:
- 0
version: "0"
requirements: []

rubyforge_project:
rubygems_version: 1.3.6
signing_key:
specification_version: 3
summary: Killer solutions for menus and tabs for Rails
test_files:
- test/helper.rb
- test/test_menu_builder.rb
2 changes: 1 addition & 1 deletion vendor/plugins/tabs_helper/MIT-LICENSE → vendor/gems/menu_builder-0.0.2/LICENSE
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2008 [name of plugin creator]
Copyright (c) 2009 Daniel Lopes

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
136 changes: 136 additions & 0 deletions vendor/gems/menu_builder-0.0.2/README.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
= menu_builder

With this gem/plugin you get a helper to define menus and also can control the current item of menu
in controller. Easy like always should be!

== Instalation

As a Rail2.1+ gem

gem.config "tabs_helper"

As Rails plugin

ruby script/plugin install git://github.com/danielvlopes/tabs_helper.git

== Usage

Just install the plugin and see the example below:

== Example

=== Controller

class DashboardController < ApplicationController
current_tab :mydashboard
...
end

=== View

==== ERB code

<% tabs :id=>"mainMenu", :class=>"menu" do |tab| %>
<%= tab.account 'Account', account_path, :style => 'float: right' %>
<%= tab.users 'Users', users_path, :style => 'float: right' %>
<%= tab.mydashboard 'Dashboard', '/' %>
<%= tab.projects 'Projects', projects_path %>
<% end %>

==== HTML Result

<ul id="mainMenu" class="menu">
<li><a href="/accounts">Account</a></li>
<li><a href="/users">Users</a></li>
<li><a href="/" class="current">Dashboard</a></li>
<li><a href="/projects">Projects</a></li>
</ul>

==== Blocks for content

Also is possible to pass blocks instead of simple strings for content.
In this way you can create tabs with icons. Like below:

<% tabs do |tab| %>
<% tab.account account_path do %>
<%= image_tag "account.jpg" /> Accounts
<% end %>
<% tab.users users_path do %>
<%= image_tag "user.jpg" /> Users
<% end %>
<% tab.posts posts_path do %>
<%= image_tag "posts.jpg" /> Posts
<% end %>
<% end %>

== CSS and HTML

This plugin don't came with any kind of asset like image or css. The layout of tabs and the way of show it depends of you css architecture. You can use any kind of technique with html UL and LI, like below:

<html>
<head>
<style type="text/css" charset="utf-8">
#header ul { font-family:Tahoma; position: absolute; margin:0; list-style:none; }
#header li { display:inline; margin:0; padding:0; }

#header a {
float:left;
background: url(corner_left.jpg) no-repeat left top;
margin:0;
padding:0 0 0 4px;
text-decoration:none;
}
#header a span {
float:left;
display:block;
background: url(corner_right.jpg) no-repeat right top;
padding:4px 14px 4px 6px;
color:#FFF;
}

#header a:hover span { color:#FFF; }
#header a:hover { background-position:0% -43px; }
#header a:hover span { background-position:100% -43px; }
#header #current a { background-position:0% -43px; }
#header #current a span { background-position:100% -43px; }
</style>
</head>

<body>
<div id="header">
<ul>
<li><a href="#"><span>Home</span></a></li>
<li><a href="#"><span>Quem Somos</span></a></li>
<li><a href="#"><span>Portif&oacute;lio</span></a></li>
<li><a href="#"><span>Contato</span></a></li>
</ul>
</div>
</body>
</html>

You can read a full tutorial and working demo of the technique above in this "link":http://www.google.com/translate?langpair=pt|en&u=http://blog.areacriacoes.com.br//2009/1/23/bordas-arredondas-para-menus-em-abas

== License

Tabs Helper is released under the MIT License.

== Author

Authors:: Daniel Lopes
Blog:: {http://blog.areacriacoes.com.br}[http://blog.areacriacoes.com.br]
Github:: {http://github.com/danielvlopes}[http://github.com/danielvlopes]
Twitter:: {danielvlopes}[http://blog.areacriacoes.com.br]

== Note on Patches/Pull Requests

* Fork the project.
* Make your feature addition or bug fix.
* Add tests for it. This is important so I don't break it in a
future version unintentionally.
* Commit, do not mess with rakefile, version, or history.
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
* Send me a pull request. Bonus points for topic branches.

== Copyright

Copyright (c) 2010 Daniel Lopes. See LICENSE for details.
51 changes: 51 additions & 0 deletions vendor/gems/menu_builder-0.0.2/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require 'rubygems'
require 'rake'

begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "menu_builder"
gem.summary = %Q{ Killer solutions for menus and tabs for Rails }
gem.description = %Q{ Some helpers for define current tab (or item) of menu in controller and also create the menu in view. }
gem.email = "[email protected]"
gem.homepage = "http://github.com/danielvlopes/menu_builder"
gem.authors = ["Daniel Lopes"]
end
Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
end

require 'rake/testtask'
Rake::TestTask.new(:test) do |test|
test.libs << 'lib' << 'test'
test.pattern = 'test/**/test_*.rb'
test.verbose = true
end

begin
require 'rcov/rcovtask'
Rcov::RcovTask.new do |test|
test.libs << 'test'
test.pattern = 'test/**/test_*.rb'
test.verbose = true
end
rescue LoadError
task :rcov do
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
end
end

task :test => :check_dependencies

task :default => :test

require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""

rdoc.rdoc_dir = 'rdoc'
rdoc.title = "menu_builder #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
1 change: 1 addition & 0 deletions vendor/gems/menu_builder-0.0.2/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.2
1 change: 1 addition & 0 deletions vendor/gems/menu_builder-0.0.2/init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require "menu_builder"
5 changes: 5 additions & 0 deletions vendor/gems/menu_builder-0.0.2/lib/menu_builder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'menu_builder/controller'
require 'menu_builder/view'

ActionController::Base.extend(MenuBuilder::Controller)
ActionView::Base.send(:include, MenuBuilder::ViewHelpers)
11 changes: 11 additions & 0 deletions vendor/gems/menu_builder-0.0.2/lib/menu_builder/controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module MenuBuilder
module Controller

def current_tab(name, options = {})
before_filter(options) do |controller|
controller.instance_variable_set('@current_tab', name)
end
end

end
end
Loading

0 comments on commit f8823cd

Please sign in to comment.