From fe925a41254785c23ed1bff82338efdf7343aadf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mich=C3=A8le=20Marais?= Date: Thu, 28 Mar 2013 14:08:05 +0100 Subject: [PATCH 01/16] added tabs --- lib/bootstrap-helper/builders/tabs.rb | 55 +++++++++++++++++++++++++++ lib/bootstrap-helper/helpers.rb | 2 + lib/bootstrap-helper/helpers/tabs.rb | 10 +++++ 3 files changed, 67 insertions(+) create mode 100644 lib/bootstrap-helper/builders/tabs.rb create mode 100644 lib/bootstrap-helper/helpers/tabs.rb diff --git a/lib/bootstrap-helper/builders/tabs.rb b/lib/bootstrap-helper/builders/tabs.rb new file mode 100644 index 0000000..d1522d3 --- /dev/null +++ b/lib/bootstrap-helper/builders/tabs.rb @@ -0,0 +1,55 @@ +module BootstrapHelper + module Builders + class Tabs + attr_accessor :template, :items + + def initialize(template, options = {}, &proc) + @template, @items = template, [] + render(options, &proc) + end + + def render(options, &proc) + buffer = template.capture(self, &proc) + template.concat(wrapper(options,buffer)) + end + + def wrapper(options, buffer) + template.content_tag( :div, class: "tabbable" ) do + content = tabs_titles do + content_items = ''.html_safe + items.each do |item| + content_items << item_title( item[:name], item[:id], item[:klass] ) + end + content_items + end + + content << template.content_tag( :div, class: "tab-content" ) do + buffer + end + end + end + + def tabs_titles(options = {}, &block) + buffer = template.capture( self, &proc ) + template.content_tag( :ul, buffer, class: "nav nav-tabs" ) + end + + def item_title(name, id, klass) + template.content_tag( :li, nil, class: klass ) do + template.link_to name, "##{id}", :data => { :toggle => 'tab' } + end + end + + def item(name, options = {}, &block) + klass = options[:active] ? "active" : "" + id = name.downcase.parameterize.gsub(/-/, '_') + + items << { :name => name, :id => id, :klass => klass } + + buffer = template.capture( self, &proc ) + template.content_tag( :div, buffer, class: "tab-pane #{klass}", :id => id ) + end + + end + end +end \ No newline at end of file diff --git a/lib/bootstrap-helper/helpers.rb b/lib/bootstrap-helper/helpers.rb index a477d21..1419a76 100644 --- a/lib/bootstrap-helper/helpers.rb +++ b/lib/bootstrap-helper/helpers.rb @@ -1,11 +1,13 @@ module BootstrapHelper module Helpers autoload :Navbar, 'bootstrap-helper/helpers/navbar' + autoload :Tabs, 'bootstrap-helper/helpers/tabs' autoload :Modal, 'bootstrap-helper/helpers/modal' autoload :Link, 'bootstrap-helper/helpers/link' autoload :Table, 'bootstrap-helper/helpers/table' autoload :Buttons, 'bootstrap-helper/helpers/buttons' include Navbar + include Tabs include Table include Modal include Link diff --git a/lib/bootstrap-helper/helpers/tabs.rb b/lib/bootstrap-helper/helpers/tabs.rb new file mode 100644 index 0000000..61d34c6 --- /dev/null +++ b/lib/bootstrap-helper/helpers/tabs.rb @@ -0,0 +1,10 @@ +require "bootstrap-helper/builders/tabs" +module BootstrapHelper + module Helpers + module Tabs + def tabs(options = {}, &proc) + ::BootstrapHelper::Builders::Tabs.new(self,options,&proc) + end + end + end +end \ No newline at end of file From 89700e83427c65ced43f1e0f0e19684e72c1cfd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mich=C3=A8le=20Marais?= Date: Wed, 3 Apr 2013 10:28:41 +0200 Subject: [PATCH 02/16] improved navbar --- README.md | 80 ++++++++++++++++--- lib/bootstrap-helper/builders/navbar.rb | 101 ++++++++++++++++++------ 2 files changed, 142 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 2c509e5..3e48d54 100644 --- a/README.md +++ b/README.md @@ -5,19 +5,6 @@ Include BootstrapHelper in Gemfile: gem 'bootstrap-helper',git: 'git://github.com/niedhui/bootstrap-helper.git' ``` -# topbar(Navigation) -``` ruby -- topbar do |bar| - = bar.brand_name "YourBrandName",root_path - = bar.nav do - = bar.item 'label1', "/url/url" - = bar.dropdown "dropdown_menu" do - = bar.item 'label2', "/url2/url2" - = bar.item 'label3', "/url3/url3" - = bar.second_nav do - = bar.item 'label4', "/url4/url4" -``` - # modal ``` ruby - modal id: "my_modal" do |m| @@ -43,3 +30,70 @@ gem 'bootstrap-helper',git: 'git://github.com/niedhui/bootstrap-helper.git' %li.divider %li= link_to "nihao" ``` + +# tabs +```ruby + <% tabs do |tab| %> + <%= tab.item "Tabs 1", { :active => true } do %> +

