Class: ActionView::Helpers::InstanceTag
- Inherits:
-
Object
- Object
- ActionView::Helpers::InstanceTag
- Defined in:
- lib/bot-away/action_view/helpers/instance_tag.rb
Instance Attribute Summary collapse
-
#spinner ⇒ Object
readonly
Returns the value of attribute spinner.
Instance Method Summary collapse
- #assuming(object) ⇒ Object
- #content_tag_with_obfuscation(name, content_or_options_with_block = nil, options = nil, *args, &block) ⇒ Object
- #disguise(element) ⇒ Object
- #honeypot_options(options) ⇒ Object
- #honeypot_tag(name, options = nil, *args) ⇒ Object
- #initialize_with_spinner(object_name, method_name, template_object, object = nil) ⇒ Object
- #obfuscate_options(options) ⇒ Object
- #obfuscated_tag(name, options = nil, *args) ⇒ Object
- #tag_with_honeypot(name, options = nil, *args) ⇒ Object
-
#to_label_tag_with_obfuscation(text = nil, options = {}) ⇒ Object
Special case.
Instance Attribute Details
#spinner ⇒ Object (readonly)
Returns the value of attribute spinner.
2 3 4 |
# File 'lib/bot-away/action_view/helpers/instance_tag.rb', line 2 def spinner @spinner end |
Instance Method Details
#assuming(object) ⇒ Object
28 29 30 31 |
# File 'lib/bot-away/action_view/helpers/instance_tag.rb', line 28 def assuming(object) yield if object object end |
#content_tag_with_obfuscation(name, content_or_options_with_block = nil, options = nil, *args, &block) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/bot-away/action_view/helpers/instance_tag.rb', line 62 def content_tag_with_obfuscation(name, = nil, = nil, *args, &block) if block_given? content_tag_without_obfuscation(name, , , *args, &block) else # this should cover all Rails selects. if spinner && && (.keys.include?('id') || .keys.include?('name')) if name == 'select' && !.empty? content = '<option selected value=""></option>' else content = "" end disguise(content_tag_without_obfuscation(name, content, (), *args)) + content_tag_without_obfuscation(name, , (), *args) else content_tag_without_obfuscation(name, , , *args) end end end |
#disguise(element) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/bot-away/action_view/helpers/instance_tag.rb', line 86 def disguise(element) case rand(3) when 0 # Hidden element.replace "<div style='display:none;'>Leave this empty: #{element}</div>" when 1 # Off-screen element.replace "<div style='position:absolute;left:-1000px;top:-1000px;'>Don't fill this in: #{element}</div>" when 2 # Negligible size element.replace "<div style='position:absolute;width:0px;height:1px;z-index:-1;color:transparent;overflow:hidden;'>Keep this blank: #{element}</div>" else # this should never happen? disguise(element) end end |
#honeypot_options(options) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/bot-away/action_view/helpers/instance_tag.rb', line 19 def () add_default_name_and_id() assuming(spinner && ) do ['value'] &&= '' ['autocomplete'] = 'off' ['tabindex'] = -rand(10) - 1 end end |
#honeypot_tag(name, options = nil, *args) ⇒ Object
33 34 35 |
# File 'lib/bot-away/action_view/helpers/instance_tag.rb', line 33 def honeypot_tag(name, = nil, *args) tag_without_honeypot(name, (.dup? || {}), *args) end |
#initialize_with_spinner(object_name, method_name, template_object, object = nil) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/bot-away/action_view/helpers/instance_tag.rb', line 4 def initialize_with_spinner(object_name, method_name, template_object, object = nil) initialize_without_spinner(object_name, method_name, template_object, object) if template_object.controller.send(:protect_against_forgery?) @spinner = BotAway::Spinner.new(template_object.request.ip, object_name, template_object.form_authenticity_token) end end |
#obfuscate_options(options) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/bot-away/action_view/helpers/instance_tag.rb', line 11 def () add_default_name_and_id() assuming(spinner && ) do ['name'] &&= spinner.encode(['name']) ['id'] &&= spinner.encode(['id']) end end |
#obfuscated_tag(name, options = nil, *args) ⇒ Object
37 38 39 |
# File 'lib/bot-away/action_view/helpers/instance_tag.rb', line 37 def (name, = nil, *args) tag_without_honeypot(name, (.dup? || {}), *args) end |
#tag_with_honeypot(name, options = nil, *args) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/bot-away/action_view/helpers/instance_tag.rb', line 41 def tag_with_honeypot(name, = nil, *args) if spinner (name, , *args) + disguise(honeypot_tag(name, , *args)) else tag_without_honeypot(name, , *args) end end |
#to_label_tag_with_obfuscation(text = nil, options = {}) ⇒ Object
Special case
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/bot-away/action_view/helpers/instance_tag.rb', line 50 def to_label_tag_with_obfuscation(text = nil, = {}) # TODO: Can this be simplified? It's pretty similar to to_label_tag_without_obfuscation... = .stringify_keys tag_value = .delete("value") name_and_id = .dup name_and_id["id"] = name_and_id["for"] add_default_name_and_id_for_value(tag_value, name_and_id) ["for"] ||= name_and_id["id"] ["for"] = spinner.encode(["for"]) if spinner && ["for"] to_label_tag_without_obfuscation(text, ) end |