Class: Inputs::EffectiveUrl::Input

Inherits:
Effective::FormInput show all
Defined in:
app/models/inputs/effective_url/input.rb

Constant Summary collapse

FA_FIELD_NAMES =
['facebook', 'google', 'linkedin', 'twitter', 'vimeo', 'youtube']

Instance Method Summary collapse

Methods inherited from Effective::FormInput

#field_name, #html_options, #initialize, #js_options, #options, #value

Constructor Details

This class inherits a constructor from Effective::FormInput

Instance Method Details

#default_input_htmlObject



8
9
10
11
12
13
14
15
# File 'app/models/inputs/effective_url/input.rb', line 8

def default_input_html
  {
    class: 'effective_url url',
    pattern: 'https?://[A-Za-z0-9]+.+',
    placeholder: placeholder,
    title: 'A URL starting with http:// or https://'
  }
end

#fontawesomeObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/models/inputs/effective_url/input.rb', line 62

def fontawesome
  if options[:fontawesome] == false
    ''.html_safe
  elsif options[:fontawesome].present? && options[:fontawesome] != true
    (:i, '', class: "fa fa-#{options[:fontawesome].to_s.gsub('fa-', '')}")
  elsif field_name.include?('facebook')
    (:i, '', class: 'fa fa-facebook')
  elsif field_name.include?('google')
    (:i, '', class: 'fa fa-google')
  elsif field_name.include?('linkedin')
    (:i, '', class: 'fa fa-linkedin')
  elsif field_name.include?('twitter')
    (:i, '', class: 'fa fa-twitter')
  elsif field_name.include?('vimeo')
    (:i, '', class: 'fa fa-vimeo')
  elsif field_name.include?('youtube')
    (:i, '', class: 'fa fa-youtube')
  else
    ''.html_safe
  end
end

#glyphiconObject



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/models/inputs/effective_url/input.rb', line 48

def glyphicon
  if options[:glyphicon] == false
    ''.html_safe
  elsif options[:glyphicon] == true
    (:i, '', class: 'glyphicon glyphicon-globe')
  elsif options[:glyphicon].present?
    (:i, '', class: "glyphicon glyphicon-#{options[:glyphicon].to_s.gsub('glyphicon-', '')}")
  elsif defined?(FontAwesome) && FA_FIELD_NAMES.any? { |name| field_name.include?(name) } && options[:fontawesome] != false
    ''.html_safe
  else
    (:i, '', class: 'glyphicon glyphicon-globe')
  end
end

#placeholderObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/inputs/effective_url/input.rb', line 30

def placeholder
  if field_name.include?('facebook')
    'https://www.facebook.com/MyProfile'
  elsif field_name.include?('google')
    'https://plus.google.com/+MyProfile'
  elsif field_name.include?('linkedin')
    'https://www.linkedin.com/in/MyProfile'
  elsif field_name.include?('twitter')
    'https://twitter.com/MyProfile'
  elsif field_name.include?('vimeo')
    'https://vimeo.com/MyProfile'
  elsif field_name.include?('youtube')
    'https://www.youtube.com/user/MyProfile'
  else
    'http://www.example.com'
  end
end

#to_htmlObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/models/inputs/effective_url/input.rb', line 17

def to_html
  if options[:input_group] == false
    return url_field_tag(field_name, value, tag_options)
  end

  (:div, class: 'input-group') do
    (:span, class: 'input-group-addon') do
       glyphicon + fontawesome
    end +
    url_field_tag(field_name, value, tag_options)
  end
end