Module: ApplicationHelper
- Defined in:
- lib/r5/template/config/initializers/html_helpers.rb
Instance Method Summary collapse
- #c_num(number, precision = 2, skip_zero = false) ⇒ Object
- #delete_button(objekt, text) ⇒ Object
- #dropdown_menu(name, test, &block) ⇒ Object
-
#lf(date, options = {}) ⇒ Object
same as I18n.l() but ignores nil.
- #menu_item(name, url, test) ⇒ Object
- #num(number, options = {:precision=>2}) ⇒ Object
- #num0(number, skip_zero = false) ⇒ Object
- #num2(number, skip_zero = false) ⇒ Object
- #num3(number, skip_zero = false) ⇒ Object
- #num_warn(condition) ⇒ Object
- #numx(number, precision = 3, skip_zero = false) ⇒ Object
- #records_filter ⇒ Object
- #session_debug ⇒ Object
-
#shorten(text, length = 20) ⇒ Object
make long text short with ‘…’.
- #t_header(name) ⇒ Object
-
#yes_no_select ⇒ Object
selecting - yes, no, nil.
Instance Method Details
#c_num(number, precision = 2, skip_zero = false) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/r5/template/config/initializers/html_helpers.rb', line 63 def c_num number, precision=2, skip_zero=false return '' if skip_zero && number==0 return number unless number.is_a? Float number_with_precision( number, :precision=>precision, :delimiter => ' ') # c_number_with_precision( number, precision ) end |
#delete_button(objekt, text) ⇒ Object
88 89 90 |
# File 'lib/r5/template/config/initializers/html_helpers.rb', line 88 def objekt, text link_to 'Archive', objekt, method: :delete, data: { confirm: text }, class: 'btn btn-danger pull-right' if params[:action] == 'edit' end |
#dropdown_menu(name, test, &block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/r5/template/config/initializers/html_helpers.rb', line 30 def name, test, &block out = %Q[<li #{"class='active'" if params[:controller] =~ /#{test}/} id='fat-menu' class='dropdown'>] out += %Q[<a href="#" role="button" class="dropdown-toggle" data-toggle="dropdown">] out += %Q[<i class="icon-user"></i>#{name}] out += %Q[<i class="icon-caret-down"></i></a>] out += %Q[<ul class="dropdown-menu">] out += capture(&block) out += %Q[</ul></li>] out.html_safe end |
#lf(date, options = {}) ⇒ Object
same as I18n.l() but ignores nil
42 43 44 |
# File 'lib/r5/template/config/initializers/html_helpers.rb', line 42 def lf date, ={} l(date, ) if date end |
#menu_item(name, url, test) ⇒ Object
26 27 28 |
# File 'lib/r5/template/config/initializers/html_helpers.rb', line 26 def name, url, test %Q{<li#{' class=active' if params[:controller]+params[:action]=~test }><a href="#{url}">#{ name }</a></li>}.html_safe end |
#num(number, options = {:precision=>2}) ⇒ Object
57 58 59 60 61 |
# File 'lib/r5/template/config/initializers/html_helpers.rb', line 57 def num number, ={:precision=>2} return number unless number.is_a? Numeric return '' if [:skip_zero] && number==0 number_with_precision( number, ) end |
#num0(number, skip_zero = false) ⇒ Object
78 79 80 81 82 |
# File 'lib/r5/template/config/initializers/html_helpers.rb', line 78 def num0 number, skip_zero=false return '' if skip_zero && number==0 return number if number.is_a? Fixnum c_num number, 0, skip_zero end |
#num2(number, skip_zero = false) ⇒ Object
74 75 76 |
# File 'lib/r5/template/config/initializers/html_helpers.rb', line 74 def num2 number, skip_zero=false c_num number, 2, skip_zero end |
#num3(number, skip_zero = false) ⇒ Object
70 71 72 |
# File 'lib/r5/template/config/initializers/html_helpers.rb', line 70 def num3 number, skip_zero=false c_num number, 3, skip_zero end |
#num_warn(condition) ⇒ Object
16 17 18 |
# File 'lib/r5/template/config/initializers/html_helpers.rb', line 16 def num_warn condition "num #{'warn' if condition}" end |
#numx(number, precision = 3, skip_zero = false) ⇒ Object
84 85 86 |
# File 'lib/r5/template/config/initializers/html_helpers.rb', line 84 def numx number, precision=3, skip_zero=false c_num number, precision, skip_zero end |
#records_filter ⇒ Object
20 21 22 23 24 |
# File 'lib/r5/template/config/initializers/html_helpers.rb', line 20 def records_filter concat t('records') + ': ' + select_tag('filter[per_page]', (%w[30 50 100], filter.params[:per_page]) ) + "\n" end |
#session_debug ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/r5/template/config/initializers/html_helpers.rb', line 92 def session_debug "#{session['debug_params']}<br />#{link_to_function 'debug', "$('#debug_div').toggle()", class: 'btn thin'}<hr class='separation'/><div class='box white spaced' id='debug_div' style='display:none'>params:#{params.inspect}<br /><br />session#{session.inspect }<br /><br />referrer:#{request.referrer}".html_safe if DEVEL && session['debug_params'] session['debug_params']='' end |
#shorten(text, length = 20) ⇒ Object
make long text short with ‘…’
10 11 12 13 14 |
# File 'lib/r5/template/config/initializers/html_helpers.rb', line 10 def shorten text, length=20 return '' unless text.present? res = text.scan /^(.{1,#{length}})(.*)/ "#{res[0][0]}#{res[0][1].present? ? '...' : ''}" end |
#t_header(name) ⇒ Object
3 4 5 6 7 |
# File 'lib/r5/template/config/initializers/html_helpers.rb', line 3 def t_header name header = t("activerecord.attributes.#{name}") header[0] = header[0].upcase header end |
#yes_no_select ⇒ Object
selecting - yes, no, nil
47 48 49 |
# File 'lib/r5/template/config/initializers/html_helpers.rb', line 47 def yes_no_select [nil, [t('yes'), 'yes'], [t('no'), 'no'] ] end |