twitter_bootstrap_builder 0.0.1
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/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/lib/twitter_bootstrap_builder.rb +20 -0
- data/lib/twitter_bootstrap_builder/builders/base.rb +20 -0
- data/lib/twitter_bootstrap_builder/builders/drop_down_link_builder.rb +17 -0
- data/lib/twitter_bootstrap_builder/builders/fieldset_builder.rb +93 -0
- data/lib/twitter_bootstrap_builder/builders/form_builder.rb +11 -0
- data/lib/twitter_bootstrap_builder/builders/link_button_builder.rb +15 -0
- data/lib/twitter_bootstrap_builder/builders/nav_bar_builder.rb +25 -0
- data/lib/twitter_bootstrap_builder/builders/nav_container_builder.rb +35 -0
- data/lib/twitter_bootstrap_builder/builders/nav_list_builder.rb +34 -0
- data/lib/twitter_bootstrap_builder/builders/submit_button_builder.rb +15 -0
- data/lib/twitter_bootstrap_builder/builders/table_builder.rb +78 -0
- data/lib/twitter_bootstrap_builder/engine.rb +16 -0
- data/lib/twitter_bootstrap_builder/helpers/buttons_helper.rb +51 -0
- data/lib/twitter_bootstrap_builder/helpers/commons_helper.rb +95 -0
- data/lib/twitter_bootstrap_builder/version.rb +3 -0
- data/twitter_bootstrap_builder.gemspec +20 -0
- data/vendor/assets/images/glyphicons-halflings-white.png +0 -0
- data/vendor/assets/images/glyphicons-halflings.png +0 -0
- data/vendor/assets/javascripts/bootstrap.js +1836 -0
- data/vendor/assets/stylesheets/bootstrap.css +4914 -0
- data/vendor/assets/stylesheets/twitter_bootstrap_builder.css +29 -0
- metadata +93 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 gabriel
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# TwitterBootstrapBuilder
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'twitter_bootstrap_builder'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install twitter_bootstrap_builder
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'twitter_bootstrap_builder/version'
|
2
|
+
require 'twitter_bootstrap_builder/engine'
|
3
|
+
|
4
|
+
require 'twitter_bootstrap_markup'
|
5
|
+
require 'kaminari'
|
6
|
+
|
7
|
+
require 'twitter_bootstrap_builder/helpers/commons_helper'
|
8
|
+
require 'twitter_bootstrap_builder/helpers/buttons_helper'
|
9
|
+
|
10
|
+
require 'twitter_bootstrap_builder/builders/base'
|
11
|
+
require 'twitter_bootstrap_builder/builders/drop_down_link_builder'
|
12
|
+
require 'twitter_bootstrap_builder/builders/fieldset_builder'
|
13
|
+
require 'twitter_bootstrap_builder/builders/form_builder'
|
14
|
+
require 'twitter_bootstrap_builder/builders/link_button_builder'
|
15
|
+
require 'twitter_bootstrap_builder/builders/nav_bar_builder'
|
16
|
+
require 'twitter_bootstrap_builder/builders/nav_container_builder'
|
17
|
+
require 'twitter_bootstrap_builder/builders/nav_list_builder'
|
18
|
+
require 'twitter_bootstrap_builder/builders/submit_button_builder'
|
19
|
+
require 'twitter_bootstrap_builder/builders/table_builder'
|
20
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module TwitterBootstrapBuilder
|
2
|
+
module Builders
|
3
|
+
class Base
|
4
|
+
include TwitterBootstrapMarkup
|
5
|
+
|
6
|
+
attr_reader :template, :options, :block
|
7
|
+
|
8
|
+
def initialize(template, options={}, &block)
|
9
|
+
@template = template
|
10
|
+
@options = options
|
11
|
+
@block = block
|
12
|
+
end
|
13
|
+
|
14
|
+
def html_safe
|
15
|
+
to_s.html_safe
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module TwitterBootstrapBuilder
|
2
|
+
module Builders
|
3
|
+
class DropDownLinkBuilder < Base
|
4
|
+
|
5
|
+
def to_s
|
6
|
+
dropdown_link = DropdownLink.new(options[:text])
|
7
|
+
dropdown_link.append template.capture(self, &block) if block
|
8
|
+
dropdown_link.as_nav_item.to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
def link_to(*args, &block)
|
12
|
+
Tag.block(:li, template.link_to(*args, &block)).to_s.html_safe
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module TwitterBootstrapBuilder
|
2
|
+
module Builders
|
3
|
+
class FieldsetBuilder < Base
|
4
|
+
|
5
|
+
def to_s
|
6
|
+
fieldset = Tag.block(:fieldset, class: 'form-horizontal')
|
7
|
+
fieldset.append template.capture(self, &block) if block
|
8
|
+
fieldset.to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
def form_builder
|
12
|
+
options[:form_builder]
|
13
|
+
end
|
14
|
+
|
15
|
+
def model
|
16
|
+
options[:model] || form_builder.object
|
17
|
+
end
|
18
|
+
|
19
|
+
def actions(&block)
|
20
|
+
actions = Tag.block(:div, class: 'form-actions')
|
21
|
+
actions.append template.capture(self, &block) if block
|
22
|
+
actions.to_s.html_safe
|
23
|
+
end
|
24
|
+
|
25
|
+
def display_field(method)
|
26
|
+
ControlGroup.new(model.class.human_attribute_name(method)) do |cg|
|
27
|
+
cg.append Tag.block(:span, model.send(method), class: 'display')
|
28
|
+
end.to_s.html_safe
|
29
|
+
end
|
30
|
+
|
31
|
+
def text_field(method, options={})
|
32
|
+
ControlGroup.new(model.class.human_attribute_name(method), for: "#{form_builder.object_name}_#{method}") do |cg|
|
33
|
+
cg.append form_builder.text_field(method, options)
|
34
|
+
end.to_s.html_safe
|
35
|
+
end
|
36
|
+
|
37
|
+
TwitterBootstrapMarkup::InputSize::VALUES.each do |size|
|
38
|
+
define_method "text_field_#{size}" do |method, options={}|
|
39
|
+
ControlGroup.new(model.class.human_attribute_name(method), for: "#{form_builder.object_name}_#{method}") do |cg|
|
40
|
+
options.append!(:class, "input-#{size}")
|
41
|
+
cg.append form_builder.text_field(method, options)
|
42
|
+
end.to_s.html_safe
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def text_area(method, options={})
|
47
|
+
ControlGroup.new(model.class.human_attribute_name(method), for: "#{form_builder.object_name}_#{method}") do |cg|
|
48
|
+
cg.append form_builder.text_area(method, options)
|
49
|
+
end.to_s.html_safe
|
50
|
+
end
|
51
|
+
|
52
|
+
TwitterBootstrapMarkup::InputSize::VALUES.each do |size|
|
53
|
+
define_method "text_area_#{size}" do |method, options={}|
|
54
|
+
ControlGroup.new(model.class.human_attribute_name(method), for: "#{form_builder.object_name}_#{method}") do |cg|
|
55
|
+
options.append!(:class, "input-#{size}")
|
56
|
+
cg.append form_builder.text_area(method, options)
|
57
|
+
end.to_s.html_safe
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def email_field(method, options={})
|
62
|
+
ControlGroup.new(model.class.human_attribute_name(method), for: "#{form_builder.object_name}_#{method}") do |cg|
|
63
|
+
cg.append form_builder.email_field(method, options)
|
64
|
+
end.to_s.html_safe
|
65
|
+
end
|
66
|
+
|
67
|
+
def password_field(method, options={})
|
68
|
+
ControlGroup.new(model.class.human_attribute_name(method), for: "#{form_builder.object_name}_#{method}") do |cg|
|
69
|
+
cg.append form_builder.password_field(method, options)
|
70
|
+
end.to_s.html_safe
|
71
|
+
end
|
72
|
+
|
73
|
+
def hidden_field(method, options={})
|
74
|
+
ControlGroup.new(model.class.human_attribute_name(method), for: "#{form_builder.object_name}_#{method}") do |cg|
|
75
|
+
cg.append form_builder.hidden_field(method, options)
|
76
|
+
end.to_s.html_safe
|
77
|
+
end
|
78
|
+
|
79
|
+
def select(method, choices, options={}, html_options={})
|
80
|
+
ControlGroup.new(model.class.human_attribute_name(method), for: "#{form_builder.object_name}_#{method}") do |cg|
|
81
|
+
cg.append form_builder.select(method, choices, options, html_options)
|
82
|
+
end.to_s.html_safe
|
83
|
+
end
|
84
|
+
|
85
|
+
def custom_field(label, options={}, &block)
|
86
|
+
ControlGroup.new(label, options) do |cg|
|
87
|
+
cg.append template.capture(self, &block) if block
|
88
|
+
end.to_s.html_safe
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module TwitterBootstrapBuilder
|
2
|
+
module Builders
|
3
|
+
class LinkButtonBuilder < Base
|
4
|
+
|
5
|
+
def to_s
|
6
|
+
link_button = block ? LinkButton.new(*options[:args], &Proc.new {}) : LinkButton.new(*options[:args])
|
7
|
+
link_button.send(options[:type]) if options[:type]
|
8
|
+
link_button.send(options[:size]) if options[:size]
|
9
|
+
link_button.append template.capture(self, &block) if block
|
10
|
+
link_button.to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module TwitterBootstrapBuilder
|
2
|
+
module Builders
|
3
|
+
class NavBarBuilder < Base
|
4
|
+
|
5
|
+
def to_s
|
6
|
+
nav_bar = NavBar.top
|
7
|
+
nav_bar.append template.capture(self, &block) if block
|
8
|
+
nav_bar.to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
def brand(title, url)
|
12
|
+
Brand.new(title, url).to_s.html_safe
|
13
|
+
end
|
14
|
+
|
15
|
+
def container(&block)
|
16
|
+
NavContainerBuilder.new(template, &block).html_safe
|
17
|
+
end
|
18
|
+
|
19
|
+
def container_right(&block)
|
20
|
+
NavContainerBuilder.new(template, align: :right, &block).html_safe
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module TwitterBootstrapBuilder
|
2
|
+
module Builders
|
3
|
+
class NavContainerBuilder < Base
|
4
|
+
|
5
|
+
def to_s
|
6
|
+
nav_container = NavContainer.new
|
7
|
+
nav_container.pull_right if options[:align] == :right
|
8
|
+
nav_container.append template.capture(self, &block) if block
|
9
|
+
nav_container.to_s
|
10
|
+
end
|
11
|
+
|
12
|
+
def link_to(*args, &block)
|
13
|
+
options = args.select { |a| a.is_a?(Hash) }.first || {}
|
14
|
+
if options[:active_if].is_a?(Proc) ? options[:active_if].call : options[:active_if]
|
15
|
+
active_link_to(*args, &block)
|
16
|
+
else
|
17
|
+
Tag.block(:li, template.link_to(*args, &block)).to_s.html_safe
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def active_link_to(*args, &block)
|
22
|
+
Tag.block(:li, template.link_to(*args, &block), class: 'active').to_s.html_safe
|
23
|
+
end
|
24
|
+
|
25
|
+
def divider
|
26
|
+
Tag.block(:li, Divider.vertical).to_s.html_safe
|
27
|
+
end
|
28
|
+
|
29
|
+
def dropdown_link(text, &block)
|
30
|
+
Tag.block(:li, DropDownLinkBuilder.new(template, text: text, &block).html_safe).to_s.html_safe
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module TwitterBootstrapBuilder
|
2
|
+
module Builders
|
3
|
+
class NavListBuilder < Base
|
4
|
+
|
5
|
+
def to_s
|
6
|
+
nav_list = NavList.new
|
7
|
+
nav_list.append template.capture(self, &block) if block
|
8
|
+
nav_list.to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
def header(text)
|
12
|
+
NavHeader.new(text).to_s.html_safe
|
13
|
+
end
|
14
|
+
|
15
|
+
def link_to(*args, &block)
|
16
|
+
options = args.select { |a| a.is_a?(Hash) }.first || {}
|
17
|
+
if options[:active_if].is_a?(Proc) ? options[:active_if].call : options[:active_if]
|
18
|
+
active_link_to(*args, &block)
|
19
|
+
else
|
20
|
+
Tag.block(:li, template.link_to(*args, &block)).to_s.html_safe
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def active_link_to(*args, &block)
|
25
|
+
Tag.block(:li, template.link_to(*args, &block), class: 'active').to_s.html_safe
|
26
|
+
end
|
27
|
+
|
28
|
+
def divider
|
29
|
+
Tag.block(:li, Divider.vertical).to_s.html_safe
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module TwitterBootstrapBuilder
|
2
|
+
module Builders
|
3
|
+
class SubmitButtonBuilder < Base
|
4
|
+
|
5
|
+
def to_s
|
6
|
+
submit = block ? Submit.new(*options[:args], &Proc.new {}) : Submit.new(*options[:args])
|
7
|
+
submit.send(options[:type]) if options[:type]
|
8
|
+
submit.send(options[:size]) if options[:size]
|
9
|
+
submit.append template.capture(self, &block) if block
|
10
|
+
submit.to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module TwitterBootstrapBuilder
|
2
|
+
module Builders
|
3
|
+
class TableBuilder < Base
|
4
|
+
|
5
|
+
def initialize(*args, &block)
|
6
|
+
super
|
7
|
+
@fields = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
template.capture(self, &block) if block
|
12
|
+
|
13
|
+
Tag.block(:div, class: 'table-container') do |data|
|
14
|
+
data.append do |d|
|
15
|
+
Tag.block(:table, class: 'table table-striped table-condensed') do |table|
|
16
|
+
table.append thead
|
17
|
+
table.append tbody
|
18
|
+
end
|
19
|
+
end
|
20
|
+
data.append pager
|
21
|
+
end.to_s.html_safe
|
22
|
+
end
|
23
|
+
|
24
|
+
def collection
|
25
|
+
options[:collection]
|
26
|
+
end
|
27
|
+
|
28
|
+
def model_class
|
29
|
+
options[:model_class] || collection.klass
|
30
|
+
end
|
31
|
+
|
32
|
+
def field(method)
|
33
|
+
@fields << method
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
|
37
|
+
def actions(&block)
|
38
|
+
@actions_block = block
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def thead
|
45
|
+
Tag.block(:thead) do |thead|
|
46
|
+
thead.append do |h|
|
47
|
+
Tag.block(:tr) do |tr|
|
48
|
+
tr.append Tag.block(:th, class: 'span2')
|
49
|
+
@fields.each do |field|
|
50
|
+
tr.append Tag.block(:th, model_class.human_attribute_name(field))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def tbody
|
58
|
+
Tag.block(:tbody) do |tbody|
|
59
|
+
collection.each do |model|
|
60
|
+
tbody.append do |b|
|
61
|
+
Tag.block(:tr) do |tr|
|
62
|
+
tr.append Tag.block(:td, template.capture(model, &@actions_block))
|
63
|
+
@fields.each do |field|
|
64
|
+
tr.append Tag.block(:td, model.send(field))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def pager
|
73
|
+
Tag.new(:div, template.paginate(collection)).pull_right if collection.respond_to?(:current_page)
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|