Module: RailsViewHelpers::HtmlHelper

Defined in:
app/helpers/rails_view_helpers/html_helper.rb

Instance Method Summary collapse

Instance Method Details

#bln(bool, true_string = "✔".html_safe, false_string = nbsp) ⇒ Object

Displays a check-mark (✔) when bln is true else nbsp.

Examples:

bln(true)                         #=> "✔"  (check mark)
bln(false)                        #=> " "    (space)
bln(true, 'Admin')                #=> "Admin"
bln(false, 'Admin', "not Admin")  #=> "not Admin"

Parameters:

  • bool (Boolean)
  • true_string (String) (defaults to: "✔".html_safe)

    the string to display if bln is true. Caller is responsible for escaping and/or marking html_safe.

  • false_string (String) (defaults to: nbsp)

    the string to display if bln is false. Caller is responsible for escaping and/or marking html_safe.



35
36
37
38
39
40
41
# File 'app/helpers/rails_view_helpers/html_helper.rb', line 35

def bln(bool, true_string="✔".html_safe, false_string=nbsp)
  if bool
    true_string
  else
    false_string
  end
end

#body_tag(options = {}, &block) ⇒ String

Includes controller and action name as data attributes.

Examples:

body_tag()  #=> <body data-action='index' data-controller='home'>

body_tag(id: 'my-id', class: 'my-class')  #=> <body class="my-class" data-action="index" data-controller="home" id="my-id">

Parameters:

  • options (Hash) (defaults to: {})

    become attributes of the BODY tag

Returns:

  • (String)


13
14
15
16
17
18
19
20
21
22
23
# File 'app/helpers/rails_view_helpers/html_helper.rb', line 13

def body_tag(options={}, &block)
  options = canonicalize_options(options)
  options.delete(:class) if options[:class].blank?
  options[:data] ||= {}
  options[:data][:controller] = controller.controller_name
  options[:data][:action] = controller.action_name
  
  (:body, options) do
    yield
  end
end

#nbsp(count = 1) ⇒ String

Returns one or more non-breaking spaces (&nbsp;) marked html_safe.

Examples:

nbsp      #=> "&nbsp;"
nbsp(3)   #=> "&nbsp;&nbsp;&nbsp;"

Parameters:

  • count (FixNum) (defaults to: 1)

    the number of non-breaking spaces to return

Returns:

  • (String)

    that is html_safe



74
75
76
# File 'app/helpers/rails_view_helpers/html_helper.rb', line 74

def nbsp(count=1)
  ('&nbsp;' * count).html_safe
end

#td_bln(*args) ⇒ String

Same as bln but wrapped in a TD and centered (w/rail_view_helper.css)

Examples:

td_bln(true)  #=> <td class="c">&#10004;</td>

Returns:

  • (String)


48
49
50
51
52
53
# File 'app/helpers/rails_view_helpers/html_helper.rb', line 48

def td_bln(*args)
  options = canonicalize_options(args.extract_options!)
  options = ensure_class(options, 'c')
  
  (:td, bln(*args), options)
end

#th_actions(*args) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'app/helpers/rails_view_helpers/html_helper.rb', line 56

def th_actions(*args)
  options = canonicalize_options(args.extract_options!)
  colspan = args.shift || 1
  text = args.shift || 'Actions'
  options[:colspan] = colspan
  options[:class] = 'c' if options[:class].empty?
  
  (:th, text, options)
end