critical-path-css-rails 1.0.1 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +0 -1
  3. data/.rubocop_todo.yml +23 -7
  4. data/BACKLOG.md +0 -4
  5. data/Gemfile +4 -0
  6. data/README.md +32 -13
  7. data/app_container_name +1 -0
  8. data/config.ru +6 -0
  9. data/critical-path-css-rails.gemspec +14 -14
  10. data/docker-compose.yml +21 -0
  11. data/docker/ruby/.env +1 -0
  12. data/docker/ruby/Dockerfile +21 -0
  13. data/docker/ruby/startup.dev +6 -0
  14. data/ext/npm/extconf.rb +0 -1
  15. data/lib/critical-path-css-rails.rb +1 -1
  16. data/lib/critical_path_css/configuration.rb +0 -1
  17. data/lib/critical_path_css/css_fetcher.rb +1 -6
  18. data/lib/critical_path_css/rails/config_loader.rb +2 -2
  19. data/lib/critical_path_css/rails/version.rb +1 -1
  20. data/lib/npm_commands.rb +2 -3
  21. data/package-lock.json +194 -622
  22. data/package.json +2 -2
  23. data/spec/features/generate_and_fetch_critical_css_spec.rb +16 -0
  24. data/spec/internal/app/controllers/root_controller.rb +3 -0
  25. data/spec/internal/app/views/layouts/application.html.erb +4 -0
  26. data/spec/internal/app/views/root/index.html.erb +1 -0
  27. data/spec/internal/config/critical_path_css.yml +11 -0
  28. data/spec/internal/config/database.yml +3 -0
  29. data/spec/internal/config/routes.rb +3 -0
  30. data/spec/internal/db/schema.rb +3 -0
  31. data/spec/internal/log/.gitignore +1 -0
  32. data/spec/internal/public/favicon.ico +0 -0
  33. data/spec/{fixtures/static → internal/public}/test.css +1 -1
  34. data/spec/spec_helper.rb +9 -3
  35. metadata +22 -9
  36. data/spec/css_fetcher_spec.rb +0 -25
  37. data/spec/fixtures/static/test.html +0 -7
  38. data/spec/support/static_file_server.rb +0 -45
data/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "critical-path-css-rails",
3
- "version": "1.0.0",
3
+ "version": "2.3.0",
4
4
  "description": "NPM dependencies of critical-path-css-rails",
5
5
  "private": true,
6
6
  "directories": {
7
7
  "lib": "lib"
8
8
  },
9
9
  "dependencies": {
10
- "penthouse": "=0.11.5"
10
+ "penthouse": "=1.3.0"
11
11
  },
12
12
  "license": "MIT"
13
13
  }
@@ -0,0 +1,16 @@
1
+ require 'spec_helper.rb'
2
+
3
+ RSpec.describe 'generate and fetch the critical css' do
4
+ before do
5
+ CriticalPathCss.generate_all
6
+ end
7
+
8
+ context 'on the root page' do
9
+ let(:route) { '/' }
10
+
11
+ it 'displays the correct critical CSS' do
12
+ visit route
13
+ expect(page).to have_content 'p{color:red}'
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ class RootController < ActionController::Base
2
+ def index; end
3
+ end
@@ -0,0 +1,4 @@
1
+ <html>
2
+ <head></head>
3
+ <body><%= yield %></body>
4
+ </html>
@@ -0,0 +1 @@
1
+ <p><%= CriticalPathCss.fetch(request.path) %></p>
@@ -0,0 +1,11 @@
1
+ defaults: &defaults
2
+ base_url: http://0.0.0.0:9292
3
+ css_path: /test.css
4
+ routes:
5
+ - /
6
+
7
+ development:
8
+ <<: *defaults
9
+
10
+ test:
11
+ <<: *defaults
@@ -0,0 +1,3 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: db/combustion_test.sqlite
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ root 'root#index'
3
+ end
@@ -0,0 +1,3 @@
1
+ ActiveRecord::Schema.define do
2
+ #
3
+ end
@@ -0,0 +1 @@
1
+ *.log
File without changes
@@ -1,3 +1,3 @@
1
1
  p {
2
2
  color: red;
3
- }
3
+ }
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/setup'
4
- require 'critical-path-css-rails'
3
+ require 'bundler'
5
4
 
6
- require 'support/static_file_server'
5
+ Bundler.require :default, :development
6
+
7
+ Combustion.initialize! :action_controller, :action_view
8
+
9
+ require 'rspec/rails'
10
+ require 'capybara/rails'
7
11
 
