asset_symlink 0.1.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.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.travis.yml +6 -0
  4. data/Gemfile +6 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +46 -0
  7. data/Rakefile +6 -0
  8. data/asset_symlink.gemspec +25 -0
  9. data/lib/asset_symlink/railtie.rb +11 -0
  10. data/lib/asset_symlink/tasks/symlink.rake +9 -0
  11. data/lib/asset_symlink/version.rb +3 -0
  12. data/lib/asset_symlink.rb +34 -0
  13. data/spec/asset_symlink_spec.rb +83 -0
  14. data/spec/dummy_app/README.rdoc +28 -0
  15. data/spec/dummy_app/Rakefile +6 -0
  16. data/spec/dummy_app/app/assets/images/.keep +0 -0
  17. data/spec/dummy_app/app/assets/javascripts/3rdparty/lib.js +1 -0
  18. data/spec/dummy_app/app/assets/javascripts/application.js +1 -0
  19. data/spec/dummy_app/app/assets/javascripts/test.js +1 -0
  20. data/spec/dummy_app/app/assets/stylesheets/application.css +15 -0
  21. data/spec/dummy_app/app/controllers/application_controller.rb +5 -0
  22. data/spec/dummy_app/app/controllers/concerns/.keep +0 -0
  23. data/spec/dummy_app/app/helpers/application_helper.rb +2 -0
  24. data/spec/dummy_app/app/mailers/.keep +0 -0
  25. data/spec/dummy_app/app/models/.keep +0 -0
  26. data/spec/dummy_app/app/models/concerns/.keep +0 -0
  27. data/spec/dummy_app/app/views/layouts/application.html.erb +14 -0
  28. data/spec/dummy_app/bin/bundle +3 -0
  29. data/spec/dummy_app/bin/rails +4 -0
  30. data/spec/dummy_app/bin/rake +4 -0
  31. data/spec/dummy_app/config/application.rb +25 -0
  32. data/spec/dummy_app/config/boot.rb +5 -0
  33. data/spec/dummy_app/config/database.yml +30 -0
  34. data/spec/dummy_app/config/environment.rb +6 -0
  35. data/spec/dummy_app/config/environments/development.rb +28 -0
  36. data/spec/dummy_app/config/environments/production.rb +83 -0
  37. data/spec/dummy_app/config/environments/test.rb +26 -0
  38. data/spec/dummy_app/config/initializers/backtrace_silencers.rb +7 -0
  39. data/spec/dummy_app/config/locales/en.yml +23 -0
  40. data/spec/dummy_app/config/routes.rb +56 -0
  41. data/spec/dummy_app/config.ru +4 -0
  42. data/spec/dummy_app/lib/assets/.keep +0 -0
  43. data/spec/dummy_app/log/.keep +0 -0
  44. data/spec/dummy_app/log/development.log +0 -0
  45. data/spec/integration_spec.rb +32 -0
  46. data/spec/spec_helper.rb +22 -0
  47. metadata +180 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f3714f6014d230d40e38200f915236038c45df97
