engine-assets 0.1.0 → 0.2.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/Rakefile +4 -0
- data/VERSION +1 -1
- data/app/controllers/engine_assets/assets_controller.rb +9 -0
- data/config/routes.rb +7 -3
- data/engine-assets.gemspec +71 -0
- data/lib/engine-assets.rb +1 -0
- data/lib/engine_assets/public_locator.rb +15 -0
- data/rails/init.rb +13 -0
- data/spec/routing/javascripts_routing_spec.rb +30 -5
- metadata +3 -1
    
        data/Rakefile
    CHANGED
    
    | @@ -11,6 +11,10 @@ begin | |
| 11 11 | 
             
                gem.homepage    = "http://github.com/coreyti/engine-assets"
         | 
| 12 12 | 
             
                gem.authors     = ["Corey Innis"]
         | 
| 13 13 | 
             
                gem.add_development_dependency "rspec", ">= 1.2.9"
         | 
| 14 | 
            +
                gem.files      += Dir['app/**/*.rb']
         | 
| 15 | 
            +
                gem.files      += Dir['lib/**/*.rb']
         | 
| 16 | 
            +
                gem.files.uniq!  # TODO (CTI): figure out why I'm having to do this manipulation.
         | 
| 17 | 
            +
             | 
| 14 18 | 
             
                # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
         | 
| 15 19 | 
             
              end
         | 
| 16 20 | 
             
              Jeweler::GemcutterTasks.new
         | 
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0. | 
| 1 | 
            +
            0.2.0
         | 
| @@ -5,6 +5,15 @@ class EngineAssets::AssetsController < ApplicationController | |
| 5 5 | 
             
              before_filter :expire, :set_headers
         | 
| 6 6 | 
             
              after_filter  :cache
         | 
| 7 7 |  | 
| 8 | 
            +
              def show
         | 
| 9 | 
            +
                flat_file = EngineAssets::PublicLocator.locate(File.join(controller_name, [params[:path], params[:format]].join('.')))
         | 
| 10 | 
            +
                if(flat_file)
         | 
| 11 | 
            +
                  render(:file => flat_file)
         | 
| 12 | 
            +
                else
         | 
| 13 | 
            +
                  render(:template => File.join('engine_assets', controller_name, params[:path]), :layout => false)
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
             | 
| 8 17 |  | 
| 9 18 | 
             
              private
         | 
| 10 19 |  | 
    
        data/config/routes.rb
    CHANGED
    
    | @@ -1,5 +1,9 @@ | |
| 1 1 | 
             
            ActionController::Routing::Routes.draw do |map|
         | 
| 2 | 
            -
               | 
| 3 | 
            -
             | 
| 4 | 
            -
             | 
| 2 | 
            +
              [:javascripts, :stylesheets].each do |type|
         | 
| 3 | 
            +
                map.send(type, "#{type}/:path.:format", {
         | 
| 4 | 
            +
                  :controller => "engine_assets/#{type}",
         | 
| 5 | 
            +
                  :action     => :show,
         | 
| 6 | 
            +
                  :path       => /[A-Za-z0-9\/_-]+/   # e.g., path/to/file.ext
         | 
| 7 | 
            +
                })
         | 
| 8 | 
            +
              end
         | 
| 5 9 | 
             
            end
         | 
| @@ -0,0 +1,71 @@ | |
| 1 | 
            +
            # Generated by jeweler
         | 
| 2 | 
            +
            # DO NOT EDIT THIS FILE DIRECTLY
         | 
| 3 | 
            +
            # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
         | 
| 4 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            Gem::Specification.new do |s|
         | 
| 7 | 
            +
              s.name = %q{engine-assets}
         | 
| 8 | 
            +
              s.version = "0.2.0"
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         | 
| 11 | 
            +
              s.authors = ["Corey Innis"]
         | 
| 12 | 
            +
              s.date = %q{2009-11-06}
         | 
| 13 | 
            +
              s.description = %q{A Rails Engine, which enables Rails Engines to provide assets (javascript, css and images)}
         | 
| 14 | 
            +
              s.email = %q{support@coolerator.net}
         | 
| 15 | 
            +
              s.extra_rdoc_files = [
         | 
| 16 | 
            +
                "LICENSE",
         | 
| 17 | 
            +
                 "README.rdoc"
         | 
| 18 | 
            +
              ]
         | 
