jekyll-pants 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 937c218b14420def96bf1b9bfea8ed597435ffb6
4
- data.tar.gz: 69ab767f91cd8f89636d6f63af0d05351c5c156c
3
+ metadata.gz: 18cd8e967afd6c5cbe5f220f62bf0134f7a780f1
4
+ data.tar.gz: 2a62173d28a1f8f907e8bdcafb30a8d9a4fd8fff
5
5
  SHA512:
6
- metadata.gz: 537a616a5077e5c3f6c73b9e70530bc2c1ff745229ca175071ca9e7cf8c70494eb4b61bedd5ff8c8758be671f20b514bb99899ec662685a3e7e6cf83e6980275
7
- data.tar.gz: e501349f08242354c6a629ef06e2eae7e0acc3bda4c794a5ef8b1800868582898be2279a305fa1a3a3add05e3b78d16977be4ccfdd4015853464b23d8561f8a9
6
+ metadata.gz: d2e544e0b3be9ffac0235fda920b541a0dfb4c4a7ba92028f1075b251530fc03939bd55c27e88cf064a709836537b8786ac183220f3b0235a6ef418ee1566422
7
+ data.tar.gz: e926cedaba9ca6595fd245360fd0c62efe1dfd99b04755b43925c3ce712e40936644922b3c04e7dd9446c931e0def65e2eb927cc7064df5751721e8c53a90cbd
data/.gitignore CHANGED
@@ -4,6 +4,7 @@
4
4
  /coverage/
5
5
  /InstalledFiles
6
6
  /pkg/
7
+ /spec/dest/
7
8
  /spec/reports/
8
9
  /spec/examples.txt
9
10
  /test/tmp/
data/.travis.yml CHANGED
@@ -5,18 +5,23 @@ rvm:
5
5
  - 2.0
6
6
  - 2.1
7
7
  - 2.2
8
+ - 2.3.0
8
9
  matrix:
9
10
  include:
10
11
  - # GitHub Pages
11
12
  rvm: 2.1.1
12
13
  env: JEKYLL_VERSION=2.4.0
13
14
  - rvm: 1.9.3
14
- env: JEKYLL_VERSION=2.5
15
+ env:
16
+ - JEKYLL_VERSION=2.5
17
+ # codecov pulls in json, breaks on 1.9.3
18
+ # https://travis-ci.org/scampersand/jekyll-pants/builds/167216488
19
+ - CODECOV=false
15
20
  env:
16
21
  matrix:
17
22
  - JEKYLL_VERSION=2.5
18
23
  - JEKYLL_VERSION=3.0
19
- - JEKYLL_VERSION=3.2.0.pre.beta1
24
+ - JEKYLL_VERSION=3.2.1
20
25
  install:
21
26
  - bundle install
22
27
  script:
data/Gemfile CHANGED
@@ -5,6 +5,6 @@ if ENV["JEKYLL_VERSION"]
5
5
  gem "jekyll", "~> #{ENV["JEKYLL_VERSION"]}"
6
6
  end
7
7
 
8
- if RUBY_VERSION >= "2"
9
- gem "json"
8
+ if ENV["CODECOV"] != "false"
9
+ gem 'codecov', :require => false, :group => :test
10
10
  end
data/README.md CHANGED
@@ -1,4 +1,101 @@
1
1
  # jekyll-pants
2
2
 
