Skip to content

Commit 0060c80

Browse files
committed
merge capterra/master
2 parents d853440 + ffa10a6 commit 0060c80

37 files changed

+198
-146
lines changed

.rubocop.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ AllCops:
66
- 'spec/*_helper.rb'
77
- 'Gemfile'
88
- 'Rakefile'
9-
- 'Vagrantfile'
109

1110
Documentation:
1211
Enabled: false

.rubocop_todo.yml

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2015-10-29 13:19:55 -0500 using RuboCop version 0.34.1.
3+
# on 2017-12-29 15:04:25 +0000 using RuboCop version 0.52.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 3
10-
# Configuration parameters: AllowURI, URISchemes.
11-
Metrics/LineLength:
12-
Max: 91
9+
# Offense count: 1
10+
Metrics/AbcSize:
11+
Max: 19
1312

1413
# Offense count: 1
15-
# Configuration parameters: Exclude.
16-
Style/FileName:
14+
# Configuration parameters: CountComments.
15+
Metrics/MethodLength:
16+
Max: 31
17+
18+
# Offense count: 1
19+
Naming/AccessorMethodName:
20+
Exclude:
21+
- 'spec/support/static_file_server.rb'
22+
23+
# Offense count: 1
24+
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
25+
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
26+
Naming/FileName:
1727
Exclude:
1828
- 'lib/critical-path-css-rails.rb'
29+
30+
# Offense count: 4
31+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
32+
# URISchemes: http, https
33+
Metrics/LineLength:
34+
Max: 96

BACKLOG.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
# Backlog
22

