engine-assets 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +5 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +38 -0
- data/LICENSE +18 -17
- data/RAILS_VERSIONS +5 -0
- data/README.md +55 -0
- data/Rakefile +253 -26
- data/VERSION +1 -1
- data/app/controllers/engine_assets/assets_controller.rb +7 -1
- data/config/routes.rb +12 -1
- data/engine-assets.gemspec +53 -20
- data/features/rails.feature +127 -0
- data/features/step_definitions/rails_steps.rb +112 -0
- data/features/support/env.rb +15 -0
- data/features/support/rails.rb +125 -0
- data/features/support/terminal.rb +83 -0
- data/init.rb +1 -0
- data/lib/engine-assets.rb +8 -2
- data/lib/engine_assets/engine.rb +3 -0
- data/lib/engine_assets/extensions/rails/assets.rb +6 -0
- data/lib/engine_assets/public_locator.rb +20 -5
- data/spec/{controllers → app/controllers/engine_assets}/javascripts_controller_spec.rb +2 -2
- data/spec/{controllers → app/controllers/engine_assets}/stylesheets_controller_spec.rb +2 -2
- data/spec/lib/engine-assets_spec.rb +7 -0
- data/spec/lib/engine_assets/public_locator_spec.rb +28 -4
- data/spec/shared/assets_controller_spec.rb +39 -0
- data/spec/shared/assets_routing_spec.rb +59 -0
- data/spec/spec.opts +2 -2
- data/spec/spec_helper.rb +61 -22
- data/spec/support/Gemfile-2.3.5 +7 -0
- data/spec/support/Gemfile-2.3.5.lock +38 -0
- data/spec/support/Gemfile-2.3.9 +7 -0
- data/spec/support/Gemfile-2.3.9.lock +38 -0
- data/spec/support/Gemfile-3.0.0 +16 -0
- data/spec/support/Gemfile-3.0.0.lock +90 -0
- data/spec/support/rails.rb +32 -0
- data/spec/support/terminal.rb +54 -0
- metadata +123 -25
- data/README.rdoc +0 -18
- data/TODO.md +0 -4
- data/rails/init.rb +0 -7
- data/spec/spec_suite.rb +0 -26
- data/spec/support/shared/assets_controller_spec.rb +0 -34
- data/spec/support/shared/assets_routing_spec.rb +0 -55
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
Before do
|
4
|
+
@terminal = Terminal.new
|
5
|
+
end
|
6
|
+
|
7
|
+
class Terminal
|
8
|
+
attr_reader :output, :status, :result
|
9
|
+
attr_accessor :environment_variables
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@cwd = FileUtils.pwd
|
13
|
+
@output = ""
|
14
|
+
@result = ""
|
15
|
+
@status = 0
|
16
|
+
@logger = Logger.new(File.join(TEMP_DIR, 'terminal.log'))
|
17
|
+
|
18
|
+
@environment_variables = {
|
19
|
+
"GEM_HOME" => LOCAL_GEM_ROOT,
|
20
|
+
"GEM_PATH" => "#{LOCAL_GEM_ROOT}:#{BUILT_GEM_ROOT}",
|
21
|
+
"PATH" => "#{gem_bin_path}:#{ENV['PATH']}"
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def cd(directory)
|
26
|
+
@cwd = directory
|
27
|
+
end
|
28
|
+
|
29
|
+
def run(command)
|
30
|
+
@output = "#{command}\n"
|
31
|
+
|
32
|
+
FileUtils.cd(@cwd) do
|
33
|
+
cmdline = "#{environment_settings} #{command} 2>&1"
|
34
|
+
logger.debug(cmdline)
|
35
|
+
result = `#{cmdline}`
|
36
|
+
logger.debug(result)
|
37
|
+
output << result
|
38
|
+
@result = clean(result)
|
39
|
+
end
|
40
|
+
|
41
|
+
@status = $?
|
42
|
+
end
|
43
|
+
|
44
|
+
def clean(content)
|
45
|
+
content.split("\n").reject { |line| line.match('deprecated') }.join("\n")
|
46
|
+
end
|
47
|
+
|
48
|
+
def echo(string)
|
49
|
+
logger.debug(string)
|
50
|
+
end
|
51
|
+
|
52
|
+
def build_and_install(gemspec)
|
53
|
+
pkg_dir = File.join(TEMP_DIR, 'pkg')
|
54
|
+
FileUtils.mkdir_p(pkg_dir)
|
55
|
+
|
56
|
+
output = `gem build #{gemspec} 2>&1`
|
57
|
+
gem_file = Dir.glob("*.gem").first
|
58
|
+
unless gem_file
|
59
|
+
raise "Gem didn't build:\n#{output}"
|
60
|
+
end
|
61
|
+
|
62
|
+
target = File.join(pkg_dir, gem_file)
|
63
|
+
FileUtils.mv(gem_file, target)
|
64
|
+
install_to(BUILT_GEM_ROOT, target)
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def install_to(root, gem)
|
71
|
+
`gem install -i #{root} --no-ri --no-rdoc #{gem}` # textmate!! `
|
72
|
+
end
|
73
|
+
|
74
|
+
def environment_settings
|
75
|
+
@environment_variables.map { |key, value| "#{key}=#{value}" }.join(' ')
|
76
|
+
end
|
77
|
+
|
78
|
+
def gem_bin_path
|
79
|
+
File.join(LOCAL_GEM_ROOT, "bin")
|
80
|
+
end
|
81
|
+
|
82
|
+
attr_reader :logger
|
83
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'engine-assets'
|
data/lib/engine-assets.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
|
-
module EngineAssets
|
1
|
+
module EngineAssets
|
2
|
+
class << self
|
3
|
+
def version
|
4
|
+
IO.read(File.join(File.dirname(__FILE__), '..', 'VERSION')).strip
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
2
8
|
|
3
|
-
require '
|
9
|
+
require 'engine_assets/engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
|
4
10
|
require 'engine_assets/public_locator'
|
5
11
|
require 'engine_assets/extensions/rails/assets'
|
@@ -1,3 +1,9 @@
|
|
1
|
+
# TODO:
|
2
|
+
# * find a mechanism to do this without monkey-patching Rails
|
3
|
+
# * add an autoload option to load all from plugins, or similar
|
4
|
+
# * allow engines to indicate (automatically when #register is called?)
|
5
|
+
# which assets to include.
|
6
|
+
|
1
7
|
module ActionView::Helpers::AssetTagHelper
|
2
8
|
def expand_javascript_sources_with_engine_assets(sources, recursive = false)
|
3
9
|
if sources.include?(:all)
|
@@ -2,20 +2,35 @@ class EngineAssets::PublicLocator
|
|
2
2
|
class << self
|
3
3
|
attr_reader :paths
|
4
4
|
|
5
|
+
# TODO: expose this as EngineAssets.register(...)
|
5
6
|
def register(full_path)
|
6
|
-
|
7
|
+
raise ArgumentError unless File.exist?(full_path)
|
7
8
|
|
9
|
+
@paths ||= []
|
8
10
|
public_path = File.join(full_path, 'public')
|
9
|
-
File.open(public_path) {}
|
10
11
|
|
11
|
-
|
12
|
+
if File.exist?(public_path)
|
13
|
+
# TODO:
|
14
|
+
# * spec me
|
15
|
+
# * split me into separate implementations
|
16
|
+
|
17
|
+
if defined?(Rails) && Rails::VERSION::MAJOR == 3
|
18
|
+
# Rails 3
|
19
|
+
Rails.configuration.middleware.use ::ActionDispatch::Static, public_path
|
20
|
+
else
|
21
|
+
# Rails 2
|
22
|
+
paths << public_path
|
23
|
+
end
|
24
|
+
end
|
12
25
|
end
|
13
26
|
|
14
27
|
def locate(file_path)
|
15
|
-
full_paths = paths.map { |base_path| File.join(base_path, file_path) }
|
28
|
+
full_paths = (paths || []).map { |base_path| File.join(base_path, file_path) }
|
29
|
+
|
16
30
|
full_paths.each do |full_path|
|
17
31
|
return full_path if File.exist?(full_path)
|
18
32
|
end
|
33
|
+
|
19
34
|
nil
|
20
35
|
end
|
21
36
|
|
@@ -23,7 +38,7 @@ class EngineAssets::PublicLocator
|
|
23
38
|
private
|
24
39
|
|
25
40
|
def clear
|
26
|
-
@paths =
|
41
|
+
@paths = nil
|
27
42
|
end
|
28
43
|
end
|
29
44
|
end
|
@@ -5,7 +5,7 @@ describe EngineAssets::PublicLocator do
|
|
5
5
|
|
6
6
|
before do
|
7
7
|
@base_path = File.join('fixtures', 'public')
|
8
|
-
@full_path = File.join(
|
8
|
+
@full_path = File.join(SPEC_DIR, 'support', 'fixtures')
|
9
9
|
@find_path = '/javascripts/dual.js'
|
10
10
|
@miss_path = '/javascripts/miss.js'
|
11
11
|
|
@@ -18,16 +18,30 @@ describe EngineAssets::PublicLocator do
|
|
18
18
|
it "raises an exception" do
|
19
19
|
lambda {
|
20
20
|
EngineAssets::PublicLocator.register('bogus')
|
21
|
-
}.should raise_error(
|
21
|
+
}.should raise_error(ArgumentError)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
context "when the suggest path does not contain a 'public' directory" do
|
26
|
-
|
26
|
+
before do
|
27
|
+
EngineAssets::PublicLocator.send(:clear)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "does not raise an exception" do
|
27
31
|
lambda {
|
28
32
|
EngineAssets::PublicLocator.register(File.dirname(__FILE__))
|
29
|
-
}.
|
33
|
+
}.should_not raise_error
|
30
34
|
end
|
35
|
+
|
36
|
+
it "does not add the path" do
|
37
|
+
EngineAssets::PublicLocator.register(File.dirname(__FILE__))
|
38
|
+
EngineAssets::PublicLocator.paths.should be_empty
|
39
|
+
end
|
40
|
+
# it "raises an exception" do
|
41
|
+
# lambda {
|
42
|
+
# EngineAssets::PublicLocator.register(File.dirname(__FILE__))
|
43
|
+
# }.should raise_error(Errno::ENOENT)
|
44
|
+
# end
|
31
45
|
end
|
32
46
|
|
33
47
|
context "when the suggest path is valid" do
|
@@ -49,5 +63,15 @@ describe EngineAssets::PublicLocator do
|
|
49
63
|
EngineAssets::PublicLocator.locate(miss_path).should be_nil
|
50
64
|
end
|
51
65
|
end
|
66
|
+
|
67
|
+
context "when no asset-providing engines have registered" do
|
68
|
+
before do
|
69
|
+
EngineAssets::PublicLocator.send(:clear)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "returns nil" do
|
73
|
+
EngineAssets::PublicLocator.locate(miss_path).should be_nil
|
74
|
+
end
|
75
|
+
end
|
52
76
|
end
|
53
77
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
begin
|
4
|
+
shared_examples_for "A controller acting as an AssetsController" do
|
5
|
+
# describe "A controller acting as an AssetsController", :shared => true do
|
6
|
+
attr_reader :format
|
7
|
+
|
8
|
+
integrate_views
|
9
|
+
|
10
|
+
before do
|
11
|
+
load_view_fixtures(@controller.class)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "response" do
|
15
|
+
context "with a matching file found in 'public'" do
|
16
|
+
it "renders that file" do
|
17
|
+
get :show, :path => 'dual', :format => format
|
18
|
+
response.body.should match("dual.#{format}, should be rendered")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "with a matching file found in 'app'" do
|
23
|
+
it "renders that file" do
|
24
|
+
get :show, :path => 'solo', :format => format
|
25
|
+
response.body.should match("solo.#{format}.erb, should be rendered")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "without a matching file" do
|
30
|
+
it "renders 404" do
|
31
|
+
get :show, :path => 'none', :format => format
|
32
|
+
response.response_code.should == 404
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
rescue ArgumentError
|
38
|
+
puts "WARNING: #{__FILE__}:#{__LINE__} trying to load this file twice, for some reason"
|
39
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
begin
|
4
|
+
shared_examples_for "A controller routed as an AssetsController" do
|
5
|
+
# describe "A controller routed as an AssetsController", :shared => true do
|
6
|
+
attr_reader :prefix, :format
|
7
|
+
|
8
|
+
describe "routing" do
|
9
|
+
attr_reader :path, :route
|
10
|
+
|
11
|
+
context "given a simple path" do
|
12
|
+
before do
|
13
|
+
@path = "/#{prefix}/asset.#{format}"
|
14
|
+
@route = { :controller => "engine_assets/#{prefix}", :action => 'show', :path => 'asset', :format => format }
|
15
|
+
end
|
16
|
+
|
17
|
+
it "recognizes the path" do
|
18
|
+
params_from(:get, path).should == route
|
19
|
+
end
|
20
|
+
|
21
|
+
it "generates the path from a URL helper" do
|
22
|
+
send("#{prefix}_path", :asset, :format => format).should == path
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "given a complex path of nested directories" do
|
27
|
+
before do
|
28
|
+
@path = "/#{prefix}/path/to/asset.#{format}"
|
29
|
+
@route = { :controller => "engine_assets/#{prefix}", :action => 'show', :path => 'path/to/asset', :format => format }
|
30
|
+
end
|
31
|
+
|
32
|
+
it "recognizes the path" do
|
33
|
+
params_from(:get, path).should == route
|
34
|
+
end
|
35
|
+
|
36
|
+
it "generates the path from a URL helper" do
|
37
|
+
CGI.unescape(send("#{prefix}_path", 'path/to/asset', :format => format)).should == CGI.unescape(path)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "given a complex path of dotted components" do
|
42
|
+
before do
|
43
|
+
@path = "/#{prefix}/path.to/asset.one.#{format}"
|
44
|
+
@route = { :controller => "engine_assets/#{prefix}", :action => 'show', :path => 'path.to/asset.one', :format => format }
|
45
|
+
end
|
46
|
+
|
47
|
+
it "recognizes the path" do
|
48
|
+
params_from(:get, path).should == route
|
49
|
+
end
|
50
|
+
|
51
|
+
it "generates the path from a URL helper" do
|
52
|
+
CGI.unescape(send("#{prefix}_path", 'path.to/asset.one', :format => format)).should == CGI.unescape(path)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
rescue ArgumentError
|
58
|
+
puts "WARNING: #{__FILE__}:#{__LINE__} trying to load this file twice, for some reason"
|
59
|
+
end
|
data/spec/spec.opts
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,35 +1,74 @@
|
|
1
|
-
|
2
|
-
RAILS_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'vanilla'))
|
1
|
+
require 'rubygems'
|
3
2
|
|
4
|
-
|
5
|
-
|
3
|
+
unless defined?(PROJECT_ROOT)
|
4
|
+
PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze
|
5
|
+
SPEC_DIR = File.join(PROJECT_ROOT, 'spec').freeze
|
6
|
+
TEMP_DIR = File.join(PROJECT_ROOT, 'tmp').freeze
|
7
|
+
BUILT_GEM_ROOT = File.join(TEMP_DIR, 'built_gems').freeze
|
8
|
+
LOCAL_GEM_ROOT = File.join(TEMP_DIR, 'local_gems').freeze
|
9
|
+
WEBAPP_ROOT = File.join(TEMP_DIR, 'rails_root').freeze
|
10
|
+
end
|
6
11
|
|
7
|
-
|
8
|
-
Dir[File.expand_path(File.join(*segments))].each { |file| require file }
|
9
|
-
end
|
12
|
+
Dir[File.join(SPEC_DIR, 'support', '**', '*.rb')].each { |f| require f }
|
10
13
|
|
11
|
-
|
14
|
+
unless @webapp
|
15
|
+
ENV["RAILS_ENV"] ||= 'test'
|
12
16
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
@webapp = Support::Rails.new(ENV['RAILS_VERSION'])
|
18
|
+
@webapp.build
|
19
|
+
@webapp.setup
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'lib/engine-assets'
|
23
|
+
%w(app config).each do |dir|
|
24
|
+
Dir[File.join(PROJECT_ROOT, dir, '**', '*.rb')].each { |f| require f }
|
25
|
+
end
|
26
|
+
|
27
|
+
Dir[File.join(SPEC_DIR, 'shared', '**', '*.rb')].each { |f| require f }
|
20
28
|
|
21
|
-
|
29
|
+
begin
|
30
|
+
# RSpec 1.3 (Rails 2)
|
31
|
+
require 'spec/rails'
|
32
|
+
require 'spec/autorun'
|
33
|
+
require 'rr'
|
22
34
|
|
23
35
|
Spec::Runner.configure do |config|
|
24
36
|
include Support::Helpers
|
25
37
|
|
26
|
-
config.fixture_path =
|
38
|
+
config.fixture_path = File.join(SPEC_DIR, 'support', 'fixtures')
|
27
39
|
config.mock_with :rr
|
28
|
-
|
29
|
-
|
40
|
+
end
|
41
|
+
rescue LoadError
|
42
|
+
# RSpec 2.0 (Rails 3)
|
43
|
+
require 'rspec'
|
44
|
+
require 'rspec/rails'
|
45
|
+
require 'rr'
|
46
|
+
|
47
|
+
RSpec.configure do |config|
|
48
|
+
include Support::Helpers
|
30
49
|
|
31
|
-
|
32
|
-
|
33
|
-
end
|
50
|
+
# config.fixture_path = File.join(SPEC_DIR, 'support', 'fixtures')
|
51
|
+
config.mock_framework = :rr
|
34
52
|
end
|
35
53
|
end
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
# begin
|
58
|
+
# # RSpec 1.3 (Rails 2)
|
59
|
+
# require 'spec/rails'
|
60
|
+
# require 'spec/autorun'
|
61
|
+
# rescue LoadError
|
62
|
+
# # RSpec 2.0 (Rails 3)
|
63
|
+
# require 'rspec'
|
64
|
+
# require 'rspec/rails'
|
65
|
+
# end
|
66
|
+
#
|
67
|
+
# Dir[File.join(SPEC_DIR, 'shared', '**', '*.rb')].each { |f| require f }
|
68
|
+
#
|
69
|
+
# Spec::Runner.configure do |config|
|
70
|
+
# include Support::Helpers
|
71
|
+
#
|
72
|
+
# config.fixture_path = File.join(SPEC_DIR, 'support', 'fixtures')
|
73
|
+
# config.mock_with :rr
|
74
|
+
# end
|