Sha256: 0b34057b93a7df788c81806040cd8e887dfff7fa32da9cb16170d04e3a23a053
Contents?: true
Size: 1.61 KB
Versions: 1
Compression:
Stored size: 1.61 KB
Contents
# Rails helper for producing Twitter Bootstrap labels. We use +#stamp()+ because +#label()+ is # a standard Rails helper method. # # See: http://twitter.github.io/bootstrap/components.html#labels-badges # # @example # stamp('Default') # stamp('Info', :info) # stamp('Warning', :warning, id: 'warn-id', class: 'more-class', my_key: 'my_value') # module Bootstrap::StampHelper InvalidStampTypeError = Class.new(StandardError) LABEL_TYPES = %w(default primary success info warning danger) #=> see {Bootstrap::StampHelper::LABEL_TYPES} # Returns a Bootstrap label # # @overload stamp(text, options={}) # Returns a label of type :default # @param [String] text text of the label # @param [Hash] options html attributes for returned <span> # @overload stamp(text, type, options={}) # Returns a label of type _type_ # @param [String] text text of the label # @param [Symbol, String] type type of label see {Bootstrap::StampHelper::LABEL_TYPES} # @param [Hash] options html attributes for returned <span> # @return [String] def stamp(*args) text = args.shift options = add_label_classes(*args) content_tag(:span, text, options) end private def add_label_classes(*args) options = canonicalize_options(args.extract_options!) validate_label_types(args) classes = ['label'] + args.map { |arg| "label-#{arg}" } classes << 'label-default' if classes == ['label'] ensure_class(options, classes) end def validate_label_types(label_types) label_types.each { |e| raise(InvalidStampTypeError, e.inspect) unless LABEL_TYPES.include?(e.to_s) } end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
bootstrap-view-helpers-0.0.14 | app/helpers/bootstrap/stamp_helper.rb |