3
- [![build status](https://img.shields.io/travis/agriffis/jekyll-pants/master.svg?style=plastic)](https://travis-ci.org/agriffis/jekyll-pants?branch=master)
4
- [![gem](https://img.shields.io/gem/v/jekyll-pants.svg)]()
3
+ [![gem](https://img.shields.io/gem/v/jekyll-pants.svg?maxAge=2592000&style=plastic)](https://rubygems.org/gems/jekyll-pants)
4
+ [![travis](https://img.shields.io/travis/scampersand/jekyll-pants.svg?maxAge=2592000&style=plastic)](https://travis-ci.org/agriffis/jekyll-pants)
5
+ [![codecov](https://img.shields.io/codecov/c/github/scampersand/jekyll-pants.svg?maxAge=2592000&style=plastic)](https://codecov.io/gh/scampersand/jekyll-pants)
6
+
7
+ Jekyll-Pants is a [Jekyll](http://jekyllrb.com/) plugin to convert plain ASCII
8
+ punctuation to typographic punctuation HTML entities. It relies on
9
+ [RubyPants](https://github.com/jmcnevin/rubypants) which is a Ruby port of the
10
+ smart-quotes library SmartyPants.
11
+
12
+ <table>
13
+ <tr><th>Input</th><th>Output</th><th>Rendered</th></tr>
14
+ <tr>
15
+ <td valign=top><pre>Here's an example--as
16
+ you can see...</pre></td>
17
+ <td valign=top><pre>Here&amp;#8217;s an example&amp;#8212;as
18
+ you can see&amp;#8230;</pre></td>
19
+ <td valign=top>Here&#8217;s an example&#8212;as you can see&#8230;</td>
20
+ </tr>
21
+ </table>
22
+
23
+
24
+ ## Rationale
25
+
26
+ This plugin exists because the default Jekyll support for smart quotes is limited to:
27
+
28
+ 1. [Markdown](https://daringfireball.net/projects/markdown/) parsed by
29
+ [kramdown](http://kramdown.gettalong.org/) (see note below for how to
30
+ disable kramdown's quoting in favor of jekyll-pants).
31
+
32
+ 2. The [smartify](https://jekyllrb.com/docs/templates/#filters) filter which is
33
+ actually another way to invoke kramdown's markdown processor, so it doesn't
34
+ work as desired on HTML.
35
+
36
+ Unlike the built-in solutions, jekyll-pants works on HTML, making it suitable
37
+ for applying typographic punctuation to an entire site of hand-authored HTML pages.
38
+
39
+ ## Usage
40
+
41
+ Add `jekyll-pants` to your site's Gemfile in the `:jekyll-plugins` group and run
42
+ `bundle` to install and update Gemfile.lock:
43
+
44
+ ```ruby
45
+ group :jekyll_plugins do
46
+ gem "jekyll-pants"
47
+ end
48
+ ```
49
+
50
+ In your base layout, filter the content through the `pants` filter:
51
+
52
+ ```liquid
53
+ <!DOCTYPE html>
54
+ <html>
55
+ <head>...</head>
56
+ <body>
57
+ {{content|pants}}
58
+ </body>
59
+ </html>
60
+ ```
61
+
62
+ Since RubyPants parses HTML tags, this will apply typographic quoting, dashes
63
+ and ellipses to text content, but will ignore preformatted text in `<pre>` and `<script>`.
64
+
65
+ ## Configuration
66
+
67
+ By default, this plugin invokes RubyPants with no options, so RubyPants runs in
68
+ its default mode which is "old-school." In old-school mode, double-dash
69
+ translates to an en-dash and triple-dash translates to an em-dash.
70
+
71
+ This can be modified in Jekyll's `_config.yml` under the `pants` key, for
72
+ example:
73
+
74
+ ```yaml
75
+ pants:
76
+ options: [1, :prevent_breaks]
77
+ entities: {:em_dash => '&mdash;'}
78
+ ```
79
+
80
+ For the available options, see https://github.com/jmcnevin/rubypants/blob/master/lib/rubypants/core.rb
81
+
82
+ ## Compatibility with kramdown
83
+
84
+ Jekyll's default markdown processor
85
+ is [kramdown](http://kramdown.gettalong.org/), and by default kramdown applies
86
+ smart quoting and typographic substitutions. Its algorithm works a little
87
+ differently from RubyPants which means that you'll get mixed results with
88
+ content coming from both markdown and HTML sources.
89
+
90
+ Jekyll-Pants supplies a parser subclass as
91
+ [recommended by kramdown's author](https://github.com/gettalong/kramdown/pull/379).
92
+ The subclass is called `Pantsdown` and removes the `:smart_quotes` and
93
+ `:typographic_syms` span parsers from the list.
94
+
95
+ To use this subclass and thereby defer to RubyPants for
96
+ quotes, dashes and ellipses, put the following in your `_config.yml`:
97
+
98
+ ```yaml
99
+ kramdown:
100
+ input: Pantsdown
101
+ ```
data/jekyll-pants.gemspec CHANGED
@@ -1,10 +1,10 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "jekyll-pants"
3
3
  spec.summary = "Jekyll plugin to run rubypants on generated HTML"
4
- spec.version = "0.1.0"
4
+ spec.version = "0.2.0"
5
5
  spec.authors = ["Aron Griffis"]
6
6
  spec.email = "aron@scampersand.com"
7
- spec.homepage = "https://github.com/agriffis/jekyll-pants"
7
+ spec.homepage = "https://github.com/scampersand/jekyll-pants"
8
8
  spec.licenses = ["MIT"]
9
9
 
10
10
  spec.files = `git ls-files -z`.split("\x0")
@@ -1,11 +1,2 @@
1
- require 'rubypants'
2
-
3
- module Jekyll
4
- module PantsFilter
5
- def pants(input)
6
- RubyPants.new(input, options=[1]).to_html
7
- end
8
- end
9
- end
10
-
11
- Liquid::Template.register_filter(Jekyll::PantsFilter)
1
+ require_relative 'pants/filter'
2
+ require_relative 'pants/down'
@@ -0,0 +1,12 @@
1
+ require 'kramdown/parser'
2
+
3
+ module Kramdown
4
+ module Parser
5
+ class Pantsdown < Kramdown::Parser::Kramdown
6
+ def initialize(source, options)
7
+ super
8
+ @span_parsers -= [:smart_quotes, :typographic_syms]
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,30 @@
1
+ require 'rubypants'
2
+
3
+ module Jekyll
4
+ module PantsFilter
5
+ def pants(input)
6
+ config = @context.registers[:site].config['pants'] || {}
7
+
8
+ if config.include?('entities') && ! config.include?('options')
9
+ Jekyll.logger.warn <<EOF
10
+ Found pants.entities in config; you should also add pants.options
11
+ since they're positional arguments to RubyPants.new
12
+ EOF
13
+ end
14
+
15
+ args = []
16
+ if config.include?('options')
17
+ args.push(config['options'])
18
+ elsif config.include?('entities')
19
+ args.push([2]) # default in RubyPants
20
+ end
21
+ if config.include?('entities')
22
+ args.push(config['entities'])
23
+ end
24
+
25
+ RubyPants.new(input, *args).to_html
26
+ end
27
+ end
28
+ end
29
+
30
+ Liquid::Template.register_filter(Jekyll::PantsFilter)
@@ -17,13 +17,13 @@ describe(Jekyll::PantsFilter) do
17
17
  let(:markdown_output) { File.read(dest_dir("markdown/with-pants.html")) }
18
18
 
19
19
  it "makes HTML pretty" do
20
- expect(html_output).to match /#{Regexp.quote "Makin&#8217; it purty&#8212;don&#8217;t you think?"}/
20
+ expect(html_output).to match /#{Regexp.quote "Makin&#8217; it purty&#8211;don&#8217;t you think?"}/
21
21
  expect(html_output).to_not match /Makin'|purty--don|don't/
22
22
  end
23
23
 
24
24
  it "preserves HTML pre" do
25
25
  expect(html_output).to match /#{Regexp.quote "But not this! This shouldn't be pretty--because it's code."}/
26
- expect(html_output).to_not match /shouldn\&#8217;t|pretty\&#8212;because/
26
+ expect(html_output).to_not match /shouldn\&#8217;t|pretty\&#8211;because/
27
27
  end
28
28
 
29
29
  it "preserves kramdown smart quotes" do
@@ -33,7 +33,19 @@ describe(Jekyll::PantsFilter) do
33
33
 
34
34
  it "preserves code in markdown" do
35
35
  expect(markdown_output).to match /#{Regexp.quote "But not this! This shouldn't be pretty--because it's code."}/
36
- expect(markdown_output).to_not match /shouldn\&#8217;t|pretty\&#8212;because/
36
+ expect(markdown_output).to_not match /shouldn\&#8217;t|pretty\&#8211;because/
37
+ end
38
+
39
+ context "with Pantsdown" do
40
+ let(:config) do
41
+ config_pantsdown = {"kramdown" => {"input" => "Pantsdown"}}
42
+ Jekyll.configuration(Jekyll::Utils.deep_merge_hashes(overrides, config_pantsdown))
43
+ end
44
+
45
+ it "makes markdown pretty" do
46
+ expect(markdown_output).to match /#{Regexp.quote "Makin&#8217; it purty&#8211;don&#8217;t you think?"}/
47
+ expect(markdown_output).to_not match /Makin'|purty--don|don't/
48
+ end
37
49
  end
38
50
 
39
51
  context "without kramdown smart quotes" do
@@ -70,4 +82,38 @@ describe(Jekyll::PantsFilter) do
70
82
  end
71
83
  end
72
84
 
85
+ context "with config" do
86
+ let(:config) do
87
+ pants_config = {
88
+ 'pants' => {
89
+ # 1 means -- is em-dash
90
+ 'options' => [1],
91
+ 'entities' => {:em_dash => '_mmm_', :en_dash => '_nnn_'},
92
+ }
93
+ }
94
+ Jekyll.configuration(Jekyll::Utils.deep_merge_hashes(overrides, pants_config))
95
+ end
96
+
97
+ it "honors the config" do
98
+ expect(html_output).to match /_mmm_/
99
+ expect(html_output).to_not match /_nnn_/
100
+ end
101
+ end
102
+
103
+ context "with lonely entities config" do
104
+ # this hits the warning and forces options => [2]
105
+ let(:config) do
106
+ pants_config = {
107
+ 'pants' => {
108
+ 'entities' => {:em_dash => '_mmm_', :en_dash => '_nnn_'},
109
+ }
110
+ }
111
+ Jekyll.configuration(Jekyll::Utils.deep_merge_hashes(overrides, pants_config))
112
+ end
113
+
114
+ it "honors the config" do
115
+ expect(html_output).to match /_nnn_/
116
+ expect(html_output).to_not match /_mmm_/
117
+ end
118
+ end
73
119
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,16 @@
1
+ begin
2
+ require 'simplecov'
3
+ SimpleCov.start
4
+ if ENV['CI'] == 'true'
5
+ require 'codecov'
6
+ SimpleCov.formatter = SimpleCov::Formatter::Codecov
7
+ end
8
+ rescue LoadError => e
9
+ if RUBY_VERSION >= '2'
10
+ raise e # codecov should exist according to Gemfile
11
+ end
12
+ end
13
+
1
14
  require 'jekyll'
2
15
  require File.expand_path('../lib/jekyll-pants', File.dirname(__FILE__))
3
16
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-pants
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aron Griffis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-19 00:00:00.000000000 Z
11
+ date: 2016-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubypants
@@ -66,10 +66,8 @@ files:
66
66
  - jekyll-pants.gemspec
67
67
  - lib/jekyll-pants.rb
68
68
  - lib/jekyll/jekyll-pants.rb
69
- - spec/dest/html/with-pants.html
70
- - spec/dest/html/without-pants.html
71
- - spec/dest/markdown/with-pants.html
72
- - spec/dest/markdown/without-pants.html
69
+ - lib/jekyll/pants/down.rb
70
+ - lib/jekyll/pants/filter.rb
73
71
  - spec/fixtures/_config.yml
74
72
  - spec/fixtures/_layouts/with-pants.html
75
73
  - spec/fixtures/_layouts/without-pants.html
@@ -79,7 +77,7 @@ files:
79
77
  - spec/fixtures/markdown/without-pants.md
80
78
  - spec/jekyll-pants_spec.rb
81
79
  - spec/spec_helper.rb
82
- homepage: https://github.com/agriffis/jekyll-pants
80
+ homepage: https://github.com/scampersand/jekyll-pants
83
81
  licenses:
84
82
  - MIT
85
83
  metadata: {}
@@ -99,15 +97,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
97
  version: '0'
100
98
  requirements: []
101
99
  rubyforge_project:
102
- rubygems_version: 2.4.8
100
+ rubygems_version: 2.5.1
103
101
  signing_key:
104
102
  specification_version: 4
105
103
  summary: Jekyll plugin to run rubypants on generated HTML
106
104
  test_files:
107
- - spec/dest/html/with-pants.html
108
- - spec/dest/html/without-pants.html
109
- - spec/dest/markdown/with-pants.html
110
- - spec/dest/markdown/without-pants.html
111
105
  - spec/fixtures/_config.yml
112
106
  - spec/fixtures/_layouts/with-pants.html
113
107
  - spec/fixtures/_layouts/without-pants.html
@@ -1,8 +0,0 @@
1
- <p>
2
- Makin&#8217; it purty&#8212;don&#8217;t you think?
3
- </p>
4
-
5
- <pre>
6
- But not this! This shouldn't be pretty--because it's code.
7
- </pre>
8
-
@@ -1,8 +0,0 @@
1
- <p>
2
- It ain't purty--without pants.
3
- </p>
4
-
5
- <pre>
6
- Nor this--it ain't no better.
7
- </pre>
8
-
@@ -1,6 +0,0 @@
1
- <p>Makin’ it purty–don’t you think?</p>
2
-
3
- <div class="highlighter-rouge"><pre class="highlight"><code>But not this! This shouldn't be pretty--because it's code.
4
- </code></pre>
5
- </div>
6
-
@@ -1,6 +0,0 @@
1
- <p>It ain’t purty–without pants.</p>
2
-
3
- <div class="highlighter-rouge"><pre class="highlight"><code>Nor this--it ain't no better.
4
- </code></pre>
5
- </div>
6
-