Module: Provideal::PluginUtils::AssetTagHelper

Defined in:
lib/provideal_plugin_utils/asset_tag_helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/provideal_plugin_utils/asset_tag_helper.rb', line 5

def self.included(base) #:nodoc:
  base.class_eval do
    [
      :stylesheet_link_tag,
      :javascript_include_tag,
      :image_path,
      :image_tag
    ].each do |m|
      alias_method_chain m, :plugin_support
    end
  end
end

.plugin_asset_path(plugin_name, type, asset) ⇒ Object



52
53
54
# File 'lib/provideal_plugin_utils/asset_tag_helper.rb', line 52

def self.plugin_asset_path(plugin_name, type, asset)
  "/plugins/#{plugin_name}/#{type}/#{asset}"
end

.pluginify_sources(type, *sources) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/provideal_plugin_utils/asset_tag_helper.rb', line 43

def self.pluginify_sources(type, *sources)
  options = sources.last.is_a?(Hash) ? sources.pop.stringify_keys : { }
  if options["plugin"]
    sources.map! { |s| plugin_asset_path(options["plugin"], type, s) }
    options.delete("plugin")
  end
  sources << options
end

Instance Method Details

#image_path_with_plugin_support(source, options = {}) ⇒ Object



26
27
28
29
30
# File 'lib/provideal_plugin_utils/asset_tag_helper.rb', line 26

def image_path_with_plugin_support(source, options = {})
  options.stringify_keys!
  pluginified_source = Provideal::PluginUtils::AssetTagHelper.plugin_asset_path(options["plugin"], "images", source) if options["plugin"]
  image_path_without_plugin_support(pluginified_source)
end

#image_tag_with_plugin_support(source, options = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/provideal_plugin_utils/asset_tag_helper.rb', line 32

def image_tag_with_plugin_support(source, options = {})
  options.stringify_keys!
  if options["plugin"]
    pluginified_source = Provideal::PluginUtils::AssetTagHelper.plugin_asset_path(options["plugin"], "images", source)
    options.delete("plugin")
    image_tag_without_plugin_support(pluginified_source, options)
  else
    image_tag_without_plugin_support(source, options)
  end
end

#javascript_include_tag_with_plugin_support(*sources) ⇒ Object



22
23
24
# File 'lib/provideal_plugin_utils/asset_tag_helper.rb', line 22

def javascript_include_tag_with_plugin_support(*sources)
  javascript_include_tag_without_plugin_support(*Provideal::PluginUtils::AssetTagHelper.pluginify_sources("javascripts", *sources))
end


18
19
20
# File 'lib/provideal_plugin_utils/asset_tag_helper.rb', line 18

def stylesheet_link_tag_with_plugin_support(*sources)
  stylesheet_link_tag_without_plugin_support(*Provideal::PluginUtils::AssetTagHelper.pluginify_sources("stylesheets", *sources))
end