Module: BrainDamage::BrainDamageHelper

Defined in:
lib/brain_damage/brain_damage_helper.rb

Instance Method Summary collapse

Instance Method Details

#ajax_sensible_field_wrapper(object, method, show = true, html = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/brain_damage/brain_damage_helper.rb', line 22

def ajax_sensible_field_wrapper(object, method, show = true, html = {})
  html[:tag] ||= 'tr'
  html[:class] ||= ''
  html[:class] += ' sensible-to-ajax'

  (html[:tag], { :class => html[:class], :data => { :ajax_sensibility_field => method }}) do
    yield if block_given? and show
  end
end

#bd(partial, locals = {}) ⇒ Object



8
9
10
# File 'lib/brain_damage/brain_damage_helper.rb', line 8

def bd(partial, locals = {})
  r "brain_damage/#{partial}", :locals => locals
end

#bd_actions(locals = {}, &block) ⇒ Object



17
18
19
20
# File 'lib/brain_damage/brain_damage_helper.rb', line 17

def bd_actions(locals = {}, &block)
  locals = {:show => false, :delete => true, :edit => true, :block => block}.merge(locals)
  render :partial => 'brain_damage/shared/actions', :locals => locals
end

#bd_id(prefix = nil) ⇒ Object



12
13
14
15
# File 'lib/brain_damage/brain_damage_helper.rb', line 12

def bd_id(prefix = nil)
  prefix = "#{prefix}-" if prefix
  "#{prefix}brain-damage-#{(0...16).map { (65 + rand(26)).chr }.join.downcase}"
end

#cet(string) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/brain_damage/brain_damage_helper.rb', line 62

def cet(string)
  string = t_or_c(string)
  if string == string.upcase
    string
  else
    string.capitalize
  end
end

#ct(string) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/brain_damage/brain_damage_helper.rb', line 52

def ct(string)
  string = t_or_c(string)

  if string == string.upcase
    string
  else
    string.capitalize
  end
end

#name_for_input_tag(attribute_name, prefix = nil) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/brain_damage/brain_damage_helper.rb', line 32

def name_for_input_tag(attribute_name, prefix = nil)
  if prefix
    return "#{prefix}[#{attribute_name}]"
  end

  attribute_name
end

#r(partial, locals = {}) ⇒ Object



4
5
6
# File 'lib/brain_damage/brain_damage_helper.rb', line 4

def r(partial, locals = {})
  render :partial => partial, :locals => locals
end

#T(string) ⇒ Object



71
72
73
# File 'lib/brain_damage/brain_damage_helper.rb', line 71

def T(string)
  t_or_c(string).upcase
end

#t_or_c(string) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/brain_damage/brain_damage_helper.rb', line 40

def t_or_c(string)
  return t string if I18n.exists? string

  common = "common.#{string.split('.').last}"
  return t common if I18n.exists? common

  entities = "entities.#{string.split('.').last}"
  return t entities if I18n.exists? entities

  t string
end