engine-assets 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/TODO.md CHANGED
@@ -1,4 +1,6 @@
1
1
 
2
2
  * support@coolerator.net
3
3
  * Visit http://github.com/coreyti/engine-assets/edit and click 'Enable RubyGems'
4
+ * from AssetTagHelper:
5
+ `collect_asset_files(JAVASCRIPTS_DIR, ('**' if recursive), '*.js')`
4
6
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{engine-assets}
8
- s.version = "0.2.1"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Corey Innis"]
12
- s.date = %q{2009-11-07}
12
+ s.date = %q{2009-11-08}
13
13
  s.description = %q{A Rails Engine, which enables Rails Engines to provide assets (javascript, css and images)}
14
14
  s.email = %q{support@coolerator.net}
15
15
  s.extra_rdoc_files = [
@@ -30,12 +30,16 @@ Gem::Specification.new do |s|
30
30
  "config/routes.rb",
31
31
  "engine-assets.gemspec",
32
32
  "lib/engine-assets.rb",
33
- "lib/engine_assets/extensions/rails/plugin.rb",
33
+ "lib/engine_assets/extensions/rails/assets.rb",
34
+ "lib/engine_assets/extensions/rails/plugins.rb",
34
35
  "lib/engine_assets/extensions/rails/routes.rb",
35
36
  "lib/engine_assets/public_locator.rb",
36
37
  "rails/init.rb",
37
38
  "spec/controllers/javascripts_controller_spec.rb",
38
39
  "spec/controllers/stylesheets_controller_spec.rb",
40
+ "spec/lib/engine_assets/extensions/rails/plugins_spec.rb",
41
+ "spec/lib/engine_assets/extensions/rails/routes_spec.rb",
42
+ "spec/lib/engine_assets/public_locator_spec.rb",
39
43
  "spec/routing/javascripts_routing_spec.rb",
40
44
  "spec/routing/stylesheets_routing_spec.rb",
41
45
  "spec/spec.opts",
@@ -60,6 +64,9 @@ Gem::Specification.new do |s|
60
64
  s.test_files = [
61
65
  "spec/controllers/javascripts_controller_spec.rb",
62
66
  "spec/controllers/stylesheets_controller_spec.rb",
67
+ "spec/lib/engine_assets/extensions/rails/plugins_spec.rb",
68
+ "spec/lib/engine_assets/extensions/rails/routes_spec.rb",
69
+ "spec/lib/engine_assets/public_locator_spec.rb",
63
70
  "spec/routing/javascripts_routing_spec.rb",
64
71
  "spec/routing/stylesheets_routing_spec.rb",
65
72
  "spec/spec_helper.rb",
data/lib/engine-assets.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  module EngineAssets ; end
2
2
 
3
3
  require 'engine_assets/public_locator'
4
- require 'engine_assets/extensions/rails/plugin'
4
+ require 'engine_assets/extensions/rails/assets'
5
+ require 'engine_assets/extensions/rails/plugins'
5
6
  require 'engine_assets/extensions/rails/routes'
@@ -0,0 +1,15 @@
1
+ module ActionView::Helpers::AssetTagHelper
2
+ def expand_javascript_sources(sources, recursive = false)
3
+ if sources.include?(:all)
4
+ all_javascript_files = collect_asset_files(JAVASCRIPTS_DIR, ('**' if recursive), '*.js')
5
+ result = ((determine_source(:defaults, @@javascript_expansions).dup) + all_javascript_files).uniq
6
+ result
7
+ else
8
+ expanded_sources = sources.collect do |source|
9
+ determine_source(source, @@javascript_expansions)
10
+ end.flatten
11
+ expanded_sources << "application" if sources.include?(:defaults) && File.exist?(File.join(JAVASCRIPTS_DIR, "application.js"))
12
+ expanded_sources
13
+ end
14
+ end
15
+ end
@@ -1,5 +1,4 @@
1
1
  if defined?(ActionController::Routing::RouteSet)
2
-
3
2
  class ActionController::Routing::RouteSet
4
3
  def load_routes_with_assets!
5
4
  lib_path = File.dirname(__FILE__)
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rails::Plugin::Loader do
4
+ attr_reader :loader, :plugin, :directory
5
+
6
+ before do
7
+ @loader = Rails::Plugin::Loader.new(OpenStruct.new({ :loaded_plugins => [] }))
8
+ end
9
+
10
+ describe "#register_plugin_as_loaded" do
11
+ before do
12
+ paths = []
13
+ stub(EngineAssets::PublicLocator).paths { paths }
14
+ end
15
+
16
+ context "given a plugin which is an engine and contains a 'public' directory" do
17
+ before do
18
+ @directory = File.join(basedir, 'spec', 'support', 'fixtures')
19
+ @plugin = OpenStruct.new({ :engine? => true, :directory => directory })
20
+ end
21
+
22
+ it "registers the plugin with the EngineAssets::PublicLocator" do
23
+ loader.send(:register_plugin_as_loaded, plugin)
24
+ EngineAssets::PublicLocator.paths.should == [ "#{directory}/public" ]
25
+ end
26
+ end
27
+
28
+ context "given a plugin which is an engine and does NOT contain a 'public' directory" do
29
+ before do
30
+ @directory = basedir
31
+ @plugin = OpenStruct.new({ :engine? => true, :directory => directory })
32
+ end
33
+
34
+ it "does not register the plugin with the EngineAssets::PublicLocator" do
35
+ loader.send(:register_plugin_as_loaded, plugin)
36
+ EngineAssets::PublicLocator.paths.should == []
37
+ end
38
+ end
39
+
40
+ context "given a plugin which is NOT an engine" do
41
+ before do
42
+ @directory = File.join(basedir, 'spec', 'support', 'fixtures')
43
+ @plugin = OpenStruct.new({ :engine? => false, :directory => directory })
44
+ end
45
+
46
+ it "does not register the plugin with the EngineAssets::PublicLocator" do
47
+ loader.send(:register_plugin_as_loaded, plugin)
48
+ EngineAssets::PublicLocator.paths.should == []
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActionController::Routing::RouteSet do
4
+ describe "#load_routes!" do
5
+ class TestRouteSet < ActionController::Routing::RouteSet
6
+ attr_reader :configuration_files
7
+
8
+ def initialize
9
+ @configuration_files = []
10
+ end
11
+
12
+ def add_configuration_file(routes)
13
+ configuration_files << routes
14
+ end
15
+ end
16
+
17
+ attr_reader :routeset
18
+
19
+ before do
20
+ @routeset = TestRouteSet.new
21
+ end
22
+
23
+ it "adds the engine-assets routes configuration" do
24
+ routeset.load_routes!
25
+ routeset.configuration_files[0].should =~ /engine-assets.*\/config\/routes\.rb/
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe EngineAssets::PublicLocator do
4
+ attr_reader :base_path, :find_path, :miss_path
5
+
6
+ before do
7
+ @base_path = File.join(basedir, 'spec', 'support', 'fixtures', 'public')
8
+ @find_path = '/javascripts/dual.js'
9
+ @miss_path = '/javascripts/miss.js'
10
+
11
+ EngineAssets::PublicLocator.paths << base_path
12
+ end
13
+
14
+ describe "#locate" do
15
+ context "when the requested sub-path is located" do
16
+ it "returns the full path to the file" do
17
+ EngineAssets::PublicLocator.locate(find_path).should == File.join(base_path, find_path)
18
+ end
19
+ end
20
+
21
+ context "when the requested sub-path is not located" do
22
+ it "returns nil" do
23
+ EngineAssets::PublicLocator.locate(miss_path).should be_nil
24
+ end
25
+ end
26
+ end
27
+ end
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,10 @@ RAILS_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'van
3
3
  dir = File.dirname(__FILE__)
4
4
  $LOAD_PATH.unshift(dir)
5
5
 
6
+ def require_files(*segments)
7
+ Dir[File.expand_path(File.join(*segments))].each { |file| require file }
8
+ end
9
+
6
10
  ENV["RAILS_ENV"] = "test"
7
11
 
8
12
  require "#{File.join(RAILS_PATH, 'config', 'environment')}"
@@ -10,10 +14,8 @@ require 'engine-assets'
10
14
  require 'spec'
11
15
  require 'spec/autorun'
12
16
  require 'spec/rails'
13
- require 'support/helpers/fixture_helper'
14
- require 'support/helpers/textmate_helper'
15
- require 'support/shared/assets_controller_spec'
16
- require 'support/shared/assets_routing_spec'
17
+
18
+ require_files(dir, 'support', '**', '*.rb')
17
19
 
18
20
  Spec::Runner.configure do |config|
19
21
  include Support::Helpers
@@ -23,12 +25,7 @@ Spec::Runner.configure do |config|
23
25
  config.use_transactional_fixtures = true
24
26
  config.use_instantiated_fixtures = false
25
27
 
26
- # def add_fixture_views(controller_class)
27
- # controller_class.prepend_view_path(File.join(basepath, '..', 'fixtures', 'app', 'views'))
28
- # controller_class.prepend_view_path(File.join(basepath, '..', 'fixtures', 'public'))
29
- # end
30
- #
31
- # def basepath
32
- # @basepath ||= File.join(File.dirname(__FILE__), '..')
33
- # end
28
+ def basedir
29
+ @basedir ||= "#{File.expand_path(File.join(File.dirname(__FILE__), '..'))}"
30
+ end
34
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: engine-assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corey Innis
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-07 00:00:00 -05:00
12
+ date: 2009-11-08 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -45,12 +45,16 @@ files:
45
45
  - config/routes.rb
46
46
  - engine-assets.gemspec
47
47
  - lib/engine-assets.rb
48
- - lib/engine_assets/extensions/rails/plugin.rb
48
+ - lib/engine_assets/extensions/rails/assets.rb
49
+ - lib/engine_assets/extensions/rails/plugins.rb
49
50
  - lib/engine_assets/extensions/rails/routes.rb
50
51
  - lib/engine_assets/public_locator.rb
51
52
  - rails/init.rb
52
53
  - spec/controllers/javascripts_controller_spec.rb
53
54
  - spec/controllers/stylesheets_controller_spec.rb
55
+ - spec/lib/engine_assets/extensions/rails/plugins_spec.rb
56
+ - spec/lib/engine_assets/extensions/rails/routes_spec.rb
57
+ - spec/lib/engine_assets/public_locator_spec.rb
54
58
  - spec/routing/javascripts_routing_spec.rb
55
59
  - spec/routing/stylesheets_routing_spec.rb
56
60
  - spec/spec.opts
@@ -97,6 +101,9 @@ summary: Rails Engines with assets.
97
101
  test_files:
98
102
  - spec/controllers/javascripts_controller_spec.rb
99
103
  - spec/controllers/stylesheets_controller_spec.rb
104
+ - spec/lib/engine_assets/extensions/rails/plugins_spec.rb
105
+ - spec/lib/engine_assets/extensions/rails/routes_spec.rb
106
+ - spec/lib/engine_assets/public_locator_spec.rb
100
107
  - spec/routing/javascripts_routing_spec.rb
101
108
  - spec/routing/stylesheets_routing_spec.rb
102
109
  - spec/spec_helper.rb