accio_bower 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ba5068a6787c84d1bba12c7b6b43522cd448b649
4
+ data.tar.gz: 2056044222f2a1d91d0fdaf0eb746a290d069d56
5
+ SHA512:
6
+ metadata.gz: 5bf3c163e67c8c582ec525064072814a41c0412191aede4e09ee4640e5076998a46a68a5dbcb8d272e13c0370ea8a9f633905d80ff7a34f2eca0af0cbe5cba3e
7
+ data.tar.gz: ba7c836c800baedf217d847e3bd25ededdf60dd233d6365c4683de6a151d58d293cfe68b9fcd6d24f61bf38e6464e1fa0b5d2dda81fb2163b0a54000fa852d6a
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /version.lock
data/.versioneer.yml ADDED
@@ -0,0 +1,8 @@
1
+ # Versioneer Project Configuration
2
+ # https://git.io/versioneer-help
3
+
4
+ type: Git
5
+ bump_segment: minor
6
+ prereleases:
7
+ - alpha
8
+ - beta
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in accio_bower.gemspec
4
+ gemspec
data/INSTALL.txt ADDED
@@ -0,0 +1,16 @@
1
+ ################################################
2
+ # ACCIO BOWER INSTALLATION #
3
+ ################################################
4
+
5
+ Add the following to any project's .bowerrc
6
+ to ensure Bower assets are installed inside
7
+ the Rail's project assets directory...
8
+
9
+ {"directory": "vendor/assets/bower_components"}
10
+
11
+ The Rails console will also output similar
12
+ instructions if the directory is not found
13
+ at startup.
14
+
15
+ You should still include `bower install`
16
+ in build scripts for your projects.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 BinaryBabel OSS
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # Accio Bower
2
+
3
+ **Bower** asset processor for **Rails 4/5**, supporting ***CSS/JS URL Rewriting*** (images, fonts, etc.), and production ***Hashes/Digests***.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's `Gemfile`:
8
+
9
+ ```ruby
10
+ gem 'accio_bower'
11
+ ```
12
+
13
+ And this line to a new/existing `.bowerrc` file:
14
+
15
+ ```json
16
+ {"directory": "vendor/assets/bower_components"}
17
+ ```
18
+
19
+ If you **DO NOT** yet have a `bower.json` file:
20
+
21
+ $ bundle install
22
+ $ bower init # follow instructions
23
+ $ bower install --save A-BOWER-PKG-YOU-WANT
24
+
25
+ If you **ALREADY** have a `bower.json` file:
26
+
27
+ $ rm -rf bower_components
28
+ $ bundle install
29
+ $ bower install
30
+
31
+ ### To include CSS/JS files in your application
32
+
33
+ Require the name of the file under the `vendor/assets/bower_components` path.
34
+
35
+ For example, to include `font-awesome` in `application.css`
36
+
37
+ ```
38
+ *= require 'font-awesome/css/font-awesome.min'
39
+ ```
40
+
41
+ ## Configuration
42
+
43
+ ### Ruby Initializer
44
+
45
+ **`app/config/initializers/bower.rb`**
46
+
47
+ ```
48
+ Rails.application.config.accio_bower.components = [
49
+ Rails.root.join('vendor', 'assets', 'bower_components')
50
+ ]
51
+ Rails.application.config.accio_bower.extensions = %w[
52
+ png gif jpg jpeg ttf svg eot woff woff2
53
+ ]
54
+ ```
55
+
56
+ ### Environment Variables
57
+ * __BOWER\_PREFIX__
58
+ * default: none - Path prefix for Bower asset URL substitutions, handy for unique CDN setups.
59
+ * `config.action_controller.asset_host` applies as normal.
60
+
61
+
62
+ ## License
63
+
64
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
65
+
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
11
+
12
+ task :versioneer do
13
+ system './bin/versioneer relock'
14
+ end
15
+
16
+ Rake::Task[:build].enhance [:versioneer] do
17
+ system './bin/versioneer unlock -q'
18
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'accio_bower/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'accio_bower'
8
+ spec.version = AccioBower::VERSION
9
+ spec.authors = ['BinaryBabel OSS']
10
+ spec.email = ['oss@binarybabel.org']
11
+
12
+ spec.summary = 'Bower asset processor for Rails, supporting CSS/JS URL rewriting (images, fonts, etc.), and production hashes/digests.'
13
+ spec.description = 'Import externally managed Bower assets via Rails Sprockets while preserving links to relative dependencies, and maintaining hash digests in production.'
14
+ spec.homepage = 'https://github.com/binarybabel/gem-accio_bower'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.require_paths = ['lib']
21
+
22
+ if File.exist?('INSTALL.txt')
23
+ spec.post_install_message = File.read('INSTALL.txt')
24
+ end
25
+
26
+ spec.files += ['version.lock']
27
+ spec.add_runtime_dependency 'versioneer', '~> 0.2'
28
+
29
+ spec.add_runtime_dependency 'rails'
30
+ spec.add_runtime_dependency 'sprockets'
31
+
32
+ spec.add_development_dependency 'bundler', '~> 1.13'
33
+ spec.add_development_dependency 'rake', '~> 10.0'
34
+ spec.add_development_dependency 'minitest', '~> 5.0'
35
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "accio_bower"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bin/versioneer ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'versioneer' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("versioneer", "versioneer")
@@ -0,0 +1,90 @@
1
+ class AccioBower::AssetsProcessor
2
+ def initialize(app)
3
+ @app = app
4
+ self.components = [@app.root.join('vendor', 'assets', 'bower_components')]
5
+ self.extensions = ::AccioBower::DEFAULT_EXTENSIONS
6
+ end
7
+
8
+ attr_reader :components
9
+ def components=(v)
10
+ @components = Array(v).map(&:to_s)
11
+ end
12
+
13
+ attr_reader :extensions
14
+ def extensions=(v)
15
+ @extensions = Array(v).map(&:to_s)
16
+ @url_exp = Regexp.new(%{(url\\(('|"|))((.+?)\\.(%s))(.*?\\2\\))} % [v.join('|')])
17
+ end
18
+
19
+ attr_accessor :output_prefix
20
+
21
+ def call(input)
22
+ output = input[:data]
23
+
24
+ unless assets_debug?
25
+ if is_component?(input[:filename])
26
+ output = fix_assets_path(input)
27
+ end
28
+ end
29
+
30
+ {data: output}
31
+ end
32
+
33
+ def fix_assets_path(input)
34
+ source_dir = File.dirname(input[:filename])
35
+
36
+ input[:data].gsub @url_exp do |*args|
37
+ # $1 = opening declaration Ex: url('
38
+ # $2 = quotation style Ex: '
39
+ # $3 = path with extension
40
+ # $4 = path without extension
41
+ # $5 = extension
42
+ # $6 = closing declaration Ex: ')
43
+
44
+ # Copy opening and closing declarations.
45
+ d1, d2 = $1.dup, $6.dup
46
+
47
+ # Map relative url to physical path.
48
+ path = File.expand_path("#{source_dir}/#{$3}")
49
+
50
+ # Replace bower_components path to create relative uri.
51
+ components.each do |base_path|
52
+ path = path.gsub("#{base_path}/", '')
53
+ end
54
+
55
+ # Convert path to digest (if needed).
56
+ if assets_digest?
57
+ if @app.assets
58
+ asset = @app.assets[path]
59
+ if asset.nil?
60
+ ::AccioBower.warn_all "AccioBower could not locate asset digest for \"#{path}\""
61
+ else
62
+ path = asset.digest_path
63
+ end
64
+ else
65
+ ::AccioBower.warn_all [
66
+ 'AccioBower needs access to assets digests for precompilation.',
67
+ "Try adding the following snippet to config/environments/#{::Rails.env}.rb",
68
+ " config.assets.compile = File.basename($0).eql?('rake')"
69
+ ]
70
+ raise 'AccioBower fatal error.'
71
+ end
72
+ end
73
+
74
+ # Wrap resultant path in declaration.
75
+ "#{d1}#{output_prefix}#{path}#{d2}"
76
+ end
77
+ end
78
+
79
+ def assets_debug?
80
+ @app.config.assets.debug
81
+ end
82
+
83
+ def assets_digest?
84
+ @app.config.assets.digest
85
+ end
86
+
87
+ def is_component?(input_path)
88
+ components.any? { |base_path| input_path.to_s.starts_with?(base_path) }
89
+ end
90
+ end
@@ -0,0 +1,45 @@
1
+ module AccioBower
2
+ class Railtie < Rails::Railtie
3
+ railtie_name :accio_bower
4
+
5
+ config.accio_bower = ActiveSupport::OrderedOptions.new
6
+
7
+ config.before_initialize do |app|
8
+ @processor = ::AccioBower::AssetsProcessor.new(app)
9
+ Sprockets.register_preprocessor 'text/css', @processor
10
+ Sprockets.register_preprocessor 'application/javascript', @processor
11
+ app.config.accio_bower.components = nil
12
+ app.config.accio_bower.extensions = nil
13
+ config.assets.compile ||= File.basename($0).eql?('rake')
14
+ end
15
+
16
+ config.after_initialize do |app|
17
+ %w{components extensions}.each do |cfg|
18
+ if (val = app.config.accio_bower.send(cfg))
19
+ @processor.send("#{cfg}=".to_sym, val)
20
+ end
21
+ end
22
+
23
+ @processor.output_prefix = ENV['ACCIOBOWER_PREFIX'] || ENV['BOWER_PREFIX']
24
+
25
+ app.config.assets.paths += @processor.components
26
+ @processor.extensions.each do |ext|
27
+ @processor.components.each do |base_path|
28
+ app.config.assets.precompile += Dir.glob("#{base_path}/**/*.#{ext}")
29
+ end
30
+ end
31
+
32
+ unless @processor.components.any? { |path| Dir.exist?(path) }
33
+ puts ''
34
+ puts '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
35
+ puts 'AccioBower: Could not locate a bower_components directory.'
36
+ puts '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
37
+ puts ''
38
+ puts 'https://git.io/accio_bower#Installation'
39
+ puts ''
40
+ Rails.logger.error('AccioBower could not locate a bower_components directory.')
41
+ Rails.logger.info('https://git.io/accio_bower#Installation')
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,5 @@
1
+ require 'versioneer'
2
+
3
+ module AccioBower
4
+ VERSION = ::Versioneer::Config.new(::File.expand_path('../../../', __FILE__))
5
+ end
@@ -0,0 +1,14 @@
1
+ require 'rails'
2
+ require 'accio_bower/railtie'
3
+ require 'accio_bower/assets_processor'
4
+
5
+ module AccioBower
6
+ DEFAULT_EXTENSIONS = %w[png gif jpg jpeg ttf svg eot woff woff2]
7
+
8
+ def self.warn_all(msgs)
9
+ logger = Logger.new(STDOUT)
10
+ msgs = Array(msgs)
11
+ msgs.each {|msg| logger.warn(msg) }
12
+ msgs.each {|msg| ::Rails.logger.warn(msg) }
13
+ end
14
+ end
data/version.lock ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: accio_bower
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - BinaryBabel OSS
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: versioneer
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sprockets
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.13'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.13'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '5.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '5.0'
97
+ description: Import externally managed Bower assets via Rails Sprockets while preserving
98
+ links to relative dependencies, and maintaining hash digests in production.
99
+ email:
100
+ - oss@binarybabel.org
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".versioneer.yml"
107
+ - Gemfile
108
+ - INSTALL.txt
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - accio_bower.gemspec
113
+ - bin/console
114
+ - bin/setup
115
+ - bin/versioneer
116
+ - lib/accio_bower.rb
117
+ - lib/accio_bower/assets_processor.rb
118
+ - lib/accio_bower/railtie.rb
119
+ - lib/accio_bower/version.rb
120
+ - version.lock
121
+ homepage: https://github.com/binarybabel/gem-accio_bower
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message: |
126
+ ################################################
127
+ # ACCIO BOWER INSTALLATION #
128
+ ################################################
129
+
130
+ Add the following to any project's .bowerrc
131
+ to ensure Bower assets are installed inside
132
+ the Rail's project assets directory...
133
+
134
+ {"directory": "vendor/assets/bower_components"}
135
+
136
+ The Rails console will also output similar
137
+ instructions if the directory is not found
138
+ at startup.
139
+
140
+ You should still include `bower install`
141
+ in build scripts for your projects.
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.5.1
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: Bower asset processor for Rails, supporting CSS/JS URL rewriting (images,
161
+ fonts, etc.), and production hashes/digests.
162
+ test_files: []