4
+ data.tar.gz: 1dcd3af0933dc96c044bdbb56391e6a362f5a6d1
5
+ SHA512:
6
+ metadata.gz: 23b181838be6960c6daf80bf0b9dbe9eff561ddf3935e05902b3127278b6e00fbe4bef8eceb58bdfcac1dfdef86d1cb2ff030c9677768d35fc8162ba4cf4b832
7
+ data.tar.gz: 25f488b3fad600084e0356c2e381b484ca8da2b60546ae969463f21260b60362acf77601e91df7460439dbe1833a9a7788f9aa76b81de263693490e8452e0461
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ spec/dummy_app/public/*
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.1
5
+ install: bundle install
6
+ gemfile: Gemfile
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in asset_symlink.gemspec
4
+ gemspec
5
+
6
+ gem 'rails', '~>4.0.4'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Frederick Cheung
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # AssetSymlink
2
+
3
+ [![Build Status](https://travis-ci.org/fcheung/asset_symlink.png)](https://travis-ci.org/fcheung/asset_symlink)
4
+
5
+ Rails 4 and above only generate digested assets. From within your app this is a huge win, but it complicates things if you need to know the location of an asset from elsewhere.
6
+
7
+ This gem automates symlinking your digested assets to their public names. You can rely on the latest
8
+ version of the asset being available at a predictable location and these assets will continue to be
9
+ served by your web servers without hitting your rails instances.
10
+
11
+ Example use cases:
12
+ - images/css referenced from static html pages (eg 500.html)
13
+ - javascript you make available to 3rd parties
14
+
15
+ ## Installation
16
+
17
+ You only need to include this gem in the environment(s) that precompile your assets
18
+
19
+ ## Usage
20
+
21
+ After installing the gem you need to configure which digested assets are mapped to their public names and how. For example
22
+
23
+ config.asset_symlink = ['widgets.js']
24
+
25
+ would symlink `widgets.js` to `widgets-<digest>.js`
26
+
27
+ you can also specify an alternative public name, for example
28
+
29
+ config.asset_symlink = {'widgets.js' => 'v1/foo.js'}
30
+
31
+ would symlink `v1/foo.js` to `widgets-<digest>.js`
32
+
33
+ Lastly you can mix and match these, for example
34
+
35
+ config.asset_symlink = ['widgets.js', {'partner.js' => 'v1/partner.js'}]
36
+
37
+ symlinks `widgets.js` to `widgets-<digest>.js` and `v1/partner.js` to `partner-<digest>.js`
38
+
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it ( http://github.com/fcheung/asset_symlink/fork )
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new(:spec) do |t|
4
+ end
5
+
6
+ task :default => :spec
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'asset_symlink/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "asset_symlink"
8
+ spec.version = AssetSymlink::VERSION
9
+ spec.authors = ["Frederick Cheung"]
10
+ spec.email = ["frederick.cheung@gmail.com"]
11
+ spec.summary = %q{easily make assets available under a consistent public name}
12
+ spec.description = %q{easily make assets available under a consistent public name}
13
+ spec.homepage = "http://github.com/fcheung/asset_symlink"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "rails", "~>4.0"
22
+ spec.add_development_dependency "bundler", "~> 1.5"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec", "~>2.14.0"
25
+ end
@@ -0,0 +1,11 @@
1
+ require 'rails'
2
+
3
+ module AssetSymlink
4
+ class Railtie < Rails::Railtie
5
+ config.asset_symlink = nil
6
+
7
+ rake_tasks do
8
+ load "asset_symlink/tasks/symlink.rake"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ Rake::Task["assets:precompile"].enhance do
2
+ Rake::Task["asset_symlink:symlink"].invoke
3
+ end
4
+
5
+ namespace :asset_symlink do
6
+ task :symlink do
7
+ AssetSymlink.execute Rails.configuration.asset_symlink
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module AssetSymlink
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,34 @@
1
+ require "asset_symlink/version"
2
+ require "asset_symlink/railtie"
3
+ require 'fileutils'
4
+ module AssetSymlink
5
+ def self.execute config
6
+ normalize_configuration(config).each do |private_name, public_name|
7
+ digested_location = Rails.root.join('public','assets', Rails.application.assets.find_asset(private_name).digest_path)
8
+ public_location = Rails.root.join('public','assets',public_name)
9
+ if File.dirname(public_name) != '.'
10
+ FileUtils.mkdir_p(File.dirname(public_location))
11
+ end
12
+ digested_location = digested_location.relative_path_from(public_location.dirname)
13
+ FileUtils.ln_sf(digested_location, Rails.root.join('public','assets',public_name))
14
+ end
15
+ end
16
+
17
+
18
+ def self.normalize_configuration config
19
+ case config
20
+ when Hash
21
+ config
22
+ when String
23
+ {config => config}
24
+ when Array
25
+ config.inject({}) do |result, element|
26
+ result.merge(normalize_configuration(element))
27
+ end
28
+ when NilClass
29
+ {}
30
+ else
31
+ raise ArgumentError, "unexpected item #{config} in config.asset_symlink"
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+
3
+ describe AssetSymlink do
4
+
5
+ describe 'execute' do
6
+ let(:sandbox) {File.join(File.dirname(__FILE__),'..','tmp')}
7
+ let(:assets) {Pathname.new(sandbox).join('public', 'assets')}
8
+
9
+ before(:each) do
10
+ FileUtils.rm_rf assets, :secure => true
11
+ FileUtils.mkdir_p(assets)
12
+ @assets_stub = double()
13
+ Rails.stub_chain(:application,:assets => @assets_stub)
14
+ Rails.stub(:root).and_return(Pathname.new(sandbox))
15
+ end
16
+
17
+ def add_fake_asset(name, location)
18
+ @assets_stub.stub(:find_asset).with(name).and_return(double(:digest_path => location))
19
+ FileUtils.mkdir_p(assets.join(location).dirname)
20
+ File.open(assets.join(location), 'w'){}
21
+ end
22
+
23
+ it 'should symlink items at the top level of the assets folder' do
24
+ add_fake_asset('widget.js', 'widget-abc123.js')
25
+ AssetSymlink.execute('widget.js')
26
+ expect(assets.join('widget.js')).to be_a_symlink_to('widget-abc123.js')
27
+ end
28
+
29
+ it 'should create directories as needed' do
30
+ add_fake_asset('widget.js', 'widget-abc123.js')
31
+ AssetSymlink.execute('widget.js' => 'v1/foo.js')
32
+ expect(assets.join('v1','foo.js')).to be_a_symlink_to('../widget-abc123.js')
33
+ end
34
+
35
+ it 'should use relative links' do
36
+ add_fake_asset('external/widget.js', 'external/widget-abc123.js')
37
+ AssetSymlink.execute('external/widget.js')
38
+ expect(assets.join('external/widget.js')).to be_a_symlink_to('widget-abc123.js')
39
+ end
40
+
41
+ it 'should overwrite old symlinks' do
42
+ add_fake_asset('widget.js', 'widget-abc123.js')
43
+ File.symlink('widget-old.js', assets.join('widget.js'))
44
+
45
+ expect(assets.join('widget.js')).to be_a_symlink_to('widget-old.js')
46
+ AssetSymlink.execute('widget.js')
47
+ expect(assets.join('widget.js')).to be_a_symlink_to('widget-abc123.js')
48
+ end
49
+ end
50
+
51
+ describe 'normalize_configuration' do
52
+ it 'should convert a nil configuration to {}' do
53
+ AssetSymlink.normalize_configuration(nil).should == {}
54
+ end
55
+
56
+ it 'should convert a single string to a 1 element hash' do
57
+ AssetSymlink.normalize_configuration('foo.js').should == {'foo.js' => 'foo.js'}
58
+ end
59
+
60
+ it 'should convert an array of strings to hashes' do
61
+ AssetSymlink.normalize_configuration(%w(foo.js bar.js)).should == {'foo.js' => 'foo.js', 'bar.js' => 'bar.js'}
62
+ end
63
+
64
+ it 'should return a hash configuration unchanged' do
65
+ AssetSymlink.normalize_configuration('foo.js' => 'bar.js').should == {'foo.js' => 'bar.js'}
66
+ end
67
+
68
+ it 'should convert an array of hashes by merging them' do
69
+ AssetSymlink.normalize_configuration([{'foo.js' => 'v1/foo.js'},
70
+ {'bar.js' => 'v1/bar.js'}]).should == {'foo.js' => 'v1/foo.js',
71
+ 'bar.js' => 'v1/bar.js'}
72
+ end
73
+
74
+ it 'should allow a mixture of strings and hashes' do
75
+ AssetSymlink.normalize_configuration(['foo.js', {'bar.js' => 'v1/bar.js'}]).
76
+ should == {'foo.js' => 'foo.js', 'bar.js' => 'v1/bar.js'}
77
+ end
78
+
79
+ it 'should raise on unexpected item in configuration' do
80
+ expect {AssetSymlink.normalize_configuration([1])}.to raise_error(ArgumentError)
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
File without changes
@@ -0,0 +1 @@
1
+ alert('3rd party js')
@@ -0,0 +1 @@
1
+ //= require test
@@ -0,0 +1 @@
1
+ alert('application.js')
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
File without changes
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,25 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+
4
+ require "sprockets/railtie"
5
+
6
+ Bundler.require(*Rails.groups)
7
+ require "asset_symlink"
8
+
9
+ module Dummy
10
+ class Application < Rails::Application
11
+ # Settings in config/environments/* take precedence over those specified here.
12
+ # Application configuration should go into files in config/initializers
13
+ # -- all .rb files in that directory are automatically loaded.
14
+
15
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
16
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
17
+ # config.time_zone = 'Central Time (US & Canada)'
18
+
19
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
20
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
21
+ # config.i18n.default_locale = :de
22
+ config.assets.precompile += ['3rdparty/lib.js']
23
+ config.asset_symlink = ['application.js', {'3rdparty/lib.js' => '3rdparty/all.js'}]
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
+ $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,30 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ #
7
+ default: &default
8
+ adapter: sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+
12
+ development:
13
+ <<: *default
14
+ database: db/development.sqlite3
15
+
16
+ # Warning: The database defined as "test" will be erased and
17
+ # re-generated from your development database when you run "rake".
18
+ # Do not set this db to the same as development or production.
19
+ test:
20
+ <<: *default
21
+ database: db/test.sqlite3
22
+
23
+ # Do not keep production credentials in the repository,
24
+ # instead read the configuration from the environment.
25
+ #
26
+ # Example:
27
+ # sqlite3://myuser:mypass@localhost/full/path/to/somedatabase
28
+ #
29
+ production:
30
+ url: <%= ENV["DATABASE_URL"] %>
@@ -0,0 +1,6 @@
1
+ # Load the Rails application.
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the Rails application.
5
+ Dummy::Application.initialize!
6
+
@@ -0,0 +1,28 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Do not eager load code on boot.
10
+ config.eager_load = false
11
+
12
+ # Show full error reports and disable caching.
13
+ config.consider_all_requests_local = true
14
+ # Debug mode disables concatenation and preprocessing of assets.
15
+ # This option may cause significant delays in view rendering with a large
16
+ # number of complex assets.
17
+ config.assets.debug = true
18
+
19
+ # Adds additional error checking when serving assets at runtime.
20
+ # Checks for improperly declared sprockets dependencies.
21
+ # Raises helpful error messages.
22
+ config.assets.raise_runtime_errors = true
23
+
24
+ config.log_level = :info
25
+ config.assets.logger = nil
26
+ # Raises error for missing translations
27
+ # config.action_view.raise_on_missing_translations = true
28
+ end
@@ -0,0 +1,83 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # Code is not reloaded between requests.
5
+ config.cache_classes = true
6
+
7
+ # Eager load code on boot. This eager loads most of Rails and
8
+ # your application in memory, allowing both threaded web servers
9
+ # and those relying on copy on write to perform better.
10
+ # Rake tasks automatically ignore this option for performance.
11
+ config.eager_load = true
12
+
13
+ # Full error reports are disabled and caching is turned on.
14
+ config.consider_all_requests_local = false
15
+ config.action_controller.perform_caching = true
16
+
17
+ # Enable Rack::Cache to put a simple HTTP cache in front of your application
18
+ # Add `rack-cache` to your Gemfile before enabling this.
19
+ # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
20
+ # config.action_dispatch.rack_cache = true
21
+
22
+ # Disable Rails's static asset server (Apache or nginx will already do this).
23
+ config.serve_static_assets = false
24
+
25
+ # Compress JavaScripts and CSS.
26
+ #config.assets.js_compressor = :uglifier
27
+ # config.assets.css_compressor = :sass
28
+
29
+ # Do not fallback to assets pipeline if a precompiled asset is missed.
30
+ config.assets.compile = false
31
+
32
+ # Generate digests for assets URLs.
33
+ config.assets.digest = true
34
+
35
+ # Version of your assets, change this if you want to expire all your assets.
36
+ config.assets.version = '1.0'
37
+
38
+ # Specifies the header that your server uses for sending files.
39
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
40
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
41
+
42
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
43
+ # config.force_ssl = true
44
+
45
+ # Set to :debug to see everything in the log.
46
+ config.log_level = :info
47
+
48
+ # Prepend all log lines with the following tags.
49
+ # config.log_tags = [ :subdomain, :uuid ]
50
+
51
+ # Use a different logger for distributed setups.
52
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
53
+
54
+ # Use a different cache store in production.
55
+ # config.cache_store = :mem_cache_store
56
+
57
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
58
+ # config.action_controller.asset_host = "http://assets.example.com"
59
+
60
+ # Precompile additional assets.
61
+ # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
62
+ # config.assets.precompile += %w( 3rdparty/lib.js )
63
+
64
+ # Ignore bad email addresses and do not raise email delivery errors.
65
+ # Set this to true and configure the email server for immediate delivery to raise delivery errors.
66
+ # config.action_mailer.raise_delivery_errors = false
67
+
68
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
69
+ # the I18n.default_locale when a translation cannot be found).
70
+ config.i18n.fallbacks = true
71
+
72
+ # Send deprecation notices to registered listeners.
73
+ config.active_support.deprecation = :notify
74
+
75
+ # Disable automatic flushing of the log to improve performance.
76
+ # config.autoflush_log = false
77
+
78
+ # Use default logging formatter so that PID and timestamp are not suppressed.
79
+ config.log_formatter = ::Logger::Formatter.new
80
+
81
+ # Do not dump schema after migrations.
82
+ config.active_record.dump_schema_after_migration = false
83
+ end
@@ -0,0 +1,26 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Do not eager load code on boot. This avoids loading your whole application
11
+ # just for the purpose of running a single test. If you are using a tool that
12
+ # preloads Rails for running tests, you may have to set it to true.
13
+ config.eager_load = false
14
+
15
+ # Configure static asset server for tests with Cache-Control for performance.
16
+ config.serve_static_assets = true
17
+ config.static_cache_control = 'public, max-age=3600'
18
+
19
+ # Show full error reports and disable caching.
20
+ config.consider_all_requests_local = true
21
+ # Print deprecation notices to the stderr.
22
+ config.active_support.deprecation = :stderr
23
+
24
+ # Raises error for missing translations
25
+ # config.action_view.raise_on_missing_translations = true
26
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,23 @@
1
+ # Files in the config/locales directory are used for internationalization
2
+ # and are automatically loaded by Rails. If you want to use locales other
3
+ # than English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t 'hello'
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%= t('hello') %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # To learn more, please read the Rails Internationalization guide
20
+ # available at http://guides.rubyonrails.org/i18n.html.
21
+
22
+ en:
23
+ hello: "Hello world"
@@ -0,0 +1,56 @@
1
+ Dummy::Application.routes.draw do
2
+ # The priority is based upon order of creation: first created -> highest priority.
3
+ # See how all your routes lay out with "rake routes".
4
+
5
+ # You can have the root of your site routed with "root"
6
+ # root 'welcome#index'
7
+
8
+ # Example of regular route:
9
+ # get 'products/:id' => 'catalog#view'
10
+
11
+ # Example of named route that can be invoked with purchase_url(id: product.id)
12
+ # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
13
+
14
+ # Example resource route (maps HTTP verbs to controller actions automatically):
15
+ # resources :products
16
+
17
+ # Example resource route with options:
18
+ # resources :products do
19
+ # member do
20
+ # get 'short'
21
+ # post 'toggle'
22
+ # end
23
+ #
24
+ # collection do
25
+ # get 'sold'
26
+ # end
27
+ # end
28
+
29
+ # Example resource route with sub-resources:
30
+ # resources :products do
31
+ # resources :comments, :sales
32
+ # resource :seller
33
+ # end
34
+
35
+ # Example resource route with more complex sub-resources:
36
+ # resources :products do
37
+ # resources :comments
38
+ # resources :sales do
39
+ # get 'recent', on: :collection
40
+ # end
41
+ # end
42
+
43
+ # Example resource route with concerns:
44
+ # concern :toggleable do
45
+ # post 'toggle'
46
+ # end
47
+ # resources :posts, concerns: :toggleable
48
+ # resources :photos, concerns: :toggleable
49
+
50
+ # Example resource route within a namespace:
51
+ # namespace :admin do
52
+ # # Directs /admin/products/* to Admin::ProductsController
53
+ # # (app/controllers/admin/products_controller.rb)
54
+ # resources :products
55
+ # end
56
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Rails.application
File without changes
File without changes
File without changes
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ describe 'Integration specs' do
3
+ def test_app_location
4
+ Pathname.new(File.dirname(__FILE__)).join('dummy_app')
5
+ end
6
+ let(:assets) {test_app_location.join('public', 'assets')}
7
+ def run_in_test_app(command)
8
+ Dir.chdir(test_app_location) do
9
+ output = Kernel.send :`,command
10
+ raise output unless $? == 0
11
+ end
12
+ end
13
+
14
+ before :all do
15
+ FileUtils.rm_rf(test_app_location.join('public', 'assets'))
16
+ run_in_test_app('rake assets:precompile 2>&1')
17
+ end
18
+
19
+ it 'should have symlinked application.js to the digested application.js' do
20
+ expect(assets.join('application.js')).to be_a_symlink_to(find_asset_name('application-*.js'))
21
+ expect(File.read(test_app_location.join('public','assets','application.js'))).to match(/alert\('application.js'\)/)
22
+ end
23
+
24
+ it 'should have symlinked 3rdpaty/all.js to the digested lib.js' do
25
+ expect(assets.join('3rdparty/all.js')).to be_a_symlink_to(find_asset_name('3rdparty/lib-*.js'))
26
+ expect(File.read(test_app_location.join('public','assets','3rdparty', 'all.js'))).to match(/alert\('3rd party js'\)/)
27
+ end
28
+
29
+ def find_asset_name(path)
30
+ File.basename(Dir.chdir(assets) { Dir.glob(path).first })
31
+ end
32
+ end
@@ -0,0 +1,22 @@
1
+ require 'bundler/setup'
2
+ require 'asset_symlink'
3
+
4
+ RSpec.configure do |config|
5
+ config.mock_with :rspec
6
+ end
7
+
8
+ RSpec::Matchers.define :be_a_symlink_to do |y|
9
+ match do |x|
10
+ @symlink_location = File.symlink?(x) && File.readlink(x)
11
+
12
+ @symlink_location == y
13
+ end
14
+
15
+ failure_message_for_should do |x|
16
+ if !@symlink_location
17
+ "expected #{x} to be a symlink but it was not"
18
+ else
19
+ "expected #{x} to be a symlink to #{y} but it was a symlink to #{@symlink_location}"
20
+ end
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asset_symlink
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Frederick Cheung
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.14.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.14.0
69
+ description: easily make assets available under a consistent public name
70
+ email:
71
+ - frederick.cheung@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - asset_symlink.gemspec
83
+ - lib/asset_symlink.rb
84
+ - lib/asset_symlink/railtie.rb
85
+ - lib/asset_symlink/tasks/symlink.rake
86
+ - lib/asset_symlink/version.rb
87
+ - spec/asset_symlink_spec.rb
88
+ - spec/dummy_app/README.rdoc
89
+ - spec/dummy_app/Rakefile
90
+ - spec/dummy_app/app/assets/images/.keep
91
+ - spec/dummy_app/app/assets/javascripts/3rdparty/lib.js
92
+ - spec/dummy_app/app/assets/javascripts/application.js
93
+ - spec/dummy_app/app/assets/javascripts/test.js
94
+ - spec/dummy_app/app/assets/stylesheets/application.css
95
+ - spec/dummy_app/app/controllers/application_controller.rb
96
+ - spec/dummy_app/app/controllers/concerns/.keep
97
+ - spec/dummy_app/app/helpers/application_helper.rb
98
+ - spec/dummy_app/app/mailers/.keep
99
+ - spec/dummy_app/app/models/.keep
100
+ - spec/dummy_app/app/models/concerns/.keep
101
+ - spec/dummy_app/app/views/layouts/application.html.erb
102
+ - spec/dummy_app/bin/bundle
103
+ - spec/dummy_app/bin/rails
104
+ - spec/dummy_app/bin/rake
105
+ - spec/dummy_app/config.ru
106
+ - spec/dummy_app/config/application.rb
107
+ - spec/dummy_app/config/boot.rb
108
+ - spec/dummy_app/config/database.yml
109
+ - spec/dummy_app/config/environment.rb
110
+ - spec/dummy_app/config/environments/development.rb
111
+ - spec/dummy_app/config/environments/production.rb
112
+ - spec/dummy_app/config/environments/test.rb
113
+ - spec/dummy_app/config/initializers/backtrace_silencers.rb
114
+ - spec/dummy_app/config/locales/en.yml
115
+ - spec/dummy_app/config/routes.rb
116
+ - spec/dummy_app/lib/assets/.keep
117
+ - spec/dummy_app/log/.keep
118
+ - spec/dummy_app/log/development.log
119
+ - spec/integration_spec.rb
120
+ - spec/spec_helper.rb
121
+ homepage: http://github.com/fcheung/asset_symlink
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.2.2
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: easily make assets available under a consistent public name
145
+ test_files:
146
+ - spec/asset_symlink_spec.rb
147
+ - spec/dummy_app/README.rdoc
148
+ - spec/dummy_app/Rakefile
149
+ - spec/dummy_app/app/assets/images/.keep
150
+ - spec/dummy_app/app/assets/javascripts/3rdparty/lib.js
151
+ - spec/dummy_app/app/assets/javascripts/application.js
152
+ - spec/dummy_app/app/assets/javascripts/test.js
153
+ - spec/dummy_app/app/assets/stylesheets/application.css
154
+ - spec/dummy_app/app/controllers/application_controller.rb
155
+ - spec/dummy_app/app/controllers/concerns/.keep
156
+ - spec/dummy_app/app/helpers/application_helper.rb
157
+ - spec/dummy_app/app/mailers/.keep
158
+ - spec/dummy_app/app/models/.keep
159
+ - spec/dummy_app/app/models/concerns/.keep
160
+ - spec/dummy_app/app/views/layouts/application.html.erb
161
+ - spec/dummy_app/bin/bundle
162
+ - spec/dummy_app/bin/rails
163
+ - spec/dummy_app/bin/rake
164
+ - spec/dummy_app/config.ru
165
+ - spec/dummy_app/config/application.rb
166
+ - spec/dummy_app/config/boot.rb
167
+ - spec/dummy_app/config/database.yml
168
+ - spec/dummy_app/config/environment.rb
169
+ - spec/dummy_app/config/environments/development.rb
170
+ - spec/dummy_app/config/environments/production.rb
171
+ - spec/dummy_app/config/environments/test.rb
172
+ - spec/dummy_app/config/initializers/backtrace_silencers.rb
173
+ - spec/dummy_app/config/locales/en.yml
174
+ - spec/dummy_app/config/routes.rb
175
+ - spec/dummy_app/lib/assets/.keep
176
+ - spec/dummy_app/log/.keep
177
+ - spec/dummy_app/log/development.log
178
+ - spec/integration_spec.rb
179
+ - spec/spec_helper.rb
180
+ has_rdoc: