Module: Admin::AdminHelper

Defined in:
lib/generators/somatics/install/templates/helper_admin.rb

Overview

Methods added to this helper will be available to all templates in the application.

Instance Method Summary collapse

Instance Method Details

#content_for(name, content = nil, &block) ⇒ Object



3
4
5
6
7
# File 'lib/generators/somatics/install/templates/helper_admin.rb', line 3

def content_for(name, content = nil, &block)
  @has_content ||= {}
  @has_content[name] = true
  super(name, content, &block)
end

#date_to_words(date) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/generators/somatics/install/templates/helper_admin.rb', line 65

def date_to_words(date)
  if date == Date.today
    "Today"
  elsif date <= Date.today - 1
    if date == Date.today - 1
      "Yesterday"
    elsif ((Date.today - 7)..(Date.today - 1)).include?(date)
      "Last #{date.strftime("%A")}"
    elsif ((Date.today - 14)..(Date.today - 8)).include?(date)
      "Two #{date.strftime("%A")}s ago"
    elsif ((Date.today - 21)..(Date.today - 15)).include?(date)
      "Three #{date.strftime("%A")}s ago"
    elsif ((Date.today - 29)..(Date.today - 22)).include?(date)
      "Four #{date.strftime("%A")}s ago"
    elsif Date.today - 30 < date
      "More than a month ago"
    end
  else
    if date == Date.today + 1
      "Tomorrow"
    elsif ((Date.today + 1)..(Date.today + 6)).include?(date)
      "This coming #{date.strftime("%A")}"
    elsif ((Date.today + 7)..(Date.today + 14)).include?(date)
      "Next #{date.strftime("%A")}s away"
    elsif ((Date.today + 15)..(Date.today + 21)).include?(date)
      "Two #{date.strftime("%A")}s away"
    elsif ((Date.today + 22)..(Date.today + 29)).include?(date)
      "Three #{date.strftime("%A")}s away"
    elsif Date.today + 30 > date
      "More than a month in the future"
    end
  end
end

#excel_document(xml, &block) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/generators/somatics/install/templates/helper_admin.rb', line 41

def excel_document(xml, &block)
  xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" 
  xml.Workbook({
    'xmlns'      => "urn:schemas-microsoft-com:office:spreadsheet", 
    'xmlns:o'    => "urn:schemas-microsoft-com:office:office",
    'xmlns:x'    => "urn:schemas-microsoft-com:office:excel",    
    'xmlns:html' => "http://www.w3.org/TR/REC-html40",
    'xmlns:ss'   => "urn:schemas-microsoft-com:office:spreadsheet" 
  }) do
    xml.Styles do
      xml.Style 'ss:ID' => 'Default', 'ss:Name' => 'Normal' do
        xml.Alignment 'ss:Vertical' => 'Bottom'
        xml.Borders
        xml.Font 'ss:FontName' => 'Arial'
        xml.Interior
        xml.NumberFormat
        xml.Protection
      end
    end
    yield block
  end
end

#has_content?(name) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/generators/somatics/install/templates/helper_admin.rb', line 9

def has_content?(name)
  (@has_content && @has_content[name]) || false
end

#match_action?(name) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/generators/somatics/install/templates/helper_admin.rb', line 17

def match_action?(name)
  controller.action_name == name
end

#match_controller?(name) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/generators/somatics/install/templates/helper_admin.rb', line 13

def match_controller?(name)
  controller.controller_name == name
end

#paper_trail_for(object) ⇒ Object



37
38
39
# File 'lib/generators/somatics/install/templates/helper_admin.rb', line 37

def paper_trail_for(object)
  render 'admin/shared/versions', :obj => object
end

#sort_asc_desc_helper(model_name, param) ⇒ Object



21
22
23
24
25
# File 'lib/generators/somatics/install/templates/helper_admin.rb', line 21

def sort_asc_desc_helper(model_name, param)
  result = image_tag('somatics/sort_asc.png') if params[:"#{model_name}_sort"] == param
  result = image_tag('somatics/sort_desc.png') if params[:"#{model_name}_sort"] == param + "_reverse"
  return result || ''
end


27
28
29
30
31
32
33
34
35
# File 'lib/generators/somatics/install/templates/helper_admin.rb', line 27

def sort_link_helper(text, model_name ,param)
  key = param
  key += "_reverse" if params[:"#{model_name}_sort"] == param
  html_options = {
    :title => I18n.t("sort_by",:field => text),
    :remote=>true
  }
  link_to(text, params.merge({:"#{model_name}_sort" => key}), html_options)  + sort_asc_desc_helper(model_name,param)
end