polyfillrb 1.0.1 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b228511cfaa9433ee7814bde7f5ddb50fd308193
4
- data.tar.gz: f7f663d58e0ba1416e2f8d8a1baa65f56d5b8545
3
+ metadata.gz: 83b52ea541bf7e5477966fac05ba3a4d330f8e20
4
+ data.tar.gz: 89bb0281f93563920c8045c9ca3f1c97c71f8e22
5
5
  SHA512:
6
- metadata.gz: 2050e3d7b66491937997b585190d95ce76c3b7c900f1c0fc78c4b2cb302ee47cb50904e50b0ffc6470d3ad918ce01e0ecb25e11c515479430b7a25098894ad95
7
- data.tar.gz: cde55d28a09d25f74b3e2130c69ffdff5959799ad1418af32a224266b972e202bdae1b035a3918cb33612e968179ba158dd4d34de7f7668f0bbffda5a8c13885
6
+ metadata.gz: 4dba32c66efc3ff13f2ef3e7d6ff5c548da9a4655bcae4bcc6b04b84cfabcd4b5d7d8d0c86e9f9d7d6a54e0e6edef3fb990b1dde847996f1b3aa307684b2713d
7
+ data.tar.gz: 0bdb15103e6cf9b009cd44d8970397f6751d3425f969aa871596579994ae8e2c027283725936efe9d5084c66190f3b0c1cf11253ff129199c1d228e9442b0e2d
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Polyfillrb
1
+ # Polyfillrb [![Code Climate](https://codeclimate.com/github/blainekasten/polyfillrb/badges/gpa.svg)](https://codeclimate.com/github/blainekasten/polyfillrb)
2
2
 
