Class: BootstrapHamlHelpers::Components::ProgressBar

Inherits:
BootstrapHamlHelpers::Component::Base show all
Defined in:
app/models/bootstrap_haml_helpers/components/progress_bar.rb

Instance Attribute Summary

Attributes inherited from BootstrapHamlHelpers::Component::Base

#attributes, #component_options, #content, #content_block, #content_string, #controller, #output_buffer

Instance Method Summary collapse

Methods inherited from BootstrapHamlHelpers::Component::Base

#add_attribute, #add_attributes, #block_or_string_content, build, #build, #content_type, init_context, teardown_context, #view_context, view_context, #view_context=, view_context=

Methods included from BootstrapHamlHelpers::Component::InheritableTraits

included

Constructor Details

#initialize(options = {}, &block) ⇒ ProgressBar



6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/models/bootstrap_haml_helpers/components/progress_bar.rb', line 6

def initialize(options = {}, &block)
  striped = options.delete(:striped)
  animated = options.delete(:animated)
  type = options.delete(:type)

  super(options, &block)

  add_attribute(:class, "progress-striped") if striped
  add_attribute(:class, "progress-striped active") if animated
  add_attribute(:class, "progress-#{type}") if type

end

Instance Method Details

#bar(percentage, *args, &block) ⇒ Object



19
20
21
22
23
24
25
# File 'app/models/bootstrap_haml_helpers/components/progress_bar.rb', line 19

def bar(percentage, *args, &block)
  options = args.extract_options!

  type = options.delete(:type)
  type_string = " bar-#{type}" if type
  view_context.(:div, nil, class: "bar#{type_string}", style: "width: #{percentage}%")
end