| 19 | 
            +
              s.files = [
         | 
| 20 | 
            +
                ".document",
         | 
| 21 | 
            +
                 ".gitignore",
         | 
| 22 | 
            +
                 "LICENSE",
         | 
| 23 | 
            +
                 "README.rdoc",
         | 
| 24 | 
            +
                 "Rakefile",
         | 
| 25 | 
            +
                 "TODO.md",
         | 
| 26 | 
            +
                 "VERSION",
         | 
| 27 | 
            +
                 "app/controllers/engine_assets/assets_controller.rb",
         | 
| 28 | 
            +
                 "app/controllers/engine_assets/javascripts_controller.rb",
         | 
| 29 | 
            +
                 "app/controllers/engine_assets/stylesheets_controller.rb",
         | 
| 30 | 
            +
                 "config/routes.rb",
         | 
| 31 | 
            +
                 "engine-assets.gemspec",
         | 
| 32 | 
            +
                 "lib/engine-assets.rb",
         | 
| 33 | 
            +
                 "lib/engine_assets/extensions/rails/routes.rb",
         | 
| 34 | 
            +
                 "lib/engine_assets/public_locator.rb",
         | 
| 35 | 
            +
                 "rails/init.rb",
         | 
| 36 | 
            +
                 "spec/routing/javascripts_routing_spec.rb",
         | 
| 37 | 
            +
                 "spec/routing/stylesheets_routing_spec.rb",
         | 
| 38 | 
            +
                 "spec/spec.opts",
         | 
| 39 | 
            +
                 "spec/spec_helper.rb",
         | 
| 40 | 
            +
                 "spec/spec_suite.rb",
         | 
| 41 | 
            +
                 "spec/support/fixtures/app/views/javascripts/asset.js.erb",
         | 
| 42 | 
            +
                 "spec/support/fixtures/public/javascripts/asset.js",
         | 
| 43 | 
            +
                 "spec/support/helpers/textmate_helper.rb"
         | 
| 44 | 
            +
              ]
         | 