3
3
  A simple ruby wrapper for the phenominal [Polyfill.io Service by FTLabs](https://cdn.polyfill.io/v1/docs/) for Rails applications.
4
4
 
@@ -24,15 +24,11 @@ The library provides a simple view helper to load in the polyfills. Simply in an
24
24
 
25
25
  ### Installing
26
26
 
27
- Add the gem to your Gemfile: `gem "polyfillrb", "~>1.0.0"`
27
+ Add the gem to your Gemfile: `gem "polyfillrb", "~>1.1.0"`
28
28
 
29
- Then you must run the command to build the polyfills. simply run:
30
-
31
- %> polyfillrb init
32
29
 
33
30
  ### Future Plans
34
31
 
35
32
  * Cache polyfills to avoid node IO calls (especially in production)
36
33
  * Ensure we are doing the most performant javascript executions.
37
- * Remove the need to run `polyfillrb init` on install. It'd be best if it could all be bundled up, but that has some issues to resolve in itself.
38
34
 
data/lib/polyfill.js ADDED
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ var args = process.argv.slice(3);
4
+
5
+ process.stdout.write((function(uaString, minify){
6
+ return require(__dirname + '/polyfill-service/lib').getPolyfillString({
7
+ uaString: uaString,
8
+ minify: !!minify,
9
+ features: { default: { flags: [] } }
10
+ });
11
+ })(args[0], args[1]));
@@ -10,6 +10,20 @@ module Polyfillrb
10
10
  include ::Polyfillrb::Rails::ViewHelper
11
11
  end
12
12
  end
13
+
14
+ # Preload the application with polyfills
15
+ initializer "polyfillrb.configure_rails_initialization" do |app|
16
+
17
+ # clone polyfill
18
+ ::Rails.logger.info "Gathering Polyfill Library..."
19
+ %x( cd #{Polyfillrb::PROJECT_DIRECTORY} && git clone git@github.com:Financial-Times/polyfill-service.git )
20
+
21
+ # build the npm locals
22
+ ::Rails.logger.info "Buidling Polyfills...\n this may take a minute"
23
+ %x( cd #{Polyfillrb::PROJECT_DIRECTORY}/polyfill-service && [ -d "node_modules" ] || npm install && grunt buildsources )
24
+
25
+ end
26
+
13
27
  end
14
28
  end
15
29
  end
@@ -4,7 +4,7 @@ module Polyfillrb
4
4
  module ViewHelper
5
5
 
6
6
  def polyfills
7
- polyfills = Polyfillrb.get_polyfills(
7
+ polyfills = ::Polyfillrb.get_polyfills(
8
8
  request.env['HTTP_USER_AGENT'],
9
9
  (::Rails.env != 'development')
10
10
  )
@@ -1,3 +1,3 @@
1
1
  module Polyfillrb
2
- VERSION = '1.0.1'
2
+ VERSION = '1.1.0'
3
3
  end
data/lib/polyfillrb.rb CHANGED
@@ -1,66 +1,11 @@
1
- require 'polyfillrb/rails'
1
+ require 'polyfillrb/rails' if defined?(Rails)
2
2
 
3
3
  module Polyfillrb
4
4
 
5
5
  PROJECT_DIRECTORY = File.expand_path(File.dirname(__FILE__))
6
6
 
7
7
  def self.get_polyfills(ua, minify=false)
8
-
9
- # we console.log the results of the polyfillService so that we
10
- # can read them from the IO instance.
11
- #
12
- # This feels kind of hacky, so in the future we can look into
13
- # better ways to inject JS into this.
14
- jscode = <<-JS
15
- console.log(
16
- require('#{PROJECT_DIRECTORY}/polyfill-service/lib').getPolyfillString({
17
- uaString: '#{ua}',
18
- minify: #{minify},
19
- features: { default: { flags: [] } }
20
- })
21
- );
22
- JS
23
-
24
- # pump into a node runner
25
- i = IO.popen('node', 'r+')
26
- i.write(jscode)
27
- i.close_write
28
-
29
- # return the results
30
- return i.read
31
- end
32
-
33
-
34
- #
35
- # loads the javascript for the application
36
- def self.init
37
- # check for node and npm
38
-
39
-
40
- # clone polyfill
41
- puts "-- Cloning Polyfill js\n"
42
- #%x( cd #{PROJECT_DIRECTORY} && git clone --branch v1.2.0 git@github.com:Financial-Times/polyfill-service.git )
43
- %x( cd #{PROJECT_DIRECTORY} && git clone git@github.com:Financial-Times/polyfill-service.git )
44
-
45
- # build the npm locals
46
- puts "\n-- Grabbing dependencies\n"
47
- %x( cd #{PROJECT_DIRECTORY}/polyfill-service && npm install )
48
-
49
- # build the polyfills
50
- #puts "\n-- Building polyfills\n"
51
- #%x( cd #{PROJECT_DIRECTORY}/polyfill-service && grunt build )
52
- end
53
-
54
- def self.build
55
-
56
- puts "-- Building polyfills \n"
57
- %x( cd #{PROJECT_DIRECTORY}/polyfill-service && grunt buildsources )
58
-
59
- end
60
-
61
-
62
- def self.method_missing(method, blah, bleh)
63
- puts "Polyfillrb does not support the action '#{method}'"
8
+ return %x( node #{PROJECT_DIRECTORY}/polyfill.js -p "#{ua}" #{minify})
64
9
  end
65
10
 
66
11
  end
data/polyfillrb.gemspec CHANGED
@@ -13,7 +13,6 @@ Gem::Specification.new do |spec|
13
13
  spec.license = "MIT"
14
14
 
15
15
  spec.files = `git ls-files -z`.split("\x0")
16
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
16
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
17
  spec.require_paths = ["lib"]
19
18
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polyfillrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blaine Kasten
@@ -27,8 +27,7 @@ dependencies:
27
27
  description: Provides user agent specific polyfills to the browser easily in ruby
28
28
  email:
29
29
  - blainekasten@gmail.com
30
- executables:
31
- - polyfillrb
30
+ executables: []
32
31
  extensions: []
33
32
  extra_rdoc_files: []
34
33
  files:
@@ -36,7 +35,7 @@ files:
36
35
  - Gemfile
37
36
  - README.md
38
37
  - Rakefile
39
- - bin/polyfillrb
38
+ - lib/polyfill.js
40
39
  - lib/polyfillrb.rb
41
40
  - lib/polyfillrb/rails.rb
42
41
  - lib/polyfillrb/rails/railtie.rb
data/bin/polyfillrb DELETED
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- begin
4
- require 'rubygems'
5
- gem 'polyfillrb'
6
- rescue LoadError
7
- end
8
-
9
- require 'polyfillrb'
10
-
11
- method = ARGV[0] || 'init'
12
- Polyfillrb.send(method.to_sym)