Module: Wallaby::ApplicationHelper

Defined in:
lib/helpers/wallaby/application_helper.rb

Overview

Application helper

Instance Method Summary collapse

Instance Method Details

#javascript_include_tag(*sources) ⇒ String

Add turbolinks options when it’s enabled

Parameters:

  • sources (Array<String>)

    source name under ‘app/assets/javascripts`

Returns:

  • (String)

    a list of javascript script tags

See Also:

  • ActionView::Helpers::AssetTagHelper#javascript_include_tag


38
39
40
41
42
43
44
45
46
47
# File 'lib/helpers/wallaby/application_helper.rb', line 38

def javascript_include_tag(*sources)
  default_options =
    if Wallaby.configuration.features.turbolinks_enabled
      { 'data-turbolinks-track' => true, 'data-turbolinks-eval' => false }
    else
      {}
    end
  options = default_options.merge!(sources.extract_options!.stringify_keys)
  super(*sources, options)
end

Add turbolinks options when it’s enabled

Parameters:

  • sources (Array<String>)

    source name under ‘app/assets/stylesheets`

Returns:

  • (String)

    a list of stylesheet link tags

See Also:

  • ActionView::Helpers::AssetTagHelper#stylesheet_link_tag


23
24
25
26
27
28
29
30
31
32
# File 'lib/helpers/wallaby/application_helper.rb', line 23

def stylesheet_link_tag(*sources)
  default_options =
    if Wallaby.configuration.features.turbolinks_enabled
      { 'data-turbolinks-track' => true }
    else
      {}
    end
  options = default_options.merge!(sources.extract_options!.stringify_keys)
  super(*sources, options)
end

#url_for(options = nil) ⇒ String

Override ‘actionview/lib/action_view/routing_url_for.rb#url_for` to handle the url_for properly for wallaby engine when options contains values of both `:resources` and `:action`

Parameters:

  • options (String, Hash) (defaults to: nil)

Returns:

  • (String)

    url



9
10
11
12
13
14
15
16
17
# File 'lib/helpers/wallaby/application_helper.rb', line 9

def url_for(options = nil)
  # possible Hash or Parameters
  if options.respond_to?(:to_h) \
    && options[:resources].present? && options[:action].present?
    UrlFor.handle wallaby_engine, options
  else
    super options
  end
end