polyfillrb 1.0.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 +7 -0
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/README.md +38 -0
- data/Rakefile +1 -0
- data/bin/polyfillrb +6 -0
- data/lib/polyfillrb/rails/railtie.rb +15 -0
- data/lib/polyfillrb/rails/view_helper.rb +17 -0
- data/lib/polyfillrb/rails.rb +2 -0
- data/lib/polyfillrb/version.rb +3 -0
- data/lib/polyfillrb.rb +67 -0
- data/npm-debug.log +22 -0
- data/polyfillrb.gemspec +22 -0
- metadata +71 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 587620e5f330dca04886415c32a699abf10f4ad9
|
4
|
+
data.tar.gz: fedb8fc7b6b87c7561369cd32e100773e9afa173
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6e56c0b92751897ce37002030016f1069bc3c309586b288b6ac561472096e44610753e542a8a2cf097c87eaf6280283a327655094a62b3028306626b8ae18e00
|
7
|
+
data.tar.gz: edb2361fac52fc2d2958dc32a8618181f659b336a47747101a22a35ad44223ee53dca55d5fbd53d5b1e3cedb872fbc28a98947a384044b29bc13e4ca3c3a931f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Polyfillrb
|
2
|
+
|
3
|
+
A simple ruby wrapper for the phenominal [Polyfill.io Service by FTLabs](https://cdn.polyfill.io/v1/docs/) for Rails applications.
|
4
|
+
|
5
|
+
|
6
|
+
### How to use
|
7
|
+
The library provides a simple view helper to load in the polyfills. Simply in any view file add the `polyfills` call. Make sure to load it prior to running any other javascript. Here's an example `app/views/layouts/welcome.erb`:
|
8
|
+
|
9
|
+
<html>
|
10
|
+
<head>
|
11
|
+
<title>Welcome</title>
|
12
|
+
<%= stylesheet_link_tag 'application', media: 'all' %>
|
13
|
+
<%= csrf_meta_tokens %>
|
14
|
+
</head>
|
15
|
+
<body>
|
16
|
+
|
17
|
+
<%= yield %>
|
18
|
+
|
19
|
+
<%= polyfills %>
|
20
|
+
<%= javascript_include_tag 'application' %>
|
21
|
+
|
22
|
+
</body>
|
23
|
+
</html>
|
24
|
+
|
25
|
+
### Installing
|
26
|
+
|
27
|
+
Add the gem to your Gemfile: `gem "polyfillrb", "~>1.0.0"`
|
28
|
+
|
29
|
+
Then you must run the command to build the polyfills. simply run:
|
30
|
+
|
31
|
+
%> polyfillrb init
|
32
|
+
|
33
|
+
### Future Plans
|
34
|
+
|
35
|
+
* Cache polyfills to avoid node IO calls (especially in production)
|
36
|
+
* 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
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/polyfillrb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
module Polyfillrb
|
4
|
+
module Rails
|
5
|
+
class Railtie < ::Rails::Railtie
|
6
|
+
|
7
|
+
# Include the react-rails view helper lazily
|
8
|
+
initializer "polyfillrb.setup_view_helpers" do |app|
|
9
|
+
ActiveSupport.on_load(:action_view) do
|
10
|
+
include ::Polyfillrb::Rails::ViewHelper
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
module Polyfillrb
|
3
|
+
module Rails
|
4
|
+
module ViewHelper
|
5
|
+
|
6
|
+
def polyfills
|
7
|
+
polyfills = Polyfillrb.get_polyfills(
|
8
|
+
request.env['HTTP_USER_AGENT'],
|
9
|
+
(::Rails.env != 'development')
|
10
|
+
)
|
11
|
+
|
12
|
+
content_tag('script', polyfills, {}, false)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/polyfillrb.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'polyfillrb/rails'
|
2
|
+
|
3
|
+
module Polyfillrb
|
4
|
+
|
5
|
+
PROJECT_DIRECTORY = File.expand_path(File.dirname(__FILE__))
|
6
|
+
|
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}'"
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
data/npm-debug.log
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
0 info it worked if it ends with ok
|
2
|
+
1 verbose cli [ 'node', '/usr/local/bin/npm', 'install' ]
|
3
|
+
2 info using npm@1.3.8
|
4
|
+
3 info using node@v0.10.32
|
5
|
+
4 verbose node symlink /usr/local/bin/node
|
6
|
+
5 error install Couldn't read dependencies
|
7
|
+
6 error Failed to parse json
|
8
|
+
6 error Unexpected token }
|
9
|
+
7 error File: /Users/blainekasten/Sites/polyfillrb/package.json
|
10
|
+
8 error Failed to parse package.json data.
|
11
|
+
8 error package.json must be actual JSON, not just JavaScript.
|
12
|
+
8 error
|
13
|
+
8 error This is not a bug in npm.
|
14
|
+
8 error Tell the package author to fix their package.json file. JSON.parse
|
15
|
+
9 error System Darwin 14.0.0
|
16
|
+
10 error command "node" "/usr/local/bin/npm" "install"
|
17
|
+
11 error cwd /Users/blainekasten/Sites/polyfillrb
|
18
|
+
12 error node -v v0.10.32
|
19
|
+
13 error npm -v 1.3.8
|
20
|
+
14 error file /Users/blainekasten/Sites/polyfillrb/package.json
|
21
|
+
15 error code EJSONPARSE
|
22
|
+
16 verbose exit [ 1, true ]
|
data/polyfillrb.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'polyfillrb/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "polyfillrb"
|
7
|
+
spec.version = Polyfillrb::VERSION
|
8
|
+
spec.authors = ["Blaine Kasten"]
|
9
|
+
spec.email = ["blainekasten@gmail.com"]
|
10
|
+
spec.summary = %q{A wrapper library for the FTLabs polyfill.io service}
|
11
|
+
spec.description = %q{Provides user agent specific polyfills to the browser easily in ruby}
|
12
|
+
spec.homepage = "https://github.com/blainekasten/polyfillrb"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
21
|
+
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: polyfillrb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Blaine Kasten
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
description: Provides user agent specific polyfills to the browser easily in ruby
|
28
|
+
email:
|
29
|
+
- blainekasten@gmail.com
|
30
|
+
executables:
|
31
|
+
- polyfillrb
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- ".gitignore"
|
36
|
+
- Gemfile
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- bin/polyfillrb
|
40
|
+
- lib/polyfillrb.rb
|
41
|
+
- lib/polyfillrb/rails.rb
|
42
|
+
- lib/polyfillrb/rails/railtie.rb
|
43
|
+
- lib/polyfillrb/rails/view_helper.rb
|
44
|
+
- lib/polyfillrb/version.rb
|
45
|
+
- npm-debug.log
|
46
|
+
- polyfillrb.gemspec
|
47
|
+
homepage: https://github.com/blainekasten/polyfillrb
|
48
|
+
licenses:
|
49
|
+
- MIT
|
50
|
+
metadata: {}
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 2.4.6
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: A wrapper library for the FTLabs polyfill.io service
|
71
|
+
test_files: []
|