Skip to content

Commit 61dfd27

Browse files
committed
buttons
1 parent ab9153c commit 61dfd27

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

README.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,20 @@ gem 'bootstrap-helper',git: 'git://github.com/niedhui/bootstrap-helper.git'
2626
%textarea#remark_field{style:"width: 95%"}
2727
= m.footer do
2828
= primary_link_to "确定","#"
29-
```
29+
```
30+
31+
# table
32+
```ruby
33+
- bt_table users do |table|
34+
= table.ths "email","name"
35+
= table.tds :email, ->(user) { user.first_name+ user.last_name}
36+
```
37+
38+
# buttons
39+
```ruby
40+
- bt_button_group "Actions" do
41+
%li= link_to "hello", hello_path
42+
%li= link_to "bye", bye_path
43+
%li.divider
44+
%li= link_to "nihao"
45+
```
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# encoding: utf-8
2+
# TODO: better doc, tr_class
3+
module BootstrapHelper
4+
module Builders
5+
class Buttons
6+
attr_accessor :template
7+
delegate :content_tag, :link_to, :to => :template
8+
9+
def initialize(template,title, options = {}, &proc)
10+
@template, @title = template, title
11+
render(options, &proc)
12+
end
13+
14+
def render(options, &proc)
15+
buffer = template.capture(self, &proc)
16+
template.concat wrapper(options,buffer)
17+
end
18+
19+
def wrapper(options ,buffer)
20+
content_tag :div, class: 'btn-group' do
21+
sub_buffer = link_to "#",class: 'btn dropdown-toggle','data-toggle' => "dropdown" do
22+
@title.html_safe << content_tag(:span,"",class: "caret")
23+
end
24+
sub_buffer << content_tag(:ul,buffer,class: "dropdown-menu")
25+
end
26+
end
27+
end
28+
end
29+
end
30+

lib/bootstrap-helper/helpers.rb

+2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ module Helpers
44
autoload :Modal, 'bootstrap-helper/helpers/modal'
55
autoload :Link, 'bootstrap-helper/helpers/link'
66
autoload :Table, 'bootstrap-helper/helpers/table'
7+
autoload :Buttons, 'bootstrap-helper/helpers/buttons'
78
include Navbar
89
include Table
910
include Modal
1011
include Link
12+
include Buttons
1113
end
1214
end
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require "bootstrap-helper/builders/buttons"
2+
module BootstrapHelper
3+
module Helpers
4+
module Buttons
5+
def bt_button_group(title , options = {},&proc)
6+
::BootstrapHelper::Builders::Buttons.new(self,title,options,&proc)
7+
end
8+
9+
end
10+
end
11+
end

0 commit comments

Comments
 (0)