Sha256: 2332b3ed400740c24aca4eb98858f781a350decedbfe700717acefe4474f4459

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

module Twitter::Bootstrap::Markup::Rails::Components
  class ProgressBar < Base
    attr_accessor :width

    def initialize(width, options = {})
      super
      @width = width
    end

    def to_s
      output_buffer << content_tag(:div, build_div_options) do
        build_bar_tag.html_safe
      end.html_safe
      super
    end

    private

    def default_options
      {
        :class        => 'progress',
        :type         => [],
        :html_options => {}
      }
    end

    def build_bar_tag
      ops = { :class => 'bar', :style => "width: #{width}%;" }
      content_tag(:div, nil, ops)
    end

    def build_div_options
      ops = { :class => build_class }
      ops.reverse_merge(options[:html_options])
    end

    def build_class
      classes = [options[:class]]

      if options[:type].is_a?(Array)
        classes = classes | options[:type].map { |c| "progress-#{c.to_s}" }
      else
        classes << "progress-#{options[:type]}"
      end

      classes << "active" if options[:active]

      classes.join(" ")
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
twitter-bootstrap-markup-rails-0.3.2.2 lib/twitter-bootstrap-markup-rails/components/progress_bar.rb
twitter-bootstrap-markup-rails-0.3.2.1 lib/twitter-bootstrap-markup-rails/components/progress_bar.rb
twitter-bootstrap-markup-rails-0.3.2 lib/twitter-bootstrap-markup-rails/components/progress_bar.rb
twitter-bootstrap-markup-rails-0.3.1 lib/twitter-bootstrap-markup-rails/components/progress_bar.rb