Title 1

+

Content 1

+ <% end %> + <%= tab.item "Tabs 2" do %> +

Title 2

+

Content 2

+ <% end %> + <% end %> +``` + +# navbar + +Simple use : + +```ruby + <% topbar do |bar| %> + + <%= bar.brand_name "YourBrandName", root_path %> + + <%= bar.nav do %> + <%= bar.item 'item', '#' %> + <%= bar.dropdown 'Title 1' do %> + <%= bar.item 'item 1', '#' %> + <%= bar.item 'item 2', '#' %> + <% end %> + <% end %> + + <% end %> +``` + +Or you can use like this : + + +```ruby + <% topbar( :inverse => true, :id => 'topBar' ) do |bar| %> + + <%= bar.collapse %> + <%= bar.brand_name "YourBrandName", root_path %> + + <%= bar.nav( :right => true ) do %> + + <%= bar.dropdown( :class => 'highlight' ) do %> + <%= bar.dropdown_title do %> + 10 + Title 2 + <% end %> + <%= bar.dropdown_menu( :right => true ) do %> + <%= bar.item do %> + Item 3 + <% end %> + <%= bar.item 'item 4', '#' %> + <%= bar.item '/link' do %> + Item 5 + 15 + <% end %> + <% end %> + <% end %> + + <% end %> + + <% end %> +``` \ No newline at end of file diff --git a/lib/bootstrap-helper/builders/navbar.rb b/lib/bootstrap-helper/builders/navbar.rb index 19ea670..1f14f5c 100644 --- a/lib/bootstrap-helper/builders/navbar.rb +++ b/lib/bootstrap-helper/builders/navbar.rb @@ -10,48 +10,97 @@ def initialize(template, options = {}, &proc) def render(options, &proc) buffer = template.capture(self, &proc) - template.concat(wrapper(options,buffer)) + template.concat(wrapper(options, buffer)) end - def wrapper(options ,buffer) - navbar_class = ["navbar"] - navbar_class << "navbar-fixed-top" if options[:top] - template.content_tag(:div, class: navbar_class, "data-dropdown" => "dropdown") do - template.content_tag(:div, class: "navbar-inner") do - template.content_tag(:div, buffer,class: "container") - end + def wrapper(options, buffer) + navbar_class = ['navbar'] + navbar_class << 'navbar-fixed-top' if options[:top] + navbar_class << 'navbar-inverse' if options[:inverse] + id = options[:id] || '' + + template.content_tag(:div, class: navbar_class, 'data-dropdown' => 'dropdown', :id => id) do + template.content_tag(:div, buffer, class: 'navbar-inner') end end - def brand_name(name,link = "#",options = {}) + def brand_name(name, link = '#', options = {}) template.link_to name, link, class: 'brand' end - - def nav(options = {},&block) + + def nav(options = {}, &block) buffer = template.capture(self, &proc) - template.content_tag(:ul,buffer, class: "nav") + klass = ['nav'] + klass << 'pull-right' if options[:right] + klass << 'pull-left' if options[:left] + + template.content_tag( :nav, class: klass ) do + template.content_tag( :ul, buffer, class: 'nav') + end end - def second_nav(options = {},&block) + def second_nav(options = {}, &block) + ActiveSupport::Deprecation.warn("use nav instead of second_nav") + nav(options.merge(:right => true), &block) + end + + def dropdown(*args, &proc) + if args.first.class == Hash + options = args.first + else + title = args.first + options = args.second || {} + end + + body = template.capture(self, &proc) + klass = ['dropdown'] + klass << options[:class] unless options[:class].nil? + + unless title.nil? + body = dropdown_title(title, options, &proc) + body << dropdown_menu(options, &proc) + end + + template.content_tag(:li, body, class: klass) + end + + def dropdown_title(title = nil, options = {}, &block) + body = title.nil? ? template.capture(self, &proc) : title.html_safe + body << template.content_tag(:b, nil, class: 'caret') + + template.link_to(body, '#', class: 'dropdown-toggle', 'data-toggle' => 'dropdown') + end + + def dropdown_menu(options = {}, &block) buffer = template.capture(self, &proc) - template.content_tag(:ul,buffer, class: ["nav","pull-right"]) + klass = ['dropdown-menu'] + klass << 'pull-right' if options[:right] + + template.content_tag(:ul, buffer, class: klass) end - def dropdown(title,options = {},&proc) - buffer = template.capture(self, &proc) - template.content_tag(:li,class: 'dropdown') do - link = template.link_to "#",class: 'dropdown-toggle',"data-toggle" => "dropdown" do - title.html_safe + template.content_tag(:b,"",class: 'caret') - end - link << template.content_tag(:ul,buffer, class: "dropdown-menu") + def item(*args, &block) + if block_given? + body = template.capture(self, &proc) + url = args.first || '#' + options = args.second || {} + else + body = args[0] + url = args[1] || '#' + options = args[2] || {} + end + + klass = options[:class] || '' + template.content_tag(:li, class: klass) do + template.link_to(body, url) end end - def item(title,link,options = {}) - template.content_tag(:li,template.link_to(title,link)) + def collapse + template.link_to nil, :class => 'btn btn-navbar collapsed', "data-toggle" => 'collapse', 'data-target' => '.nav-collapse' do + 3.times.map { template.content_tag :span, nil, class: 'icon-bar' }.inject(:+) + end end - end end -end - +end \ No newline at end of file From 0b69bc52c3365bee6ddc4f33623162cfccd41c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mich=C3=A8le=20Marais?= Date: Wed, 3 Apr 2013 11:38:33 +0200 Subject: [PATCH 03/16] Add divider_vertical --- lib/bootstrap-helper/builders/navbar.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/bootstrap-helper/builders/navbar.rb b/lib/bootstrap-helper/builders/navbar.rb index 1f14f5c..33a1787 100644 --- a/lib/bootstrap-helper/builders/navbar.rb +++ b/lib/bootstrap-helper/builders/navbar.rb @@ -101,6 +101,11 @@ def collapse 3.times.map { template.content_tag :span, nil, class: 'icon-bar' }.inject(:+) end end + + def divider_vertical + template.content_tag :li, nil, class: 'divider-vertical' + end + end end end \ No newline at end of file From bdb1a463fc6e75e7ee544fea3be3841cd54e509f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mich=C3=A8le=20Marais?= Date: Wed, 3 Apr 2013 11:45:04 +0200 Subject: [PATCH 04/16] Improved divider --- README.md | 2 ++ lib/bootstrap-helper/builders/navbar.rb | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3e48d54..ef889e0 100644 --- a/README.md +++ b/README.md @@ -56,8 +56,10 @@ Simple use : <%= bar.nav do %> <%= bar.item 'item', '#' %> + <%= bar.divider( :vertical => true ) %> <%= bar.dropdown 'Title 1' do %> <%= bar.item 'item 1', '#' %> + <%= bar.divider %> <%= bar.item 'item 2', '#' %> <% end %> <% end %> diff --git a/lib/bootstrap-helper/builders/navbar.rb b/lib/bootstrap-helper/builders/navbar.rb index 33a1787..93efadd 100644 --- a/lib/bootstrap-helper/builders/navbar.rb +++ b/lib/bootstrap-helper/builders/navbar.rb @@ -102,8 +102,11 @@ def collapse end end - def divider_vertical - template.content_tag :li, nil, class: 'divider-vertical' + def divider(options = {}) + klass = 'divider' + klass = 'divider-vertical' if options[:vertical] + + template.content_tag :li, nil, class: klass end end From 232d4eeafdad298d1b4b7b83d51d4362f3ab48b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mich=C3=A8le=20Marais?= Date: Wed, 3 Apr 2013 11:57:38 +0200 Subject: [PATCH 05/16] Add nav header --- README.md | 9 +++++++++ lib/bootstrap-helper/builders/navbar.rb | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/README.md b/README.md index ef889e0..6e7e402 100644 --- a/README.md +++ b/README.md @@ -58,9 +58,14 @@ Simple use : <%= bar.item 'item', '#' %> <%= bar.divider( :vertical => true ) %> <%= bar.dropdown 'Title 1' do %> + <%= bar.header "Items a" %> <%= bar.item 'item 1', '#' %> <%= bar.divider %> <%= bar.item 'item 2', '#' %> + <%= bar.item 'item 2', '#' %> + <%= bar.header "Items b" %> + <%= bar.item 'item 2', '#' %> + <%= bar.item 'item 2', '#' %> <% end %> <% end %> @@ -84,10 +89,14 @@ Or you can use like this : Title 2 <% end %> <%= bar.dropdown_menu( :right => true ) do %> + <%= bar.header do %> + Items a + <% end %> <%= bar.item do %> Item 3 <% end %> <%= bar.item 'item 4', '#' %> + <%= bar.header "Items b" %> <%= bar.item '/link' do %> Item 5 15 diff --git a/lib/bootstrap-helper/builders/navbar.rb b/lib/bootstrap-helper/builders/navbar.rb index 93efadd..c550ef6 100644 --- a/lib/bootstrap-helper/builders/navbar.rb +++ b/lib/bootstrap-helper/builders/navbar.rb @@ -109,6 +109,12 @@ def divider(options = {}) template.content_tag :li, nil, class: klass end + def header(title = nil, &block) + body = title.nil? ? template.capture(self, &proc) : title + + template.content_tag :li, body, class: 'nav-header' + end + end end end \ No newline at end of file From 9154eeee3bd1b2896043a51c01bb55d0182d5bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mich=C3=A8le=20Marais?= Date: Wed, 3 Apr 2013 13:31:09 +0200 Subject: [PATCH 06/16] Add bottombar --- lib/bootstrap-helper/builders/navbar.rb | 1 + lib/bootstrap-helper/helpers/navbar.rb | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/lib/bootstrap-helper/builders/navbar.rb b/lib/bootstrap-helper/builders/navbar.rb index c550ef6..3eadb56 100644 --- a/lib/bootstrap-helper/builders/navbar.rb +++ b/lib/bootstrap-helper/builders/navbar.rb @@ -16,6 +16,7 @@ def render(options, &proc) def wrapper(options, buffer) navbar_class = ['navbar'] navbar_class << 'navbar-fixed-top' if options[:top] + navbar_class << 'navbar-fixed-bottom' if options[:bottom] navbar_class << 'navbar-inverse' if options[:inverse] id = options[:id] || '' diff --git a/lib/bootstrap-helper/helpers/navbar.rb b/lib/bootstrap-helper/helpers/navbar.rb index b93927a..4bc300b 100644 --- a/lib/bootstrap-helper/helpers/navbar.rb +++ b/lib/bootstrap-helper/helpers/navbar.rb @@ -9,6 +9,10 @@ def navbar(options = {},&proc) def topbar(options = {}, &proc) ::BootstrapHelper::Builders::Navbar.new(self,options.merge(top: true),&proc) end + + def bottombar(options = {}, &proc) + ::BootstrapHelper::Builders::Navbar.new(self,options.merge(bottom: true),&proc) + end end end end \ No newline at end of file From 1c5db8eb0b892daf520528cbcd09297d1130dfa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mich=C3=A8le=20Marais?= Date: Wed, 3 Apr 2013 13:33:49 +0200 Subject: [PATCH 07/16] update README --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 6e7e402..8063f88 100644 --- a/README.md +++ b/README.md @@ -107,4 +107,21 @@ Or you can use like this : <% end %> <% end %> +``` + +Different uses : + + +```ruby +<% navbar do |bar| %> + ... +<% end %> + +<% topbar do |bar| %> + ... +<% end %> + +<% bottombar do |bar| %> + ... +<% end %> ``` \ No newline at end of file From 31eb3caf60a11bec4dcd40558c5204f5c1a2a135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mich=C3=A8le=20Marais?= Date: Wed, 3 Apr 2013 14:21:15 +0200 Subject: [PATCH 08/16] added active item --- README.md | 18 ++++++++---------- lib/bootstrap-helper/builders/navbar.rb | 7 ++----- lib/bootstrap-helper/helpers/navbar.rb | 4 ++-- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 8063f88..b79ca04 100644 --- a/README.md +++ b/README.md @@ -50,22 +50,22 @@ gem 'bootstrap-helper',git: 'git://github.com/niedhui/bootstrap-helper.git' Simple use : ```ruby - <% topbar do |bar| %> + <% navbar do |bar| %> <%= bar.brand_name "YourBrandName", root_path %> <%= bar.nav do %> - <%= bar.item 'item', '#' %> + <%= bar.item 'item', '#', { :active => true } %> <%= bar.divider( :vertical => true ) %> <%= bar.dropdown 'Title 1' do %> <%= bar.header "Items a" %> <%= bar.item 'item 1', '#' %> - <%= bar.divider %> - <%= bar.item 'item 2', '#' %> <%= bar.item 'item 2', '#' %> + <%= bar.divider %> + <%= bar.item 'item 3', '#' %> <%= bar.header "Items b" %> - <%= bar.item 'item 2', '#' %> - <%= bar.item 'item 2', '#' %> + <%= bar.item 'item 4', '#' %> + <%= bar.item 'item 5', '#' %> <% end %> <% end %> @@ -82,7 +82,6 @@ Or you can use like this : <%= bar.brand_name "YourBrandName", root_path %> <%= bar.nav( :right => true ) do %> - <%= bar.dropdown( :class => 'highlight' ) do %> <%= bar.dropdown_title do %> 10 @@ -103,13 +102,12 @@ Or you can use like this : <% end %> <% end %> <% end %> - <% end %> - + <% end %> ``` -Different uses : +Optional display variations : ```ruby diff --git a/lib/bootstrap-helper/builders/navbar.rb b/lib/bootstrap-helper/builders/navbar.rb index 3eadb56..15ce120 100644 --- a/lib/bootstrap-helper/builders/navbar.rb +++ b/lib/bootstrap-helper/builders/navbar.rb @@ -91,7 +91,7 @@ def item(*args, &block) options = args[2] || {} end - klass = options[:class] || '' + klass = options[:active] ? 'active' : '' template.content_tag(:li, class: klass) do template.link_to(body, url) end @@ -104,15 +104,12 @@ def collapse end def divider(options = {}) - klass = 'divider' - klass = 'divider-vertical' if options[:vertical] - + klass = "divider#{options[:vertical] ? '-vertical' : ''}" template.content_tag :li, nil, class: klass end def header(title = nil, &block) body = title.nil? ? template.capture(self, &proc) : title - template.content_tag :li, body, class: 'nav-header' end diff --git a/lib/bootstrap-helper/helpers/navbar.rb b/lib/bootstrap-helper/helpers/navbar.rb index 4bc300b..807581d 100644 --- a/lib/bootstrap-helper/helpers/navbar.rb +++ b/lib/bootstrap-helper/helpers/navbar.rb @@ -7,11 +7,11 @@ def navbar(options = {},&proc) end def topbar(options = {}, &proc) - ::BootstrapHelper::Builders::Navbar.new(self,options.merge(top: true),&proc) + navbar(options.merge(top: true),&proc) end def bottombar(options = {}, &proc) - ::BootstrapHelper::Builders::Navbar.new(self,options.merge(bottom: true),&proc) + navbar(options.merge(bottom: true),&proc) end end end From 9a9341f05d882789f65aa0e217de77f5281a8b41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mich=C3=A8le=20Marais?= Date: Mon, 8 Apr 2013 15:48:07 +0200 Subject: [PATCH 09/16] Adding a class to an item --- lib/bootstrap-helper/builders/navbar.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/bootstrap-helper/builders/navbar.rb b/lib/bootstrap-helper/builders/navbar.rb index 15ce120..10e8342 100644 --- a/lib/bootstrap-helper/builders/navbar.rb +++ b/lib/bootstrap-helper/builders/navbar.rb @@ -91,7 +91,8 @@ def item(*args, &block) options = args[2] || {} end - klass = options[:active] ? 'active' : '' + klass = options[:class] || [] + klass << 'active' if options[:active] template.content_tag(:li, class: klass) do template.link_to(body, url) end From b4acd7ff1069e5a7d6757024cba93b9a40bf01b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mich=C3=A8le=20Marais?= Date: Tue, 9 Apr 2013 11:21:18 +0200 Subject: [PATCH 10/16] Adding a data-toggle to an item (url) --- lib/bootstrap-helper/builders/navbar.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/bootstrap-helper/builders/navbar.rb b/lib/bootstrap-helper/builders/navbar.rb index 10e8342..59034a9 100644 --- a/lib/bootstrap-helper/builders/navbar.rb +++ b/lib/bootstrap-helper/builders/navbar.rb @@ -93,8 +93,10 @@ def item(*args, &block) klass = options[:class] || [] klass << 'active' if options[:active] + data_toggle = options[:url_data_toggle] || '' + template.content_tag(:li, class: klass) do - template.link_to(body, url) + template.link_to(body, url, 'data-toggle' => data_toggle) end end From c02435c97c0f0ab7adc5526b8d73e9b4bdf49e39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mich=C3=A8le=20Marais?= Date: Tue, 9 Apr 2013 13:40:53 +0200 Subject: [PATCH 11/16] Adding helper alert --- lib/bootstrap-helper/builders/alert.rb | 27 ++++++++++++++++++++++++++ lib/bootstrap-helper/helpers.rb | 2 ++ lib/bootstrap-helper/helpers/alert.rb | 22 +++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 lib/bootstrap-helper/builders/alert.rb create mode 100644 lib/bootstrap-helper/helpers/alert.rb diff --git a/lib/bootstrap-helper/builders/alert.rb b/lib/bootstrap-helper/builders/alert.rb new file mode 100644 index 0000000..98a7926 --- /dev/null +++ b/lib/bootstrap-helper/builders/alert.rb @@ -0,0 +1,27 @@ +module BootstrapHelper + module Builders + class Alert + attr_accessor :template, :items + + def initialize(template, options = {}, &proc) + @template, @items = template, [] + render(options, &proc) + end + + def render(options, &proc) + buffer = template.capture(self, &proc) + template.concat(wrapper(options,buffer)) + end + + def wrapper(options, buffer) + klass = options[:type].nil? ? ['alert'] : ["alert alert-#{options[:type]}"] + klass << options[:klass] || '' + + template.content_tag(:div, class: klass) do + template.content_tag(:button, template.raw('×'), :type => 'button', class: 'close', 'data-dismiss' => 'alert') + buffer + end + end + + end + end +end \ No newline at end of file diff --git a/lib/bootstrap-helper/helpers.rb b/lib/bootstrap-helper/helpers.rb index 1419a76..7aa58ce 100644 --- a/lib/bootstrap-helper/helpers.rb +++ b/lib/bootstrap-helper/helpers.rb @@ -6,11 +6,13 @@ module Helpers autoload :Link, 'bootstrap-helper/helpers/link' autoload :Table, 'bootstrap-helper/helpers/table' autoload :Buttons, 'bootstrap-helper/helpers/buttons' + autoload :Alert, 'bootstrap-helper/helpers/alert' include Navbar include Tabs include Table include Modal include Link include Buttons + include Alert end end \ No newline at end of file diff --git a/lib/bootstrap-helper/helpers/alert.rb b/lib/bootstrap-helper/helpers/alert.rb new file mode 100644 index 0000000..16e2fad --- /dev/null +++ b/lib/bootstrap-helper/helpers/alert.rb @@ -0,0 +1,22 @@ +require "bootstrap-helper/builders/alert" +module BootstrapHelper + module Helpers + module Alert + def bt_alert(options = {}, &proc) + ::BootstrapHelper::Builders::Alert.new(self,options,&proc) + end + def bt_alert_success(options = {}, &proc) + bt_alert(options.merge(type: 'success'), &proc) + end + def bt_alert_error(options = {}, &proc) + bt_alert(options.merge(type: 'error'), &proc) + end + def bt_alert_warning(options = {}, &proc) + bt_alert(options.merge(type: 'block'), &proc) + end + def bt_alert_info(options = {}, &proc) + bt_alert(options.merge(type: 'info'), &proc) + end + end + end +end \ No newline at end of file From 61d90a50a772d737d49d5a92161c49c5908a170d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mich=C3=A8le=20Marais?= Date: Fri, 17 May 2013 17:18:12 +0200 Subject: [PATCH 12/16] adding class to a nav --- lib/bootstrap-helper/builders/navbar.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/bootstrap-helper/builders/navbar.rb b/lib/bootstrap-helper/builders/navbar.rb index 59034a9..e0543db 100644 --- a/lib/bootstrap-helper/builders/navbar.rb +++ b/lib/bootstrap-helper/builders/navbar.rb @@ -34,9 +34,11 @@ def nav(options = {}, &block) klass = ['nav'] klass << 'pull-right' if options[:right] klass << 'pull-left' if options[:left] + klass_ul = ['nav'] + klass_ul << options[:class] || '' template.content_tag( :nav, class: klass ) do - template.content_tag( :ul, buffer, class: 'nav') + template.content_tag( :ul, buffer, class: klass_ul) end end @@ -101,7 +103,7 @@ def item(*args, &block) end def collapse - template.link_to nil, :class => 'btn btn-navbar collapsed', "data-toggle" => 'collapse', 'data-target' => '.nav-collapse' do + template.content_tag(:button, nil, :class => 'btn btn-navbar collapsed', "data-toggle" => 'collapse', 'data-target' => '.nav-collapse') do 3.times.map { template.content_tag :span, nil, class: 'icon-bar' }.inject(:+) end end From 5895328dbf233270bdc00be2e980c3535da61721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mich=C3=A8le=20Marais?= Date: Thu, 23 May 2013 10:03:43 +0200 Subject: [PATCH 13/16] added collapse to tabs --- lib/bootstrap-helper/builders/tabs.rb | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/bootstrap-helper/builders/tabs.rb b/lib/bootstrap-helper/builders/tabs.rb index d1522d3..fff6df4 100644 --- a/lib/bootstrap-helper/builders/tabs.rb +++ b/lib/bootstrap-helper/builders/tabs.rb @@ -14,13 +14,18 @@ def render(options, &proc) end def wrapper(options, buffer) + klass = options[:class] || 'nav-collapse' + template.content_tag( :div, class: "tabbable" ) do - content = tabs_titles do - content_items = ''.html_safe - items.each do |item| - content_items << item_title( item[:name], item[:id], item[:klass] ) + content = template.content_tag( :div, :class => 'navbar' ) do + content_div = collapse({:class => klass}) + content_div << tabs_titles({:class => klass}) do + content_items = ''.html_safe + items.each do |item| + content_items << item_title( item[:name], item[:id], item[:klass] ) + end + content_items end - content_items end content << template.content_tag( :div, class: "tab-content" ) do @@ -28,10 +33,16 @@ def wrapper(options, buffer) end end end - + + def collapse(options = {}) + template.content_tag(:button, nil, :class => 'btn btn-navbar', "data-toggle" => 'collapse', 'data-target' => ".#{options[:class]}") do + 3.times.map { template.content_tag :span, nil, class: 'icon-bar' }.inject(:+) + end + end + def tabs_titles(options = {}, &block) buffer = template.capture( self, &proc ) - template.content_tag( :ul, buffer, class: "nav nav-tabs" ) + template.content_tag( :ul, buffer, class: "nav nav-tabs #{options[:class]} collapse" ) end def item_title(name, id, klass) From 25a8ad46ad4a429e9d500d636639ad82dc0e5285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mich=C3=A8le=20Marais?= Date: Thu, 23 May 2013 16:56:14 +0200 Subject: [PATCH 14/16] added type to button collapse --- lib/bootstrap-helper/builders/tabs.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bootstrap-helper/builders/tabs.rb b/lib/bootstrap-helper/builders/tabs.rb index fff6df4..aa3d2be 100644 --- a/lib/bootstrap-helper/builders/tabs.rb +++ b/lib/bootstrap-helper/builders/tabs.rb @@ -35,7 +35,7 @@ def wrapper(options, buffer) end def collapse(options = {}) - template.content_tag(:button, nil, :class => 'btn btn-navbar', "data-toggle" => 'collapse', 'data-target' => ".#{options[:class]}") do + template.content_tag(:button, nil, :class => 'btn btn-navbar', "data-toggle" => 'collapse', 'data-target' => ".#{options[:class]}", :type => 'button') do 3.times.map { template.content_tag :span, nil, class: 'icon-bar' }.inject(:+) end end From 07a88002b4c5d45eff5ce70a0812448969097d6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mich=C3=A8le=20Marais?= Date: Thu, 6 Jun 2013 16:37:13 +0200 Subject: [PATCH 15/16] tabs : adding a class to item --- lib/bootstrap-helper/builders/tabs.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/bootstrap-helper/builders/tabs.rb b/lib/bootstrap-helper/builders/tabs.rb index aa3d2be..af3bcc3 100644 --- a/lib/bootstrap-helper/builders/tabs.rb +++ b/lib/bootstrap-helper/builders/tabs.rb @@ -53,6 +53,8 @@ def item_title(name, id, klass) def item(name, options = {}, &block) klass = options[:active] ? "active" : "" + klass += " #{options[:class]}" unless options[:class].nil? + id = name.downcase.parameterize.gsub(/-/, '_') items << { :name => name, :id => id, :klass => klass } From 6f7a3311daf060bc3cd9d6e80f8404750529bffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mich=C3=A8le=20Marais?= Date: Fri, 7 Jun 2013 15:15:58 +0200 Subject: [PATCH 16/16] tabs : adding title to item --- lib/bootstrap-helper/builders/tabs.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/bootstrap-helper/builders/tabs.rb b/lib/bootstrap-helper/builders/tabs.rb index af3bcc3..ff68151 100644 --- a/lib/bootstrap-helper/builders/tabs.rb +++ b/lib/bootstrap-helper/builders/tabs.rb @@ -22,7 +22,7 @@ def wrapper(options, buffer) content_div << tabs_titles({:class => klass}) do content_items = ''.html_safe items.each do |item| - content_items << item_title( item[:name], item[:id], item[:klass] ) + content_items << item_title( item[:name], item[:id], item[:klass], item[:title] ) end content_items end @@ -45,8 +45,8 @@ def tabs_titles(options = {}, &block) template.content_tag( :ul, buffer, class: "nav nav-tabs #{options[:class]} collapse" ) end - def item_title(name, id, klass) - template.content_tag( :li, nil, class: klass ) do + def item_title(name, id, klass, title) + template.content_tag( :li, nil, class: klass, :title => title ) do template.link_to name, "##{id}", :data => { :toggle => 'tab' } end end @@ -54,10 +54,11 @@ def item_title(name, id, klass) def item(name, options = {}, &block) klass = options[:active] ? "active" : "" klass += " #{options[:class]}" unless options[:class].nil? + title = options[:title] || '' id = name.downcase.parameterize.gsub(/-/, '_') - items << { :name => name, :id => id, :klass => klass } + items << { :name => name, :id => id, :klass => klass, :title => title } buffer = template.capture( self, &proc ) template.content_tag( :div, buffer, class: "tab-pane #{klass}", :id => id )