jekyll-tidy 0.0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 58967e88bfd942d10fab9105034ef701b6d1d1b3
4
- data.tar.gz: 048887c85e9b68f6d605ae08e8e630f3db951f04
3
+ metadata.gz: c805bb34d487c1a46119f92371bebe325adc9832
4
+ data.tar.gz: fb1e1beb9d82ddab33e6b47996689d09ca264483
5
5
  SHA512:
6
- metadata.gz: 727a0f0223cdd15260c3c8578a7977f55c0ffce6547637ba0ae06395cf87890760f7c570ed985f955f5afd7b7274de9ee25c7dbd7237fa2aae7e45903ba43b1c
7
- data.tar.gz: 74ceaebe678217e8a5d091d08649de94ddb01c062a75b1dd1a0a3b7e368564c6a59a3d3c403aa1fd14b114088f16964d4c225dc6ad77f31c4bec8b973bf55767
6
+ metadata.gz: ad9d1ddccf895a04e817699c37597340d4c756eaa49825be958b3250289cdee1f4f6dd2049ed10ccef1a4c7bf816477270a5e39b051f39e7df95fb46bfd42a42
7
+ data.tar.gz: 415b64fbbdd4f2035061c5208bfd86fc9f756623880e8fca26b386d7e4ea9ba2e3799ce346496ea4ab77abb1ea1fcd782aa6f2bf5656a1443771336984fbe39b
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.14.3
data/LICENSE.txt CHANGED
@@ -1,22 +1,21 @@
1
- Copyright (c) 2016 Wyatt Kirby
1
+ The MIT License (MIT)
2
2
 
3
- MIT License
3
+ Copyright (c) 2017 Wyatt Kirby
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
12
11
 
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
15
14
 
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,19 +1,21 @@
1
1
  # Jekyll::Tidy
2
2
 
