Module: ActionView::Helpers::DateHelper

Defined in:
lib/rails_admin_content/helper.rb

Instance Method Summary collapse

Instance Method Details

#content_field(column, value = nil) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rails_admin_content/helper.rb', line 45

def content_field(column, value=nil)
  type = column["Type"].gsub(/\(.*?\)/,'')
  column["Default"] = value if value
  column["Field"] = "field[#{column["Field"]}]"
  case type
  when 'text'
    text_area_tag column["Field"], column["Default"], :size => "25x6", 'data-field' => column["Field"], class: "#{type} span10"
  when 'varchar'
    text_field_tag column["Field"], column["Default"], 'data-field' => column["Field"],  class: "#{type} span10"
  when 'int'
    number_field_tag column["Field"], column["Default"], 'data-field' => column["Field"],  class: "#{type} span10"
  when 'tinyint'
    select_tag column["Field"], options_for_select([['Yes',1],['No',0]], column["Default"]), 'data-field' => column["Field"],  class: "#{type} span10"
  else
    text_field_tag column["Field"], column["Default"],  'data-field' => column["Field"], class: "#{type} span10"
  end
end

#custom_paginate(scope, options = {}) ⇒ Object



4
5
6
7
# File 'lib/rails_admin_content/helper.rb', line 4

def custom_paginate(scope, options = {})
  paginate = RailsAdminContent::Paginate.new(scope, options.update(per_page: options[:stint]))
  paginate.to_s
end

#edited(key, value, str = '') ⇒ Object



35
36
37
38
39
# File 'lib/rails_admin_content/helper.rb', line 35

def edited(key, value, str='')
  str << 'editable' unless key == 'id'
  str << ' edit_datepicker' if value.is_a?(Time)
  str
end

#format(value, limit = 10) ⇒ Object



9
10
11
12
13
# File 'lib/rails_admin_content/helper.rb', line 9

def format(value, limit=10)
  value = value.is_a?(String) && value.size > limit ? value.truncate(limit) : value
  value = value.is_a?(Time) ? value.to_s(:db) : value
  value ||= "null"
end


21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rails_admin_content/helper.rb', line 21

def link_to_menu(*args, &block)
  name         = menu_value(args[0], args[1])
  options      = args[2] || {}
  html_options = args[3]

  html_options = convert_options_to_data_attributes(options, html_options)
  url = url_for(options)

  href = html_options['href']
  tag_options = tag_options(html_options)
  href_attr = "href=\"#{ERB::Util.html_escape(url)}\"" unless href
  "<a #{href_attr}#{tag_options}>#{ERB::Util.html_escape(name || url)}</a>".html_safe
end


15
16
17
18
19
# File 'lib/rails_admin_content/helper.rb', line 15

def menu_value(value, icon)
  raw "  <i class=\"\#{icon}\"></i><span class=\"hidden-tablet\">\#{value}</span>\n  HTML\nend\n"

#options_for_select_column_data(table, selected = nil) ⇒ Object



41
42
43
# File 'lib/rails_admin_content/helper.rb', line 41

def options_for_select_column_data(table, selected=nil)
  options_for_select RailsAdminContent::Client.desc_table(table).map{|a| [ a["Field"],a["Field"], column_type: a["Type"].gsub(/\(.*?\)/,'') ]}, selected
end