| 45 | 
            +
              s.homepage = %q{http://github.com/coreyti/engine-assets}
         | 
| 46 | 
            +
              s.rdoc_options = ["--charset=UTF-8"]
         | 
| 47 | 
            +
              s.require_paths = ["lib"]
         | 
| 48 | 
            +
              s.rubygems_version = %q{1.3.5}
         | 
| 49 | 
            +
              s.summary = %q{Rails Engines with assets.}
         | 
| 50 | 
            +
              s.test_files = [
         | 
| 51 | 
            +
                "spec/routing/javascripts_routing_spec.rb",
         | 
| 52 | 
            +
                 "spec/routing/stylesheets_routing_spec.rb",
         | 
| 53 | 
            +
                 "spec/spec_helper.rb",
         | 
| 54 | 
            +
                 "spec/spec_suite.rb",
         | 
| 55 | 
            +
                 "spec/support/helpers/textmate_helper.rb"
         | 
| 56 | 
            +
              ]
         | 
| 57 | 
            +
             | 
| 58 | 
            +
              if s.respond_to? :specification_version then
         | 
| 59 | 
            +
                current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
         | 
| 60 | 
            +
                s.specification_version = 3
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
         | 
| 63 | 
            +
                  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
         | 
| 64 | 
            +
                else
         | 
| 65 | 
            +
                  s.add_dependency(%q<rspec>, [">= 1.2.9"])
         | 
| 66 | 
            +
                end
         | 
| 67 | 
            +
              else
         | 
| 68 | 
            +
                s.add_dependency(%q<rspec>, [">= 1.2.9"])
         | 
| 69 | 
            +
              end
         | 
| 70 | 
            +
            end
         | 
| 71 | 
            +
             | 
    
        data/lib/engine-assets.rb
    CHANGED
    
    
| @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            class EngineAssets::PublicLocator
         | 
| 2 | 
            +
              class << self
         | 
| 3 | 
            +
                def paths
         | 
| 4 | 
            +
                  @paths ||= []
         | 
| 5 | 
            +
                end
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                def locate(file_path)
         | 
| 8 | 
            +
                  full_paths = paths.map { |base_path| File.join(base_path, file_path) }
         | 
| 9 | 
            +
                  full_paths.each do |full_path|
         | 
| 10 | 
            +
                    return full_path if File.exist?(full_path)
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
                  nil
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
            end
         | 
    
        data/rails/init.rb
    CHANGED
    
    | @@ -5,3 +5,16 @@ require 'engine-assets' | |
| 5 5 | 
             
            require 'controllers/engine_assets/assets_controller'
         | 
| 6 6 | 
             
            require 'controllers/engine_assets/javascripts_controller'
         | 
| 7 7 | 
             
            require 'controllers/engine_assets/stylesheets_controller'
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            class Rails::Plugin
         | 
| 10 | 
            +
              class Loader
         | 
| 11 | 
            +
                def register_plugin_as_loaded_with_engine_assets(plugin)
         | 
| 12 | 
            +
                  register_plugin_as_loaded_without_engine_assets(plugin)
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  if(plugin.engine? && File.exist?(public_dir = File.join(plugin.directory, 'public')))
         | 
| 15 | 
            +
                    EngineAssets::PublicLocator.paths << public_dir
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
                alias_method_chain :register_plugin_as_loaded, :engine_assets
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
            end
         | 
| @@ -2,12 +2,37 @@ require 'spec_helper' | |
| 2 2 |  | 
| 3 3 | 
             
            describe EngineAssets::JavascriptsController do
         | 
| 4 4 | 
             
              describe "routing" do
         | 
| 5 | 
            -
                 | 
| 6 | 
            -
             | 
| 5 | 
            +
                attr_reader :path
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                context "given a simple path" do
         | 
| 8 | 
            +
                  before do
         | 
| 9 | 
            +
                    @path = '/javascripts/asset.js'
         | 
| 10 | 
            +
                  end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  it "is able to recognize the path" do
         | 
| 13 | 
            +
                    pending "my ability to overcome the challenges of spec'ing this working behavior"
         | 
| 14 | 
            +
                    { :get => path }.should be_routable
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  it "is able to generate the path" do
         | 
| 18 | 
            +
                    javascripts_path(:asset, :format => :js).should == path
         | 
| 19 | 
            +
                  end
         | 
| 7 20 | 
             
                end
         | 
| 8 | 
            -
             | 
| 9 | 
            -
                 | 
| 10 | 
            -
                   | 
| 21 | 
            +
             | 
| 22 | 
            +
                context "given a complex path" do
         | 
| 23 | 
            +
                  before do
         | 
| 24 | 
            +
                    @path = '/javascripts/path/to/asset.js'
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                  it "is able to recognize the path" do
         | 
| 28 | 
            +
                    pending "my ability to overcome the challenges of spec'ing this working behavior"
         | 
| 29 | 
            +
                    { :get => path }.should be_routable
         | 
| 30 | 
            +
                  end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                  it "is able to generate the path" do
         | 
| 33 | 
            +
                    pending "my ability to overcome the challenges of spec'ing this working behavior"
         | 
| 34 | 
            +
                    javascripts_path('path/to/asset', :format => :js).should == path
         | 
| 35 | 
            +
                  end
         | 
| 11 36 | 
             
                end
         | 
| 12 37 | 
             
              end
         | 
| 13 38 | 
             
            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. | 
| 4 | 
            +
              version: 0.2.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors: 
         | 
| 7 7 | 
             
            - Corey Innis
         | 
| @@ -43,8 +43,10 @@ files: | |
| 43 43 | 
             
            - app/controllers/engine_assets/javascripts_controller.rb
         | 
| 44 44 | 
             
            - app/controllers/engine_assets/stylesheets_controller.rb
         | 
| 45 45 | 
             
            - config/routes.rb
         | 
| 46 | 
            +
            - engine-assets.gemspec
         | 
| 46 47 | 
             
            - lib/engine-assets.rb
         | 
| 47 48 | 
             
            - lib/engine_assets/extensions/rails/routes.rb
         | 
| 49 | 
            +
            - lib/engine_assets/public_locator.rb
         | 
| 48 50 | 
             
            - rails/init.rb
         | 
| 49 51 | 
             
            - spec/routing/javascripts_routing_spec.rb
         | 
| 50 52 | 
             
            - spec/routing/stylesheets_routing_spec.rb
         |