3
+ [![Build Status](https://travis-ci.org/apsislabs/jekyll-tidy.svg?branch=master)](https://travis-ci.org/apsislabs/jekyll-tidy)
4
+
3
5
  `jekyll-tidy` is a plugin for tidying the HTML output of your Jekyll website, using either `htmlbeautifier` or `htmlcompressor`.
4
6
 
5
7
  ## Usage
6
8
 
7
9
  Usage is straightforward. Simply include the gem in your `Gemfile` with:
8
10
 
9
- ```
10
- gem 'jekyll-tidy'
11
+ ```ruby
12
+ gem 'jekyll-tidy'
11
13
  ```
12
14
 
13
15
  And then include the plugin in a file located in your `_plugins` directory. You can also include the plugin using the `gems` option in your `_config.yml` file, like so:
14
16
 
15
17
  ```
16
- gems: [jekyll-tidy]
18
+ gems: [jekyll-tidy]
17
19
  ```
18
20
 
19
21
  **Note**: if you set the `compress_html` option to `true` and your templates have inline CSS or javascript, it will not be minified.
@@ -23,15 +25,58 @@ And then include the plugin in a file located in your `_plugins` directory. You
23
25
  `jekyll-tidy` takes two configuration settings, an array of files to exclude, and a flag for whether or not to compress the HTML output.
24
26
 
25
27
  ```
26
- jekyll_tidy:
27
- exclude: [index.html]
28
- compress_html: true
28
+ jekyll_tidy:
29
+ exclude: ["index.html"]
30
+ compress_html: true
31
+ ignore_env: development
32
+ ```
33
+
34
+ ### exclude (default: [])
35
+
36
+ `exclude` is an array of relative file paths that will be ignored by `jekyll-tidy`. Exclude must be set as an array, or it will cause errors.
37
+
38
+ ```
39
+ exclude: ["index.html"] # excludes only index.html
29
40
  ```
30
41
 
42
+ `exclude` can also take a glob of file paths. *Note:* File globs must be wrapped with `""`.
43
+
44
+ ```
45
+ exclude: ["_posts/*.md"] # excludes all markdown files directly within the posts directory.
46
+ exclude: ["_posts/**/*.md"] # excludes all markdown files anywhere within the _posts directory
47
+ ```
48
+
49
+ ### compress_html (default: false)
50
+
51
+ If `compress_html` is set to `true` then `htmlcompressor` will be used to tidy the markup. If it
52
+ is set to `false` then `htmlbeautifier` will be used to tidy the markup.
53
+
54
+ ### ignore_env (default: nil)
55
+
56
+ If `ignore_env` is set to a string, we will check the `JEKYLL_ENV` environment variable and skip tidying if it matches. Setting `_config.yml` with:
57
+
58
+ ```
59
+ ignore_env: development
60
+ ```
61
+
62
+ And then running jekyll with:
63
+
64
+ ```sh
65
+ $ JEKYLL_ENV=development jekyll serve
66
+ ```
67
+
68
+ Will skip all tidying.
69
+
70
+ ## Development
71
+
72
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
73
+
74
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
75
+
31
76
  ## Contributing
32
77
 
33
- 1. Fork it ( https://github.com/[my-github-username]/jekyll-tidy/fork )
34
- 2. Create your feature branch (`git checkout -b my-new-feature`)
35
- 3. Commit your changes (`git commit -am 'Add some feature'`)
36
- 4. Push to the branch (`git push origin my-new-feature`)
37
- 5. Create a new Pull Request
78
+ Bug reports and pull requests are welcome on GitHub at https://github.com/apsislabs/jekyll-tidy.
79
+
80
+ ## License
81
+
82
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,2 +1,10 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rake/testtask"
2
3
 
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jekyll/tidy"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/jekyll-tidy.gemspec CHANGED
@@ -8,19 +8,23 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Jekyll::Tidy::VERSION
9
9
  spec.authors = ["Wyatt Kirby"]
10
10
  spec.email = ["wyatt@apsis.io"]
11
+
11
12
  spec.summary = %q{Sanitize and Tidy HTML Output for Jekyll}
12
13
  spec.homepage = "http://www.apsis.io"
13
14
  spec.license = "MIT"
14
15
 
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)/})
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
21
  spec.require_paths = ["lib"]
19
22
 
20
- spec.add_dependency "jekyll"
21
- spec.add_dependency "htmlbeautifier"
22
- spec.add_dependency "htmlcompressor"
23
+ spec.add_runtime_dependency "jekyll"
24
+ spec.add_runtime_dependency "htmlbeautifier"
25
+ spec.add_runtime_dependency "htmlcompressor"
23
26
 
24
- spec.add_development_dependency "bundler", "~> 1.6"
25
- spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "bundler", "~> 1.14"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "minitest", "~> 5.0"
26
30
  end
data/lib/jekyll/tidy.rb CHANGED
@@ -1,45 +1,59 @@
1
+ require "jekyll/tidy/version"
2
+
1
3
  require "jekyll"
2
4
  require "htmlbeautifier"
3
5
  require "htmlcompressor"
4
6
 
5
- JEKYLL_CONFIG = Jekyll.configuration({})
6
-
7
7
  module Jekyll
8
- module Tidy
9
- def self.exclude?(path)
10
- res = false
11
- exclude = JEKYLL_CONFIG['jekyll_tidy'] && JEKYLL_CONFIG['jekyll_tidy']['exclude']
12
-
13
- if exclude
14
- res = exclude.to_a.include? path
15
- end
16
-
17
- return res
18
- end
19
-
20
- def self.compress_html?
21
- JEKYLL_CONFIG['jekyll_tidy'] && JEKYLL_CONFIG['jekyll_tidy']['compress_html']
22
- end
23
-
24
- def self.output_clean(output)
25
- if compress_html?
26
- compressor = HtmlCompressor::Compressor.new
27
- return compressor.compress output
28
- else
29
- return HtmlBeautifier.beautify output
30
- end
31
- end
8
+ module Tidy
9
+ def self.init(site)
10
+ @JEKYLL_CONFIG = site.config
11
+ end
12
+
13
+ def self.jekyll_config
14
+ @JEKYLL_CONFIG || Jekyll.configuration({})
15
+ end
16
+
17
+ def self.exclude?(path, override = {})
18
+ exclude_paths = jekyll_config.merge(override).dig("jekyll_tidy", "exclude").to_a
19
+ exclude_paths.any? { |exclude| File.fnmatch(exclude, path) }
20
+ end
21
+
22
+ def self.compress_output?
23
+ jekyll_config.dig("jekyll_tidy", "compress_html")
32
24
  end
33
- end
34
25
 
35
- Jekyll::Hooks.register :posts, :post_render do |post|
36
- unless Jekyll::Tidy::exclude?(post.path)
37
- post.output = Jekyll::Tidy::output_clean(post.output)
26
+ def self.output_clean(output, compress = false)
27
+ if compress
28
+ return HtmlCompressor::Compressor.new.compress output
29
+ else
30
+ return HtmlBeautifier.beautify output
31
+ end
38
32
  end
33
+
34
+ def self.ignore_env?
35
+ Jekyll.env == jekyll_config.dig("jekyll_tidy", "ignore_env")
36
+ end
37
+ end
38
+ end
39
+
40
+ # Jekyll Hooks
41
+ # -------------------------------------
42
+
43
+ Jekyll::Hooks.register :site, :after_reset do |jekyll|
44
+ Jekyll::Tidy.init(jekyll)
45
+ end
46
+
47
+ Jekyll::Hooks.register :documents, :post_render do |doc|
48
+ next if Jekyll::Tidy.ignore_env?
49
+ unless Jekyll::Tidy::exclude?(doc.relative_path)
50
+ doc.output = Jekyll::Tidy::output_clean(doc.output, Jekyll::Tidy.compress_output?)
51
+ end
39
52
  end
40
53
 
41
54
  Jekyll::Hooks.register :pages, :post_render do |page|
42
- unless Jekyll::Tidy::exclude?(page.path)
43
- page.output = Jekyll::Tidy::output_clean(page.output)
44
- end
55
+ next if Jekyll::Tidy.ignore_env?
56
+ unless Jekyll::Tidy::exclude?(page.relative_path)
57
+ page.output = Jekyll::Tidy::output_clean(page.output, Jekyll::Tidy.compress_output?)
58
+ end
45
59
  end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Tidy
3
- VERSION = "0.0.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-tidy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wyatt Kirby
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-25 00:00:00.000000000 Z
11
+ date: 2017-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -58,28 +58,42 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.6'
61
+ version: '1.14'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.6'
68
+ version: '1.14'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '10.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '5.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '5.0'
83
97
  description:
84
98
  email:
85
99
  - wyatt@apsis.io
@@ -88,10 +102,13 @@ extensions: []
88
102
  extra_rdoc_files: []
89
103
  files:
90
104
  - ".gitignore"
105
+ - ".travis.yml"
91
106
  - Gemfile
92
107
  - LICENSE.txt
93
108
  - README.md
94
109
  - Rakefile
110
+ - bin/console
111
+ - bin/setup
95
112
  - jekyll-tidy.gemspec
96
113
  - lib/jekyll-tidy.rb
97
114
  - lib/jekyll/tidy.rb
@@ -116,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
133
  version: '0'
117
134
  requirements: []
118
135
  rubyforge_project:
119
- rubygems_version: 2.2.2
136
+ rubygems_version: 2.6.8
120
137
  signing_key:
121
138
  specification_version: 4
122
139
  summary: Sanitize and Tidy HTML Output for Jekyll