Module: Provideal::PluginUtils

Defined in:
lib/provideal_plugin_utils.rb,
lib/provideal_plugin_utils/asset_tag_helper.rb

Defined Under Namespace

Modules: AssetTagHelper

Class Method Summary collapse

Class Method Details

.enableObject

Enables Rails extensions



43
44
45
46
47
# File 'lib/provideal_plugin_utils.rb', line 43

def enable #:nodoc:
  # enable our overriden asset helper
  require 'provideal_plugin_utils/asset_tag_helper'
  ::ActionView::Helpers::AssetTagHelper.send :include, Provideal::PluginUtils::AssetTagHelper
end

.install_assets(plugin_name, source_path) ⇒ Object

Installs your plugins’ assets into the host application by linking public/plugins/ to your plugins’ public folder.

In your plugins’ init.rb:

Provideal::PluginUtils.install_assets('your_plugin', 'path to your plugins' public folder')

The host application may access the plugins’ assets using Rails asset tag helpers together with the provided :plugin option.

Example:

<%= javascript_include_tag 'foo.js', :plugin => 'your_plugin' %>

This will create a proper link to ‘/plugins/your_plugin/javascripts/foo.js’.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/provideal_plugin_utils.rb', line 22

def install_assets(plugin_name, source_path)
  # Precheck conditions
  raise "Plugin name required" unless plugin_name
  raise "Source path required" unless source_path
  raise "Source path does't exists" unless File.exists?(source_path)

  # Target path
  target_base_path = "#{RAILS_ROOT}/public/plugins"
  FileUtils.mkdir_p(target_base_path) unless File.exists?(target_base_path)
  target_path = "#{target_base_path}/#{plugin_name}"

  # Only install if the target path does not exists
  unless File.exists?(target_path)
    puts "Installing assets for plugin #{plugin_name} from #{source_path} into #{target_path}."
    File.symlink(source_path, target_path)
  end
end