3-
## Tests
4-
- Add a testing suite (preferably rspec)
5-
63
## Features
74
- Allow the user to give a single route for a Controller#Show route, instead of hard coding every unique Resource#Show URL
85
* Implementation should account for any route that allows variables/parameters in the URL
96
- Error reporting during CSS generation (404, 500 errors, etc.)
10-
- Allow the user to pass arguments to Penthouse.js, i.e. Viewport size, etc. For a list of the configurable options, please see [Penthouse](https://github.com/pocketjoso/penthouse)
117
- Improve installation process, if possible
128
- Improve implementation. Is their a better solution then using Rails.cache?

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ source 'https://rubygems.org'
33
gemspec
44

55
group :development, :test do
6+
gem 'actionpack'
67
gem 'byebug', platform: [:ruby], require: false
78
gem 'rubocop', require: false
9+
gem 'rspec-rails', '~> 3.6'
10+
gem 'capybara', '~> 2.16'
11+
gem 'pry-rails'
812
end
913

1014
# HACK: npm install on bundle

README.md

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,32 @@
22

33
Only load the CSS you need for the initial viewport in Rails!
44

5-
This gem give you the ability to load only the CSS you *need* on an initial page view. This gives you blazin' fast rending as there's no initial network call to grab your application's CSS.
5+
This gem gives you the ability to load only the CSS you *need* on an initial page view. This gives you blazin' fast rending as there's no initial network call to grab your application's CSS.
66

77
This gem assumes that you'll load the rest of the CSS asyncronously. At the moment, the suggested way is to use the [loadcss-rails](https://github.com/michael-misshore/loadcss-rails) gem.
88

99
This gem uses [Penthouse](https://github.com/pocketjoso/penthouse) to generate the critical CSS.
1010

11-
## Update
11+
## Dependency Requirements for / Upgrading to the Latest Release
1212

13-
Versions below 0.3.0 are not compatible with this version. Please read the Upgrading from Previous Versions section below for more information.
13+
### For 1.0.0 or later
14+
To maintain the latest version of Penthouse, this gem depends on NodeJS and NVM to be installed on the system.
15+
16+
### For 2.0.0 or later
17+
This gem may require additional packages to be installed to run Chrome headless. Per the Penthouse documentation, this may be all you need:
18+
19+
```
20+
sudo apt-get install libnss3
21+
```
22+
23+
However, more packages may need to be installed depending on your OS distribution which can be found via [this answer](https://github.com/GoogleChrome/puppeteer/issues/404#issuecomment-323555784)
1424

1525
## Installation
1626

17-
Add `critical-path-css-rails` to your Gemfile:
27+
After reviewing the dependency requirements, add `critical-path-css-rails` to your Gemfile:
1828

1929
```
20-
gem 'critical-path-css-rails', '~> 1.0.0'
30+
gem 'critical-path-css-rails', '~> 2.3.0'
2131
```
2232

2333
Download and install by running:
@@ -110,7 +120,7 @@ Careful use of these methods allows the developer to generate critical path CSS
110120

111121
A user can use these methods to [dynamically generate critical path CSS](https://gist.github.com/taranda/1597e97ccf24c978b59aef9249666c77) without using the `rake critical_path_css:generate` rake task and without hardcoding the application's routes into `config/critical_path_css.yml`. See [this Gist](https://gist.github.com/taranda/1597e97ccf24c978b59aef9249666c77) for an example of such an implementation.
112122

113-
## Upgrading from Previous Versions
123+
## Upgrading from a version earlier than 0.3.0
114124

115125
The latest version of Critcal Path CSS Rails changes the functionality of the `generate` method. In past versions,
116126
`generate` would produce CSS for all of the routes listed in `config/critical_path_css.yml`. This functionality has been replaced by the `generate_all` method, and `generate` will only produce CSS for one route.
@@ -121,7 +131,21 @@ Developers upgrading from versions prior to 0.3.0 will need to replace `Critical
121131
rails generate critical_path_css:install
122132
```
123133

124-
Answer 'Y' when prompted to overwrite `critical_path_css.rake`. However, overwriting `critical_path_css.yml` is not necessary and not recommended.
134+
Answer 'Y' when prompted to overwrite `critical_path_css.rake`. However, overwriting `critical_path_css.yml` is not recommended nor necessary.
135+
136+
137+
## Testing / Development
138+
139+
This gem is to be tested inside of docker/docker-compose. [Combustion](https://github.com/pat/combustion), alongside rspec-rails and capybara, are the primary components for testing. To run the test, you'll need to have [Docker](https://docs.docker.com/engine/installation) installed. Once installed, run the following commands in the gem's root to build, run, and shell into the docker container.
140+
141+
```Bash
142+
docker-compose build
143+
docker-compose up -d
144+
docker exec -it $(cat app_container_name) /bin/bash
145+
```
146+
147+
Once shell'd in, run `bundle exec rspec spec` to run the test. The test rails app lives in `spec/internal`, and it can be viewed locally at `http://localhost:9292/`
148+
125149

126150
## Versions
127151

@@ -135,8 +159,6 @@ major version bump = major-level updates to critical-path-css-rails, Penthouse,
135159

136160
## Contributing
137161

138-
Feel free to open an issue ticket if you find something that could be improved. A couple notes:
139-
140-
* If the Penthouse.js script is outdated (i.e. maybe a new version of Penthouse.js was released yesterday), feel free to open an issue and prod us to get that thing updated. However, for security reasons, we won't be accepting pull requests with updated Penthouse.js script.
162+
Feel free to open an issue ticket if you find something that could be improved.
141163

142-
Copyright Mudbug Media and Michael Misshore, released under the MIT License.
164+
Copyright Mudbug Media and Michael Misshore, released under the MIT License.

app_container_name

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
criticalpathcss_ruby

config.ru

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'rubygems'
2+
require 'bundler'
3+
require 'combustion'
4+
5+
Combustion.initialize! :action_controller, :action_view
6+
run Combustion::Application

critical-path-css-rails.gemspec

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
require File.expand_path('../lib/critical_path_css/rails/version', __FILE__)
22

3-
Gem::Specification.new do |s|
4-
s.name = 'critical-path-css-rails'
5-
s.version = CriticalPathCSS::Rails::VERSION
6-
s.platform = Gem::Platform::RUBY
7-
s.authors = ['Michael Misshore']
8-
s.email = 'mmisshore@gmail.com'
9-
s.summary = 'Critical Path CSS for Rails!'
10-
s.description = 'Only load the CSS you need for the initial viewport in Rails!'
11-
s.license = 'MIT'
3+
Gem::Specification.new do |gem|
4+
gem.name = 'critical-path-css-rails'
5+
gem.version = CriticalPathCSS::Rails::VERSION
6+
gem.platform = Gem::Platform::RUBY
7+
gem.authors = ['Michael Misshore']
8+
gem.email = 'mmisshore@gmail.com'
9+
gem.summary = 'Critical Path CSS for Rails!'
10+
gem.description = 'Only load the CSS you need for the initial viewport in Rails!'
11+
gem.license = 'MIT'
1212

13-
s.files = `git ls-files`.split("\n")
14-
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
15-
s.require_path = 'lib'
13+
gem.files = `git ls-files`.split("\n")
14+
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
15+
gem.require_path = 'lib'
1616

17-
s.add_development_dependency 'rspec', '~> 3.6'
17+
gem.add_development_dependency 'combustion', '~> 0.7.0'
1818

19-
s.extensions = ['ext/npm/extconf.rb']
19+
gem.extensions = ['ext/npm/extconf.rb']
2020
end

docker-compose.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: '2'
2+
services:
3+
ruby:
4+
build:
5+
context: .
6+
dockerfile: docker/ruby/Dockerfile
7+
ports:
8+
- 9292:9292
9+
volumes:
10+
- .:/app:rw
11+
volumes_from:
12+
- data
13+
env_file: docker/ruby/.env
14+
container_name: criticalpathcss_ruby
15+
data:
16+
build:
17+
context: .
18+
dockerfile: docker/ruby/Dockerfile
19+
volumes:
20+
- /gems
21+
command: "true"

docker/ruby/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
RAILS_ENV=development

docker/ruby/Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM ruby:2.5.0
2+
3+
# Install Dependencies
4+
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
5+
RUN apt-get update && apt-get install -y build-essential libpq-dev nodejs npm
6+
7+
# Install Penthouse JS Dependencies
8+
RUN apt-get install -y libpangocairo-1.0-0 libx11-xcb1 libxcomposite1 libxcursor1 libxdamage1 libxi6 libxtst6 libnss3 libcups2 libxss1 libxrandr2 libgconf2-4 libasound2 libatk1.0-0 libgtk-3-0
9+
10+
RUN npm cache clean -f
11+
RUN npm install -g n
12+
RUN n 8.9.3
13+
RUN ln -sf /usr/local/n/versions/node/8.9.3/bin/node /usr/bin/nodejs
14+
15+
ENV BUNDLE_PATH /gems
16+
17+
WORKDIR /app
18+
19+
COPY docker/ruby/startup.dev /usr/local/bin/startup
20+
RUN chmod 755 /usr/local/bin/startup
21+
CMD "/usr/local/bin/startup"

docker/ruby/startup.dev

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
bundle check || bundle install
4+
bundle update critical-path-css-rails
5+
6+
bundle exec rackup --host 0.0.0.0

ext/npm/extconf.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
File.write 'Makefile',
22
"make:\n\t\ninstall:\n\truby install.rb\nclean:\n\t\n"
3-

lib/critical-path-css-rails.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'critical_path_css/rails/config_loader'
44

55
module CriticalPathCss
6-
CACHE_NAMESPACE = 'critical-path-css'
6+
CACHE_NAMESPACE = 'critical-path-css'.freeze
77

88
def self.generate(route, expires_in: nil)
99
::Rails.cache.write(

lib/critical_path_css/configuration.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
require 'erb'
22
module CriticalPathCss
33
class Configuration
4-
54
def initialize(config)
65
@config = config
76
end

lib/critical_path_css/css_fetcher.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def css_for_route(route)
3333
# '^\.regexWorksToo'
3434
],
3535
# ms; abort critical CSS generation after this timeout
36-
'timeout' => 30000,
36+
'timeout' => 30_000,
3737
# set to true to throw on CSS errors (will run faster if no errors)
3838
'strict' => false,
3939
# characters; strip out inline base64 encoded resources larger than this
@@ -44,11 +44,6 @@ def css_for_route(route)
4444
'renderWaitTime' => 100,
4545
# set to false to load (external) JS (default: true)
4646
'blockJSRequests' => true,
47-
# see `phantomjs --help` for the list of all available options
48-
'phantomJsOptions' => {
49-
'ignore-ssl-errors' => true,
50-
'ssl-protocol' => 'tlsv1'
51-
},
5247
'customPageHeaders' => {
5348
# use if getting compression errors like 'Data corrupted':
5449
'Accept-Encoding' => 'identity'

lib/critical_path_css/rails/config_loader.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
module CriticalPathCss
22
module Rails
33
class ConfigLoader
4-
CONFIGURATION_FILENAME = 'critical_path_css.yml'
4+
CONFIGURATION_FILENAME = 'critical_path_css.yml'.freeze
55

66
def load
7-
config = YAML.load(ERB.new(File.read(configuration_file_path)).result)[::Rails.env]
7+
config = YAML.safe_load(ERB.new(File.read(configuration_file_path)).result, [], [], true)[::Rails.env]
88
config['css_path'] = "#{::Rails.root}/public" + (
99
config['css_path'] ||
1010
ActionController::Base.helpers.stylesheet_path(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module CriticalPathCSS
22
module Rails
3-
VERSION = '1.0.0'
3+
VERSION = '2.3.0'.freeze
44
end
55
end

lib/generators/critical_path_css/install_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'rails/generators'
22

33
module CriticalPathCss
4-
class InstallGenerator < Rails::Generators::Base
4+
class InstallGenerator < ::Rails::Generators::Base
55
source_root File.expand_path('..', __FILE__)
66

77
# Copy the needed rake task for generating critical CSS

lib/npm_commands.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
# NPM wrapper with helpful error messages
44
class NpmCommands
5-
65
# @return [Boolean] whether the installation succeeded
7-
def install(*args) # rubocop:disable Metrics/MethodLength
6+
def install(*args)
87
return false unless check_nodejs_installed
98
STDERR.puts 'Installing npm dependencies...'
109
install_status = Dir.chdir File.expand_path('..', File.dirname(__FILE__)) do
@@ -24,7 +23,7 @@ def install(*args) # rubocop:disable Metrics/MethodLength
2423

2524
private
2625

27-
def check_nodejs_installed # rubocop:disable Metrics/MethodLength
26+
def check_nodejs_installed
2827
return true if executable?('node')
2928
STDERR.puts(
3029
'-' * 60,

package-lock.json

Lines changed: 4 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "critical-path-css-rails",
3-
"version": "1.0.0",
3+
"version": "2.3.0",
44
"description": "NPM dependencies of critical-path-css-rails",
55
"private": true,
66
"directories": {

0 commit comments

Comments
 (0)