forked from pusewicz/twitter-bootstrap-markup-rails
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
144 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module Twitter::Bootstrap::Markup::Rails::Components | ||
class Badge < Base | ||
attr_reader :message | ||
|
||
def initialize(message, options = {}) | ||
super | ||
@message = message | ||
end | ||
|
||
def to_s | ||
output_buffer << content_tag(:span, message, build_tag_options).html_safe | ||
super | ||
end | ||
|
||
private | ||
def default_options | ||
{ | ||
:class => "badge", | ||
:class_prefix => "badge-", | ||
:type => nil, | ||
:html_options => {} | ||
} | ||
end | ||
|
||
def build_class | ||
classes = [options[:class]] | ||
classes << "#{options[:class_prefix]}#{options[:type]}" if options[:type] | ||
classes.join(" ") | ||
end | ||
|
||
def build_tag_options | ||
ops = {:class => build_class} | ||
ops.reverse_merge(options[:html_options]) | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module Twitter::Bootstrap::Markup::Rails::Components | ||
class Icon < Base | ||
|
||
def initialize(options = {}) | ||
super | ||
end | ||
|
||
def to_s | ||
output_buffer << content_tag(:i, nil, build_tag_options).html_safe | ||
super | ||
end | ||
|
||
private | ||
def default_options | ||
{ | ||
:class => nil, | ||
:class_prefix => "icon-", | ||
:color => :black, | ||
:name => nil, | ||
:html_options => {} | ||
} | ||
end | ||
|
||
def build_class | ||
klass = [ options[:class] ] | ||
klass << "#{options[:class_prefix]}#{options[:name]}" if options[:name] | ||
klass << " icon-white" unless options[:color].equal?(:black) | ||
classes.join(" ") | ||
end | ||
|
||
def build_tag_options | ||
ops = {:class => build_class} | ||
ops.reverse_merge(options[:html_options]) | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
lib/twitter-bootstrap-markup-rails/helpers/badge_helpers.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# encoding: utf-8 | ||
module Twitter::Bootstrap::Markup::Rails::Helpers | ||
module BadgeHelpers | ||
# Renders badge | ||
# | ||
# @param [String] message message to be displayed | ||
# @param [Hash] options hash containing options (default: {}): | ||
# :type - The String type of alert to display: success warning important notice | ||
# :html_options - Any additional options you'd like to pass to the span tag that will be created | ||
# for this label (for instance :"data-whatever" can be specified in :html_options). | ||
# | ||
# Examples | ||
# | ||
# bootstrap_badge_tag("Hello!") | ||
# # => '<span class="badge">Hello!</span>' | ||
# | ||
# Returns HTML String for the label | ||
def bootstrap_badge_tag(message, options = {}) | ||
Twitter::Bootstrap::Markup::Rails::Components::Badge.new( | ||
message, | ||
options | ||
).to_s | ||
end | ||
|
||
%w(success warning important notice).each do |type| | ||
module_eval <<-EOF | ||
def bootstrap_badge_#{type}_tag(message, options = {}) | ||
bootstrap_badge_tag(message, options.merge({ :type => "#{type}" })) | ||
end | ||
EOF | ||
end | ||
end | ||
end | ||
|
26 changes: 26 additions & 0 deletions
26
lib/twitter-bootstrap-markup-rails/helpers/icon_helpers.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# encoding: utf-8 | ||
module Twitter::Bootstrap::Markup::Rails::Helpers | ||
module IconHelpers | ||
# Renders badge | ||
# | ||
# @param [String] message message to be displayed | ||
# @param [Hash] options hash containing options (default: {}): | ||
# :type - The String type of alert to display: success warning important notice | ||
# :html_options - Any additional options you'd like to pass to the span tag that will be created | ||
# for this label (for instance :"data-whatever" can be specified in :html_options). | ||
# | ||
# Examples | ||
# | ||
# bootstrap_icon_tag(:name => 'user', :color => :white) | ||
# # => '<i class="icon-user icon-white"></i>' | ||
# | ||
# Returns HTML String for the label | ||
def bootstrap_icon_tag(options = {}) | ||
Twitter::Bootstrap::Markup::Rails::Components::Icon.new( | ||
options | ||
).to_s | ||
end | ||
|
||
end | ||
end | ||
|