provideal-plugin-utils 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ nbproject
2
+ pkg
3
+ .DS_Store
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,7 @@
1
+ Provideal Plugin Utils
2
+ ======================
3
+
4
+ A small collection of Rails plugin utilities to deal with assets
5
+ bundled within Rails plugins/engines.
6
+
7
+ Copyright (c) 2009 Provideal Systems GmbH, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # coding: utf-8
2
+
3
+ require 'rake'
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |gemspec|
8
+ gemspec.name = "provideal-plugin-utils"
9
+ gemspec.summary = "A collection of Rails plugin utilities"
10
+ gemspec.email = "info@provideal.net"
11
+ gemspec.homepage = "http://github.com/provideal/plugin-utils/"
12
+ gemspec.authors = ["René Sprotte"]
13
+ end
14
+ rescue LoadError
15
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
16
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'provideal_plugin_utils'
@@ -0,0 +1,55 @@
1
+ module Provideal
2
+ module PluginUtils
3
+ module AssetTagHelper
4
+
5
+ def self.included(base) #:nodoc:
6
+ base.class_eval do
7
+ [
8
+ :stylesheet_link_tag,
9
+ :javascript_include_tag,
10
+ :image_path,
11
+ :image_tag
12
+ ].each do |m|
13
+ alias_method_chain m, :plugin_support
14
+ end
15
+ end
16
+ end
17
+
18
+ def stylesheet_link_tag_with_plugin_support(*sources)
19
+ stylesheet_link_tag_without_plugin_support(*Provideal::PluginUtils::AssetTagHelper.pluginify_sources("stylesheets", *sources))
20
+ end
21
+
22
+ def javascript_include_tag_with_plugin_support(*sources)
23
+ javascript_include_tag_without_plugin_support(*Provideal::PluginUtils::AssetTagHelper.pluginify_sources("javascripts", *sources))
24
+ end
25
+
26
+ def image_path_with_plugin_support(source, options = {})
27
+ options.stringify_keys!
28
+ pluginified_source = Provideal::PluginUtils::AssetTagHelper.plugin_asset_path(options["plugin"], "images", source) if options["plugin"]
29
+ image_path_without_plugin_support(pluginified_source)
30
+ end
31
+
32
+ def image_tag_with_plugin_support(source, options = {})
33
+ options.stringify_keys!
34
+ if options["plugin"]
35
+ pluginified_source = Provideal::PluginUtils::AssetTagHelper.plugin_asset_path(options["plugin"], "images", source)
36
+ options.delete("plugin")
37
+ end
38
+ image_tag_without_plugin_support(pluginified_source, options)
39
+ end
40
+
41
+ def self.pluginify_sources(type, *sources)
42
+ options = sources.last.is_a?(Hash) ? sources.pop.stringify_keys : { }
43
+ if options["plugin"]
44
+ sources.map! { |s| plugin_asset_path(options["plugin"], type, s) }
45
+ options.delete("plugin")
46
+ end
47
+ sources << options
48
+ end
49
+
50
+ def self.plugin_asset_path(plugin_name, type, asset)
51
+ "/plugins/#{plugin_name}/#{type}/#{asset}"
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,56 @@
1
+ module Provideal
2
+ module PluginUtils
3
+ class << self
4
+ #
5
+ # Installs your plugins' assets into the host
6
+ # application by linking public/plugins/[your_plugin] to
7
+ # your plugins' public folder.
8
+ #
9
+ # In your plugins' init.rb:
10
+ #
11
+ # Provideal::PluginUtils.install_assets('your_plugin', 'path to your plugins' public folder')
12
+ #
13
+ # The host application may access the plugins' assets using Rails
14
+ # asset tag helpers together with the provided :plugin option.
15
+ #
16
+ # Example:
17
+ #
18
+ # <%= javascript_include_tag 'foo.js', :plugin => 'your_plugin' %>
19
+ #
20
+ # This will create a proper link to '/plugins/your_plugin/javascripts/foo.js'.
21
+ #
22
+ def install_assets(plugin_name, target_path)
23
+ # Precheck conditions
24
+ raise "Plugin name required" unless plugin_name
25
+ raise "Target path required" unless target_path
26
+ raise "Taget does't exists" unless File.exists?(target_path)
27
+
28
+ # Create the plugins base path inside the hosts public folder
29
+ plugins_public_base_path = "#{RAILS_ROOT}/public/plugins"
30
+ FileUtils.mkdir_p(plugins_public_base_path)
31
+
32
+ # The source path
33
+ source_path = "#{plugins_public_base_path}/#{plugin_name}"
34
+
35
+ # Create the symlink if the source_path is not present
36
+ # This allows for manual overrides
37
+ unless File.exists?(source_path)
38
+ system "ln -s #{target_path} #{source_path}"
39
+ end
40
+ end
41
+
42
+ #
43
+ # Enables Rails extensions
44
+ #
45
+ def enable #:nodoc:
46
+ # enable our overriden asset helper
47
+ require 'provideal_plugin_utils/asset_tag_helper'
48
+ ::ActionView::Helpers::AssetTagHelper.send :include, Provideal::PluginUtils::AssetTagHelper
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ if defined?(Rails) and defined?(ActionController)
55
+ Provideal::PluginUtils.enable
56
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: provideal-plugin-utils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - "Ren\xC3\xA9 Sprotte"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-15 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: info@provideal.net
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ files:
25
+ - .gitignore
26
+ - MIT-LICENSE
27
+ - README
28
+ - Rakefile
29
+ - VERSION
30
+ - init.rb
31
+ - lib/provideal_plugin_utils.rb
32
+ - lib/provideal_plugin_utils/asset_tag_helper.rb
33
+ has_rdoc: true
34
+ homepage: http://github.com/provideal/plugin-utils/
35
+ licenses: []
36
+
37
+ post_install_message:
38
+ rdoc_options:
39
+ - --charset=UTF-8
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ version:
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ requirements: []
55
+
56
+ rubyforge_project:
57
+ rubygems_version: 1.3.5
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: A collection of Rails plugin utilities
61
+ test_files: []
62
+