Module: Workbench::StyleHelper

Defined in:
app/helpers/workbench/style_helper.rb

Overview

Helpers that add/wrap information in CSS/SCSS, or are related to adding attributes to CSS. Also includes 'data-' related functionality.

Instance Method Summary (collapse)

Instance Method Details

- (Object) attribute_block(hash)



45
46
47
# File 'app/helpers/workbench/style_helper.rb', line 45

def attribute_block(hash)
  hash.collect{|label, content| attribute_tag(label, content)}.join.html_safe
end

- (Object) attribute_tag(label, content)



38
39
40
41
42
43
# File 'app/helpers/workbench/style_helper.rb', line 38

def attribute_tag(label, content)
  (:p) do
    (:strong, label) + ' ' +
      data_tag(content)
  end
end

- (Object) collapsed_css_property_if(tru)



15
16
17
# File 'app/helpers/workbench/style_helper.rb', line 15

def collapsed_css_property_if(tru)
  tru ? 'collapsed'.html_safe : nil
end

- (Object) color_tag(css_color = nil, value)

TODO: make the color an attribute and apply it after, give a border



50
51
52
53
# File 'app/helpers/workbench/style_helper.rb', line 50

def color_tag(css_color = nil, value)
  return value if css_color.nil?
  (:span, value, style: "background-color: #{css_color};")
end

- (String) data_tag(content)

Wrap content in a span, and give it a :data class

Returns:

  • (String)


34
35
36
# File 'app/helpers/workbench/style_helper.rb', line 34

def data_tag(content)
  (:span, content, class: :data)
end

- (Object) hidden_css_property_if(tru)



11
12
13
# File 'app/helpers/workbench/style_helper.rb', line 11

def hidden_css_property_if(tru)
  tru ? 'hidden'.html_safe : nil
end

- (Object) scrollable_div_tag(text)



6
7
8
9
# File 'app/helpers/workbench/style_helper.rb', line 6

def scrollable_div_tag(text)
  return nil if text.blank?
  (:div, text, class: 'scrollable_div one_third')
end

- (Object) toggle_class_css(css_class, boolean)



24
25
26
27
28
29
30
# File 'app/helpers/workbench/style_helper.rb', line 24

def toggle_class_css(css_class, boolean)
  if boolean
    css_class
  else
    nil
  end
end

Set @no_turbolinks in a before_action, then use the method in, say a layout.



20
21
22
# File 'app/helpers/workbench/style_helper.rb', line 20

def turbolinks_off_tag
  'data-no-turbolink="true"'.html_safe if @no_turbolinks
end