Module: HtmlHelper
- Defined in:
- app/helpers/html_helper.rb
Instance Method Summary collapse
- #bootstrap_class_for(flash_type) ⇒ Object
- #code_block(&block) ⇒ Object
- #flash_messages(opts = {}) ⇒ Object
- #html_tag(options = {}, &block) ⇒ Object
- #random_avatar(size = 64, css_class) ⇒ Object
- #random_landscape(width = '100%', css_class = '') ⇒ Object
- #random_landscape_name ⇒ Object
Instance Method Details
#bootstrap_class_for(flash_type) ⇒ Object
34 35 36 |
# File 'app/helpers/html_helper.rb', line 34 def bootstrap_class_for flash_type { success: "alert-success", error: "alert-danger", alert: "alert-warning", notice: "alert-info" }[flash_type.to_sym] || flash_type.to_s end |
#code_block(&block) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'app/helpers/html_helper.rb', line 24 def code_block(&block) code = capture(&block) indent = code.scan(/^ +/).first.size code.gsub!(/^ {#{indent}}/, "") code.chomp! content_tag :pre, code, :class => "prettyprint linenums" end |
#flash_messages(opts = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/helpers/html_helper.rb', line 38 def (opts = {}) flash.each do |msg_type, | concat(content_tag(:div, , class: "alert #{bootstrap_class_for(msg_type)} alert-dismissible fade show", role: 'alert') do concat(content_tag(:button, class: 'close', data: { dismiss: 'alert' }, 'aria-label' => "Close" ) do concat content_tag(:span, '×'.html_safe, 'aria-hidden' => true) end) case when bootstrap_class_for(msg_type) == "alert-success" concat content_tag(:span, '<i class="fa fa-check-circle"></i>'.html_safe, 'aria-hidden' => true) when bootstrap_class_for(msg_type) == ("alert-danger" || "alert-warning") concat content_tag(:span, '<i class="fa fa-times-circle"></i>'.html_safe, 'aria-hidden' => true) else concat content_tag(:span, '<i class="fa fa-info-circle"></i>'.html_safe, 'aria-hidden' => true) end concat " " + end) end nil end |
#html_tag(options = {}, &block) ⇒ Object
2 3 4 5 6 7 8 |
# File 'app/helpers/html_helper.rb', line 2 def html_tag(={}, &block) custom_class = [:class] ? ' ' + [:class] : '' raw "" + tag(:html, , true) + capture(&block) + "</html>" end |
#random_avatar(size = 64, css_class) ⇒ Object
10 11 12 13 |
# File 'app/helpers/html_helper.rb', line 10 def random_avatar size=64, css_class value = (rand() * 4 + 1).to_i image_tag "kiso_themes/stock/#{value}.jpg", class: css_class, width: size, height: size, 'data-turbolinks-permanent': true end |
#random_landscape(width = '100%', css_class = '') ⇒ Object
15 16 17 |
# File 'app/helpers/html_helper.rb', line 15 def random_landscape width='100%', css_class='' image_tag random_landscape_name, class: css_class, width: width end |
#random_landscape_name ⇒ Object
19 20 21 22 |
# File 'app/helpers/html_helper.rb', line 19 def random_landscape_name value = (rand() * 10 + 1).to_i "kiso_themes/stock/landscape_#{value}.jpg" end |