Module: CanonicalRails::TagHelper
- Defined in:
- app/helpers/canonical_rails/tag_helper.rb
Instance Method Summary collapse
- #canonical_host ⇒ Object
- #canonical_href(host = canonical_host) ⇒ Object
- #canonical_tag(host = canonical_host) ⇒ Object
- #path_without_html_extension ⇒ Object
- #trailing_slash_if_needed ⇒ Object
- #trailing_slash_needed? ⇒ Boolean
- #whitelisted_params ⇒ Object
- #whitelisted_query_string ⇒ Object
Instance Method Details
#canonical_host ⇒ Object
16 17 18 |
# File 'app/helpers/canonical_rails/tag_helper.rb', line 16 def canonical_host CanonicalRails.host || request.host end |
#canonical_href(host = canonical_host) ⇒ Object
20 21 22 |
# File 'app/helpers/canonical_rails/tag_helper.rb', line 20 def canonical_href(host=canonical_host) raw "#{request.protocol}#{host}#{path_without_html_extension}#{trailing_slash_if_needed}#{whitelisted_query_string}" end |
#canonical_tag(host = canonical_host) ⇒ Object
24 25 26 |
# File 'app/helpers/canonical_rails/tag_helper.rb', line 24 def canonical_tag(host=canonical_host) tag(:link, :href => canonical_href(host), :rel => 'canonical') end |
#path_without_html_extension ⇒ Object
12 13 14 |
# File 'app/helpers/canonical_rails/tag_helper.rb', line 12 def path_without_html_extension request.path.sub(/\.html$/, '') end |
#trailing_slash_if_needed ⇒ Object
8 9 10 |
# File 'app/helpers/canonical_rails/tag_helper.rb', line 8 def trailing_slash_if_needed "/" if trailing_slash_needed? and request.path != '/' end |
#trailing_slash_needed? ⇒ Boolean
4 5 6 |
# File 'app/helpers/canonical_rails/tag_helper.rb', line 4 def trailing_slash_needed? CanonicalRails.sym_collection_actions.include? request.params['action'].to_sym end |
#whitelisted_params ⇒ Object
28 29 30 31 32 33 |
# File 'app/helpers/canonical_rails/tag_helper.rb', line 28 def whitelisted_params request.params.select do |key, value| value.present? and CanonicalRails.sym_whitelisted_parameters.include? key.to_sym end end |
#whitelisted_query_string ⇒ Object
35 36 37 |
# File 'app/helpers/canonical_rails/tag_helper.rb', line 35 def whitelisted_query_string "?" + Rack::Utils.build_nested_query(whitelisted_params) if whitelisted_params.present? end |