purgecss_rails 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +72 -0
- data/Rakefile +27 -0
- data/lib/purgecss_rails.rb +23 -0
- data/lib/purgecss_rails/builder.rb +67 -0
- data/lib/purgecss_rails/version.rb +3 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0cc2d4d2e912a40049906bdd59ad44980b5339d6eb2e04a141ae9a657168ed38
|
4
|
+
data.tar.gz: 8922f762b735a68d340c4794667930900d0182279f59094316cef6690b810510
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4b0066cc05354fb384a0375a4d683247957b49a9914ea4550536fbc75dbaf4f4b362a5f0de8861d71258d1485028170cda20db27e17c0a5a3a2c25652b8e5702
|
7
|
+
data.tar.gz: 740d9640affe431606042f67ea75d014968befda50fc9fc39b1e07639cbaea4d206a316b202765b898469c36feed2b3ebb932a338ed2782ff230d9be7d9a5c0c
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2019 sebi
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# PurgecssRails
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'purgecss_rails', require: false
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
```bash
|
15
|
+
$ bundle
|
16
|
+
```
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
```bash
|
20
|
+
$ gem install purgecss_rails
|
21
|
+
```
|
22
|
+
|
23
|
+
Define a file lib/tasks/purge_css.rake and put:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require "purgecss_rails"
|
27
|
+
|
28
|
+
desc "PurgeCSS"
|
29
|
+
namespace :purge_css do
|
30
|
+
task :clear do
|
31
|
+
`rm public/assets/*.css -rf`
|
32
|
+
`rm public/assets/*.css.gz -rf`
|
33
|
+
end
|
34
|
+
|
35
|
+
task :run do
|
36
|
+
PurgecssRails.configure do |purge|
|
37
|
+
purge.search_css_files("public/assets/**/*.css")
|
38
|
+
|
39
|
+
purge.match_html_files "public/assets/**/*.js",
|
40
|
+
"app/views/**/*.html.erb",
|
41
|
+
"app/helpers/**/*.rb"
|
42
|
+
|
43
|
+
purge.optimize!
|
44
|
+
end.enable!.run_now!
|
45
|
+
end
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
If you need more precision in purging the css, ex engines:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
PurgecssRails.configure do |purge|
|
53
|
+
purge.search_css_files("public/assets/my_engine/application.css")
|
54
|
+
|
55
|
+
purge.match_html_files "public/assets/my_engine/application.js",
|
56
|
+
"engines/my_engine/views/**/*.html.erb",
|
57
|
+
"app/helpers/**/*.rb"
|
58
|
+
|
59
|
+
purge.optimize!
|
60
|
+
end.enable!.run_now!
|
61
|
+
```
|
62
|
+
|
63
|
+
When you are using an external engine and you don't want to purge their css file, add a ingore
|
64
|
+
```ruby
|
65
|
+
purge.search_css_files("public/assets/**/*.css", ignore: ['rails_admin'])
|
66
|
+
```
|
67
|
+
|
68
|
+
|
69
|
+
you can also call `purge.refresh!` and reuse the the `purge` object
|
70
|
+
|
71
|
+
## License
|
72
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'PurgecssRails'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'bundler/gem_tasks'
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
|
21
|
+
Rake::TestTask.new(:test) do |t|
|
22
|
+
t.libs << 'test'
|
23
|
+
t.pattern = 'test/**/*_test.rb'
|
24
|
+
t.verbose = false
|
25
|
+
end
|
26
|
+
|
27
|
+
task default: :test
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "purgecss_rails/builder"
|
2
|
+
|
3
|
+
module PurgecssRails
|
4
|
+
def self.configure(purge_css_path: "purgecss", &block)
|
5
|
+
@@purge_css_path = purge_css_path
|
6
|
+
@@configuration = block
|
7
|
+
self
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.enable!
|
11
|
+
@@enabled = true
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.run_now!
|
16
|
+
begin
|
17
|
+
@@enabled
|
18
|
+
rescue NameError
|
19
|
+
return
|
20
|
+
end
|
21
|
+
@@configuration.call(PurgecssRails::Builder.new(purge_css_path: @@purge_css_path))
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module PurgecssRails
|
2
|
+
class Builder
|
3
|
+
def initialize(purge_css_path:)
|
4
|
+
@purge_css_executable = purge_css_path
|
5
|
+
@css_files = []
|
6
|
+
end
|
7
|
+
|
8
|
+
def search_css_files(path, ignore: [])
|
9
|
+
@css_files += Dir[path]
|
10
|
+
@ignored_names = ignore
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
def match_html_files(*paths)
|
15
|
+
@html_files_match = paths
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def ignore_files
|
20
|
+
return @ignore_files if @ignore_files.present?
|
21
|
+
@ignore_files = @css_files.select do |f|
|
22
|
+
included = true
|
23
|
+
@ignored_names.each do |ignored_name|
|
24
|
+
if f.include?(ignored_name)
|
25
|
+
break included = false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
included
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def optimize!
|
33
|
+
print "\n"
|
34
|
+
ignore_files.each do |f|
|
35
|
+
print "purging #{f}\n"
|
36
|
+
end
|
37
|
+
|
38
|
+
@result = `#{purge_css_executable} --css #{ignore_files.join(" ")} --content #{html_files_match.join(" ")}`
|
39
|
+
@result = JSON.parse(result)
|
40
|
+
|
41
|
+
result.each do |result_item|
|
42
|
+
file_name = result_item["file"]
|
43
|
+
File.write(file_name, result_item["css"])
|
44
|
+
|
45
|
+
zipped = "#{file_name}.gz"
|
46
|
+
print "zipping #{zipped}\n"
|
47
|
+
|
48
|
+
Zlib::GzipWriter.open(zipped) do |gz|
|
49
|
+
gz.mtime = File.mtime(file_name)
|
50
|
+
gz.orig_name = file_name
|
51
|
+
gz.write IO.binread(file_name)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
self
|
55
|
+
end
|
56
|
+
|
57
|
+
def refresh!
|
58
|
+
@css_files = []
|
59
|
+
@html_files_match = []
|
60
|
+
@ignore_files = []
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
attr_reader :purge_css_executable, :css_files, :html_files_match, :result
|
66
|
+
end
|
67
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: purgecss_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- sebi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.2.3
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.2.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Reduce your css files considerably and improve your users experience
|
42
|
+
email:
|
43
|
+
- gore.sebyx@yahoo.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- MIT-LICENSE
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- lib/purgecss_rails.rb
|
52
|
+
- lib/purgecss_rails/builder.rb
|
53
|
+
- lib/purgecss_rails/version.rb
|
54
|
+
homepage: https://www.google.com
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubygems_version: 3.0.3
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: Use PurgeCSS with rails, designed for Asset Pipeline
|
77
|
+
test_files: []
|