Module: AccessKit::UrlHelperAdditions
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/access_kit/url_helper_additions.rb
Constant Summary collapse
- DEFAULT_KEY_NAME_FOR_PRECEDING_TEXT =
:intro
- DEFAULT_KEY_NAME_FOR_FOLLOWING_TEXT =
:outro
Class Method Summary collapse
- .add_supplement_to_text(text, opts = {}) ⇒ Object
- .args_for_link_to_with_supplement?(*args) ⇒ Boolean
-
.process_options_for_link_to_with_supplement(*args) ⇒ Object
TODO: maybe rename to ‘process_args’.
Class Method Details
.add_supplement_to_text(text, opts = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/access_kit/url_helper_additions.rb', line 9 def add_supplement_to_text(text, opts={}) default_opts = {DEFAULT_KEY_NAME_FOR_PRECEDING_TEXT => nil, DEFAULT_KEY_NAME_FOR_FOLLOWING_TEXT => nil, :auto_pad => true} opts = default_opts.merge(opts) padding = begin if opts[:auto_pad] === true ' ' elsif opts[:auto_pad] === false '' else opts[:auto_pad].to_s end end before_span = opts[DEFAULT_KEY_NAME_FOR_PRECEDING_TEXT].blank? ? "" : span_tag(opts[DEFAULT_KEY_NAME_FOR_PRECEDING_TEXT] + padding) after_span = opts[DEFAULT_KEY_NAME_FOR_FOLLOWING_TEXT].blank? ? "" : span_tag(padding + opts[DEFAULT_KEY_NAME_FOR_FOLLOWING_TEXT]) "#{before_span}#{text}#{after_span}".html_safe end |
.args_for_link_to_with_supplement?(*args) ⇒ Boolean
34 35 36 37 38 39 |
# File 'lib/access_kit/url_helper_additions.rb', line 34 def args_for_link_to_with_supplement?(*args) args[2].is_a?(Hash) && ( args[2].keys.include?(DEFAULT_KEY_NAME_FOR_PRECEDING_TEXT) || args[2].keys.include?(DEFAULT_KEY_NAME_FOR_FOLLOWING_TEXT) ) end |
.process_options_for_link_to_with_supplement(*args) ⇒ Object
TODO: maybe rename to ‘process_args’
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/access_kit/url_helper_additions.rb', line 42 def (*args) if args_for_link_to_with_supplement?(*args) # TODO: move to separate method: 'extract_supplement_opts' supplement_opts = [ DEFAULT_KEY_NAME_FOR_PRECEDING_TEXT, DEFAULT_KEY_NAME_FOR_FOLLOWING_TEXT, :auto_pad ].inject({}) do |memo, k| value = args[2].delete(k) value.blank? ? memo : memo.merge( k => value ) end new_args = args.dup # replace the name argument with new_name new_args[0] = AccessKit::UrlHelperAdditions.add_supplement_to_text(args[0], supplement_opts) new_args else nil end end |