8
12
  RSpec.configure do |config|
13
+ config.use_transactional_fixtures = true
14
+
9
15
  # Enable flags like --only-failures and --next-failure
10
16
  config.example_status_persistence_file_path = '.rspec_status'
11
17
 
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: critical-path-css-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Misshore
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-02 00:00:00.000000000 Z
11
+ date: 2018-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec
14
+ name: combustion
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.6'
19
+ version: 0.7.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.6'
26
+ version: 0.7.0
27
27
  description: Only load the CSS you need for the initial viewport in Rails!
28
28
  email: mmisshore@gmail.com
29
29
  executables: []
@@ -39,7 +39,13 @@ files:
39
39
  - Gemfile
40
40
  - LICENSE
41
41
  - README.md
42
+ - app_container_name
43
+ - config.ru
42
44
  - critical-path-css-rails.gemspec
45
+ - docker-compose.yml
46
+ - docker/ruby/.env
47
+ - docker/ruby/Dockerfile
48
+ - docker/ruby/startup.dev
43
49
  - ext/npm/extconf.rb
44
50
  - ext/npm/install.rb
45
51
  - lib/config/critical_path_css.yml
@@ -55,11 +61,18 @@ files:
55
61
  - lib/tasks/critical_path_css.rake
56
62
  - package-lock.json
57
63
  - package.json
58
- - spec/css_fetcher_spec.rb
59
- - spec/fixtures/static/test.css
60
- - spec/fixtures/static/test.html
64
+ - spec/features/generate_and_fetch_critical_css_spec.rb
65
+ - spec/internal/app/controllers/root_controller.rb
66
+ - spec/internal/app/views/layouts/application.html.erb
67
+ - spec/internal/app/views/root/index.html.erb
68
+ - spec/internal/config/critical_path_css.yml
69
+ - spec/internal/config/database.yml
70
+ - spec/internal/config/routes.rb
71
+ - spec/internal/db/schema.rb
72
+ - spec/internal/log/.gitignore
73
+ - spec/internal/public/favicon.ico
74
+ - spec/internal/public/test.css
61
75
  - spec/spec_helper.rb
62
- - spec/support/static_file_server.rb
63
76
  homepage:
64
77
  licenses:
65
78
  - MIT
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'CssFetcher' do
6
- before :all do
7
- StaticFileServer.start
8
- end
9
-
10
- after :all do
11
- StaticFileServer.stop
12
- end
13
-
14
- it 'fetches css' do
15
- config = CriticalPathCss::Configuration.new(
16
- 'base_url' => StaticFileServer.url,
17
- 'css_path' => 'spec/fixtures/static/test.css',
18
- 'routes' => ['/test.html']
19
- )
20
- fetcher = CriticalPathCss::CssFetcher.new(config)
21
- expect(fetcher.fetch).to(
22
- eq('/test.html' => "p {\n color: red;\n}\n")
23
- )
24
- end
25
- end
@@ -1,7 +0,0 @@
1
- <!doctype html>
2
- <head>
3
- <link rel="stylesheet" href="test.css">
4
- </head>
5
- <body>
6
- <p>Hello world</p>
7
- </body>
@@ -1,45 +0,0 @@
1
- require 'socket'
2
-
3
- module StaticFileServer
4
- class << self
5
- def start # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
6
- @port = get_free_port
7
- rd, wt = IO.pipe
8
- @pid = fork do
9
- require 'webrick'
10
- rd.close
11
- server = WEBrick::HTTPServer.new(
12
- DocumentRoot: File.expand_path('spec/fixtures/static'),
13
- Port: @port,
14
- BindAddress: '127.0.0.1',
15
- StartCallback: lambda do
16
- # write "1", signal a server start message
17
- wt.write(1)
18
- wt.close
19
- end
20
- )
21
- trap('INT') { server.shutdown }
22
- server.start
23
- end
24
- wt.close
25
- # read a byte for the server start signal
26
- rd.read(1)
27
- rd.close
28
- end
29
-
30
- def stop
31
- Process.kill('INT', @pid)
32
- end
33
-
34
- def url
35
- "http://localhost:#{@port}"
36
- end
37
-
38
- def get_free_port
39
- server = TCPServer.new('127.0.0.1', 0)
40
- port = server.addr[1]
41
- server.close
42
- port
43
- end
44
- end
45
- end