asset_copier_generator 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1 -0
- data/MIT-LICENSE +16 -0
- data/README +59 -0
- data/Rakefile +22 -0
- data/TODO +2 -0
- data/USAGE +1 -0
- data/asset_copier_generator.gemspec +28 -0
- data/asset_copier_generator.rb +15 -0
- data/templates/asset_copier.rake.erb +11 -0
- data/templates/asset_copier.rb.erb +90 -0
- data/templates/deleted_files +14 -0
- data/templates/init.rb.erb +7 -0
- data/templates/install.rb.erb +20 -0
- metadata +68 -0
data/CHANGELOG
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
10/30/08 - Initial version [Matthew Bass]
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Copyright (c) 2007-2008 Matthew Bass (http://matthewbass.com)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
4
|
+
and associated documentation files (the "Software"), to deal in the Software without
|
5
|
+
restriction, including without limitation the rights to use, copy, modify, merge, publish,
|
6
|
+
distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
Software is furnished to do so, subject to the following conditions:
|
8
|
+
|
9
|
+
The above copyright notice and this permission notice shall be included in all copies or
|
10
|
+
substantial portions of the Software.
|
11
|
+
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
13
|
+
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
14
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
15
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
16
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
= asset_copier_generator
|
2
|
+
|
3
|
+
Intelligent asset management for Rails plugins.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
Install the gem directly:
|
8
|
+
|
9
|
+
sudo gem install pelargir-asset_copier --source=http://gems.github.com
|
10
|
+
|
11
|
+
Or clone the project, build the gem, and install:
|
12
|
+
|
13
|
+
git clone git://github.com/pelargir/asset_copier.git
|
14
|
+
gem build asset_copier_generator.gemspec
|
15
|
+
sudo gem install asset_copier_generator
|
16
|
+
|
17
|
+
== Apply to Target Plugin
|
18
|
+
|
19
|
+
asset_copier_generator will copy the necessary files into a target plugin
|
20
|
+
to enable intelligent asset management. You should then check these files in
|
21
|
+
to source control. The generated files become a part of your plugin.
|
22
|
+
|
23
|
+
To install the files in your plugin, first ensure that your plugin is installed
|
24
|
+
or symlinked from an existing Rails app. From the root of that Rails app, run:
|
25
|
+
|
26
|
+
script/generate asset_copier plugin_name
|
27
|
+
|
28
|
+
Where "plugin_name" is the name of the plugin you want to install into. The
|
29
|
+
appropriate files will be copied into your plugin. Now, to copy assets
|
30
|
+
from your plugin into your Rails app, run:
|
31
|
+
|
32
|
+
rake plugin_name:install
|
33
|
+
|
34
|
+
Your users can run this same Rake task any time they want to update files
|
35
|
+
in their Rails app to reflect the assets needed by your plugin.
|
36
|
+
|
37
|
+
== Usage
|
38
|
+
|
39
|
+
Once applied to a target plugin, files within the /files directory of that
|
40
|
+
plugin will be copied into RAILS_ROOT whenever the installation task is run.
|
41
|
+
|
42
|
+
Files will also be copied every time the Rails server is started if the project
|
43
|
+
is running in development mode. (Projects running in production mode will instead
|
44
|
+
receive a warning in the log that one or more files are missing. No files
|
45
|
+
will automatically be copied.)
|
46
|
+
|
47
|
+
What if you remove a file from your plugin at some future point? Simply add
|
48
|
+
the file path to deleted_files. The next time the Rails server is started
|
49
|
+
or the install task is run, a warning will print in the log informing the
|
50
|
+
user that the file has been removed from the plugin and can also safely
|
51
|
+
be removed from their Rails project.
|
52
|
+
|
53
|
+
== Resources
|
54
|
+
|
55
|
+
Repository: http://github.com/pelargir/asset_copier
|
56
|
+
Blog: http://matthewbass.com
|
57
|
+
Author: Matthew Bass
|
58
|
+
|
59
|
+
Extraction work sponsored by Terralien
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the asset_copier_generator gem.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
#t.libs << 'lib'
|
11
|
+
t.pattern = 'test/**/*_test.rb'
|
12
|
+
t.verbose = true
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Generate documentation for the asset_copier_generator gem.'
|
16
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
17
|
+
rdoc.rdoc_dir = 'rdoc'
|
18
|
+
rdoc.title = 'asset_copier_generator'
|
19
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
20
|
+
rdoc.rdoc_files.include('README')
|
21
|
+
#rdoc.rdoc_files.include('lib/**/*.rb')
|
22
|
+
end
|
data/TODO
ADDED
data/USAGE
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
describe how to use the generator
|
@@ -0,0 +1,28 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "asset_copier_generator"
|
3
|
+
s.version = "0.5"
|
4
|
+
s.date = "2008-10-30"
|
5
|
+
s.summary = "Intelligent asset management for plugins."
|
6
|
+
s.email = "pelargir@gmail.com"
|
7
|
+
s.homepage = "http://github.com/pelargir/asset_copier"
|
8
|
+
s.description = "Provides intelligent asset management for Rails plugins."
|
9
|
+
s.has_rdoc = true
|
10
|
+
s.authors = ["Matthew Bass"]
|
11
|
+
s.files = [
|
12
|
+
"asset_copier_generator.rb",
|
13
|
+
"CHANGELOG",
|
14
|
+
"MIT-LICENSE",
|
15
|
+
"Rakefile",
|
16
|
+
"README",
|
17
|
+
"templates/asset_copier.rb.erb",
|
18
|
+
"templates/asset_copier.rake.erb",
|
19
|
+
"templates/init.rb.erb",
|
20
|
+
"templates/install.rb.erb",
|
21
|
+
"templates/deleted_files",
|
22
|
+
"TODO",
|
23
|
+
"USAGE",
|
24
|
+
"asset_copier_generator.gemspec"
|
25
|
+
]
|
26
|
+
s.rdoc_options = ["--main", "README"]
|
27
|
+
s.extra_rdoc_files = ["README"]
|
28
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class AssetCopierGenerator < Rails::Generator::NamedBase
|
2
|
+
def manifest
|
3
|
+
record do |m|
|
4
|
+
m.directory "vendor/plugins/#{file_name}/tasks"
|
5
|
+
m.directory "vendor/plugins/#{file_name}/lib/#{file_name}"
|
6
|
+
|
7
|
+
m.template "init.rb.erb", "vendor/plugins/#{file_name}/init.rb"
|
8
|
+
m.template "install.rb.erb", "vendor/plugins/#{file_name}/install.rb"
|
9
|
+
m.template "asset_copier.rake.erb", "vendor/plugins/#{file_name}/tasks/asset_copier.rake"
|
10
|
+
m.template "asset_copier.rb.erb", "vendor/plugins/#{file_name}/lib/#{file_name}/asset_copier.rb"
|
11
|
+
|
12
|
+
m.file "deleted_files", "vendor/plugins/#{file_name}/deleted_files"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# Generated by the asset_copier plugin
|
2
|
+
# http://github.com/pelargir/asset_copier
|
3
|
+
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/<%= file_name %>/asset_copier')
|
5
|
+
|
6
|
+
namespace :<%= file_name %> do
|
7
|
+
desc "Install files required by <%= file_name %>"
|
8
|
+
task :install do
|
9
|
+
<%= class_name %>::AssetCopier.copy "<%= file_name %>"
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# Generated by the asset_copier plugin
|
2
|
+
# http://github.com/pelargir/asset_copier
|
3
|
+
|
4
|
+
require 'find'
|
5
|
+
require 'digest/md5'
|
6
|
+
|
7
|
+
module <%= class_name %>
|
8
|
+
class AssetCopier
|
9
|
+
@source = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'files'))
|
10
|
+
@destination = RAILS_ROOT
|
11
|
+
@deleted_files = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'deleted_files'))
|
12
|
+
class << self
|
13
|
+
attr_accessor :source, :destination, :deleted_files
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.copy(plugin_name)
|
17
|
+
begin
|
18
|
+
each_path do |path, dest_path, short_path|
|
19
|
+
if File.directory?(path)
|
20
|
+
unless File.exists?(dest_path)
|
21
|
+
FileUtils.mkdir_p(dest_path)
|
22
|
+
log "Creating directory #{short_path} for #{plugin_name}"
|
23
|
+
end
|
24
|
+
elsif !compare(path, dest_path)
|
25
|
+
FileUtils.cp(path, dest_path)
|
26
|
+
log "Copying #{short_path} from #{plugin_name}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
rescue Exception => e
|
30
|
+
log "Error trying to copy files: #{e.inspect}"
|
31
|
+
raise e
|
32
|
+
end
|
33
|
+
print_deletion_warnings(plugin_name)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.warn(plugin_name)
|
37
|
+
each_path do |path, dest_path, short_path|
|
38
|
+
next if File.directory?(path)
|
39
|
+
reinstall = false
|
40
|
+
if File.exists?(dest_path)
|
41
|
+
unless compare(path, dest_path)
|
42
|
+
log "WARNING: #{short_path} is out of date and needs to be reinstalled"
|
43
|
+
reinstall = true
|
44
|
+
end
|
45
|
+
else
|
46
|
+
reinstall = true
|
47
|
+
log "WARNING: #{short_path} is missing and needs to be installed"
|
48
|
+
end
|
49
|
+
log "WARNING: Please run rake #{plugin_name}:install" if reinstall
|
50
|
+
end
|
51
|
+
print_deletion_warnings(plugin_name)
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.compare(file1, file2)
|
55
|
+
File.exists?(file1) && File.exists?(file2) &&
|
56
|
+
Digest::MD5.hexdigest(File.read(file1)) == Digest::MD5.hexdigest(File.read(file2))
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.print_deletion_warnings(plugin_name)
|
60
|
+
File.open(deleted_files, "r") do |f|
|
61
|
+
f.readlines.reject { |l| l =~ /^#/ || l.strip.blank? }.each do |l|
|
62
|
+
log "WARNING: #{l} is no longer required by the #{plugin_name} plugin " <<
|
63
|
+
"and can can be safely removed" if File.exists?(l)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.paths
|
69
|
+
returning [] do |paths|
|
70
|
+
Find.find(source) do |path|
|
71
|
+
Find.prune if path =~ /\/\..+/
|
72
|
+
Find.prune if path =~ /(CVS|\.svn|\.git)/
|
73
|
+
paths << path
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.each_path
|
79
|
+
paths.each do |path|
|
80
|
+
dest_path = path.gsub(source, destination)
|
81
|
+
short_path = dest_path.gsub("#{destination}/", "")
|
82
|
+
yield path, dest_path, short_path
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.log(msg)
|
87
|
+
puts msg
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Generated by the asset_copier plugin
|
2
|
+
# http://github.com/pelargir/asset_copier
|
3
|
+
#
|
4
|
+
# Files that have been removed from the plugin and should also be removed from
|
5
|
+
# any Rails projects that use the plugin should be listed here, one entry
|
6
|
+
# per line. For example:
|
7
|
+
#
|
8
|
+
# public/javascripts/foo.js
|
9
|
+
# app/views/foo/bar.erb.html
|
10
|
+
#
|
11
|
+
# Adding the paths above to this file would ensure that foo.js and bar.erb.html
|
12
|
+
# both get removed from the target Rails project the next time the plugin's
|
13
|
+
# files are copied over.
|
14
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Generated by the asset_copier plugin
|
2
|
+
# http://github.com/pelargir/asset_copier
|
3
|
+
|
4
|
+
require 'rake'
|
5
|
+
|
6
|
+
begin
|
7
|
+
puts "============================================================="
|
8
|
+
puts "Attempting to install required files into your application..."
|
9
|
+
puts "============================================================="
|
10
|
+
RAKE_FILE = File.expand_path(File.join(File.dirname(__FILE__), 'tasks', 'asset_copier.rake'))
|
11
|
+
load RAKE_FILE
|
12
|
+
|
13
|
+
Rake::Task['<%= file_name %>:install'].invoke
|
14
|
+
puts "=========================================================="
|
15
|
+
puts "Success!"
|
16
|
+
puts "=========================================================="
|
17
|
+
rescue Exception => ex
|
18
|
+
puts "FAILED TO INSTALL REQUIRED FILES. PLEASE RUN rake <%= file_name %>:install."
|
19
|
+
puts "EXCEPTION: #{ex}"
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: asset_copier_generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.5"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Bass
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-10-30 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Provides intelligent asset management for Rails plugins.
|
17
|
+
email: pelargir@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
files:
|
25
|
+
- asset_copier_generator.rb
|
26
|
+
- CHANGELOG
|
27
|
+
- MIT-LICENSE
|
28
|
+
- Rakefile
|
29
|
+
- README
|
30
|
+
- templates/asset_copier.rb.erb
|
31
|
+
- templates/asset_copier.rake.erb
|
32
|
+
- templates/init.rb.erb
|
33
|
+
- templates/install.rb.erb
|
34
|
+
- templates/deleted_files
|
35
|
+
- TODO
|
36
|
+
- USAGE
|
37
|
+
- asset_copier_generator.gemspec
|
38
|
+
has_rdoc: true
|
39
|
+
homepage: http://github.com/pelargir/asset_copier
|
40
|
+
licenses: []
|
41
|
+
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options:
|
44
|
+
- --main
|
45
|
+
- README
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.3.4
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: Intelligent asset management for plugins.
|
67
|
+
test_files: []
|
68
|
+
|