jekyll-hyphenate_filter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a09f1859dd01c032edac992368b4b78ac18bcb3d
4
+ data.tar.gz: c2a0687578ca3b5ba22fd6fb311525d3d8752895
5
+ SHA512:
6
+ metadata.gz: 78c143b3f0f79ba74589232b5c86b8e70a8e8a5e81ea6209455db99bac553ac9d5507f4d8e37c82d0b56e4564e62ae23fab6c8d5c87066e2febd51cd85b0d441
7
+ data.tar.gz: 83322cc1dd9563fb55bf9902d9903662e4cb75b1dae23b7d65a550d0b9cb7b59a5999a7df7e6a10cd5c7d87a63a6912e6e723c0bdc1b05982468d10b1c5a2506
@@ -0,0 +1 @@
1
+ # Jekyll::HyphenateFilter ChangeLog
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+ gem "nokogiri"
3
+ gem "liquid"
4
+ gem "text-hyphen"
5
+ gem "test-unit"
data/Gemfile.lock ADDED
@@ -0,0 +1,23 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ liquid (3.0.6)
5
+ mini_portile2 (2.0.0)
6
+ nokogiri (1.6.7.2)
7
+ mini_portile2 (~> 2.0.0.rc2)
8
+ power_assert (0.2.2)
9
+ test-unit (3.0.8)
10
+ power_assert
11
+ text-hyphen (1.4.1)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ liquid
18
+ nokogiri
19
+ test-unit
20
+ text-hyphen
21
+
22
+ BUNDLED WITH
23
+ 1.10.5
data/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Michael Glaesemann
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,67 @@
1
+ # Jekyll HyphenateFilter
2
+
3
+ Jekyll Liquid filter to apply [Text::Hyphen][] to content.
4
+
5
+ [text::hyphen]: https://github.com/halostatue/text-hyphen
6
+
7
+ ## Installation
8
+
9
+ Install the `jekyll-hyphenate_filter` gem in a [Jekyll-approved
10
+ manner](https://jekyllrb.com/docs/plugins/#installing-a-plugin).
11
+
12
+ ## Use
13
+
14
+ To hyphenate content, you can use the filter like this:
15
+
16
+ {{ content | hyphenate }}
17
+
18
+ ## Configuration
19
+
20
+ There are a few configurable parameters which control hyphenation behavior.
21
+ These parameters are `language`, `left`, and `right`. These take the same
22
+ values as [Text::Hyphen][]. In brief:
23
+
24
+ * `language` - language of the content. Defaults to `en_us`.
25
+ * `left` - minimum number of characters to the left of the hyphen.
26
+ Defaults to 2.
27
+ * `right` - minimum number of characters to the right of the hyphen.
28
+ Defaults to 2.
29
+
30
+ In addition, you can specify the string used to indicate hyphenation points
31
+ with the `hyphen` parameter. The default is the UTF-8 soft-hyphen character
32
+ (Unicode code U+00AD). Note that this is the UTF-8 character, not an entity.
33
+
34
+ You can update `_config.yml` to set these parameters. For example:
35
+
36
+ hyphenate_filter:
37
+ language: en_uk
38
+ left: 4
39
+ right: 3
40
+ hyphen: "­"
41
+
42
+ This configuration sets the language to UK English, with a minimum of 4
43
+ characters to the left of the hyphenation, minimum 3 characters to the right,
44
+ and the HTML entity `­` to indicate hyphenation points.
45
+
46
+ ## Notes
47
+
48
+ HyphenateFilter builds upon the [Jekyll::HyphenateFilter][] from
49
+ [Jekyll plugins by Aucor][aucor-jekyll-plugins].
50
+
51
+ Two behavior differences between the Aucor Oy filter (as of 2013-09-20) and the
52
+ one provided here:
53
+
54
+ * This filter will descend into subelements (such as tags). Paragraphs
55
+ containing tags is effectively skipped by the Aucor Oy filter.
56
+ * The Aucor Oy filter rightly does not hyphenate the final word of a paragraph.
57
+ However, all instances of that word in the paragraph will not be hyphenated.
58
+ This filter does not special case the final word in the paragraph: all words
59
+ are subject to the hyphenation rules.
60
+
61
+ [Jekyll::HyphenateFilter]: https://github.com/aucor/jekyll-plugins/blob/1bbc2aeacc24c816a0f1cad74c71f3ccd4eb307b/hyphenate.rb
62
+ [aucor-jekyll-plugins]: https://github.com/aucor/jekyll-plugins
63
+
64
+ ## Copyright
65
+
66
+ Copyright 2016 Michael Glaesemann. Released under the MIT License (see LICENSE
67
+ for details).
@@ -0,0 +1,36 @@
1
+ lib = File.expand_path("../lib/", __FILE__)
2
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
3
+ require "rake"
4
+ require "jekyll/hyphenate_filter/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jekyll-hyphenate_filter"
8
+ spec.version = Jekyll::HyphenateFilter::VERSION
9
+ spec.licenses = ["MIT"]
10
+ spec.summary = "jekyll-hyphenate_filter"
11
+ spec.date = "2016-05-01"
12
+ spec.description = "Jekyll Hyphenation Filter"
13
+ spec.authors = ["Michael Glaesemann"]
14
+ spec.email = ["grzm@seespotcode.net"]
15
+ spec.files = FileList["{lib,test}/**/*.*",
16
+ "jekyll-hyphenate_filter.gemspec",
17
+ "rakefile",
18
+ "LICENSE",
19
+ "README.markdown",
20
+ "CHANGELOG.markdown",
21
+ "Gemfile",
22
+ "Gemfile.lock"].to_a
23
+ spec.require_path = %(lib)
24
+ spec.test_files = FileList["test/**/*.*"].to_a
25
+ spec.extra_rdoc_files = ["LICENSE", "README.markdown"]
26
+ spec.homepage = "http://rubygems.org/gems/jekyll-hyphenate_filter"
27
+ [["text-hyphen", ["~> 1.4"]],
28
+ ["nokogiri", ["~> 1.6"]]].each do |dep|
29
+ spec.add_runtime_dependency(*dep)
30
+ end
31
+
32
+ [["test-unit", ["~> 3.0"]]].each do |dep|
33
+ spec.add_development_dependency(*dep)
34
+ end
35
+
36
+ end
@@ -0,0 +1,47 @@
1
+ # coding: utf-8
2
+ require "nokogiri"
3
+ require "text/hyphen"
4
+
5
+ module Jekyll
6
+ module HyphenateFilter
7
+ class Hyphenator
8
+
9
+ SOFT_HYPHEN_CHAR = '­'
10
+ SOFT_HYPHEN_ENTITY = '­'
11
+
12
+ def initialize(opts = {})
13
+ language = opts[:language] || "en_us"
14
+ left = opts[:left] || 2
15
+ right = opts[:right] || 2
16
+ @hyphenator = Text::Hyphen.new(language: language,
17
+ left: left,
18
+ right: right)
19
+ @hyphen = opts[:hyphen] || SOFT_HYPHEN_CHAR
20
+ @selector = opts[:selector] || 'p'
21
+ end
22
+
23
+ def hyphenate(content)
24
+ fragment = Nokogiri::HTML::DocumentFragment.parse(content)
25
+
26
+ fragment.css(@selector).each do |el|
27
+ el.traverse do |node|
28
+ node.content = hyphenate_text(node.to_s) if node.text?
29
+ end
30
+ end
31
+
32
+ fragment.to_s
33
+ end
34
+
35
+ def hyphenate_text(text)
36
+ words = text.split
37
+ words.each do |word|
38
+ regex = /#{Regexp.escape(word)}(?!\z)/
39
+ hyphenated_word = @hyphenator.visualize(word, @hyphen)
40
+ text.gsub!(regex, hyphenated_word)
41
+ end
42
+ text
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,5 @@
1
+ module Jekyll
2
+ module HyphenateFilter
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ require_relative "hyphenate_filter/hyphenator"
2
+
3
+ module Jekyll
4
+ module HyphenateFilter
5
+ def hyphenate(content)
6
+ config = @context.registers[:site].config['hyphenate_filter'] || {}
7
+ config = {'language' => 'en_us',
8
+ 'left' => 2,
9
+ 'right' => 2,
10
+ 'hyphen' => Hyphenator::SOFT_HYPHEN_CHAR,
11
+ 'selector' => 'p'}.merge!(config)
12
+ hyphenator = Hyphenator.new(language: config['language'],
13
+ left: config['left'],
14
+ right: config['right'],
15
+ hyphen: config['hyphen'],
16
+ selector: config['selector'])
17
+ hyphenator.hyphenate(content)
18
+ end
19
+ end
20
+ end
21
+
22
+ Liquid::Template.register_filter(Jekyll::HyphenateFilter)
data/rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ t.verbose = true
6
+ end
7
+
8
+ task :default => :test
@@ -0,0 +1,75 @@
1
+ # coding: utf-8
2
+ require "rubygems"
3
+ require "bundler/setup"
4
+ require_relative "../lib/jekyll/hyphenate_filter/hyphenator"
5
+ require "test/unit"
6
+
7
+ class TestHyphenate < Test::Unit::TestCase
8
+
9
+ def test_no_sub_elements
10
+ content = <<-EOS
11
+ <p>The nested set however, has performance limitations on insert, update, and
12
+ delete. This arises because the nested set model encodes the hierarchy based on
13
+ what the set contains: when a node is inserted or deleted, all of the sets
14
+ containing the node must be updated as well. In other words, the encoding
15
+ depends on the current state of the database. This behavior makes the nested set
16
+ model less desirable for large, dynamic hierarchies. There are limitations</p>
17
+ EOS
18
+ expected = <<-EOS
19
+ <p>The nested set how­ev­er, has per­for­mance lim­i­ta­tions on insert, update, and
20
+ delete. This arises because the nested set model encodes the hier­ar­chy based on
21
+ what the set con­tains: when a node is inserted or delet­ed, all of the sets
22
+ con­tain­ing the node must be updated as well. In other words, the encod­ing
23
+ depends on the cur­rent state of the data­base. This behav­ior makes the nested set
24
+ model less desir­able for large, dynamic hier­ar­chies. There are limitations</p>
25
+ EOS
26
+ hyphenated = Jekyll::HyphenateFilter::Hyphenator.new.hyphenate(content)
27
+ assert_equal(expected, hyphenated)
28
+ end
29
+
30
+ def test_with_tag
31
+ content = <<-EOS
32
+ <p>The <a href="https://example.com/path/to/article?id=100" title="article name">nested set model</a>
33
+ is a convenient way to represent hierarchies in SQL. By
34
+ taking advantage of the set nature of relations, it provides quick and
35
+ relatively simple queries to determine, for example, all descendants of a given
36
+ node. Such queries are more computationally difficult using adjacency lists.</p>
37
+ EOS
38
+ expected = <<-EOS
39
+ <p>The <a href="https://example.com/path/to/article?id=100" title="article name">nested set model</a>
40
+ is a con­ve­nient way to rep­re­sent hier­ar­chies in SQL. By
41
+ tak­ing advan­tage of the set nature of rela­tions, it pro­vides quick and
42
+ rel­a­tively sim­ple queries to deter­mine, for exam­ple, all descen­dants of a given
43
+ node. Such queries are more com­pu­ta­tion­ally dif­fi­cult using adja­cency lists.</p>
44
+ EOS
45
+ hyphenated = Jekyll::HyphenateFilter::Hyphenator.new.hyphenate(content)
46
+
47
+ assert_equal(expected, hyphenated)
48
+ end
49
+
50
+ def test_nested
51
+ content = <<-EOS
52
+ <ul>
53
+ <li>
54
+ <p>Vadim Tropashko, <cite><a href="https://example.com/path/to/article?id=100" title="Tropashko on nested intervals">Trees in SQL: Nested Sets and Materialized Path</a></cite></p>
55
+ </li>
56
+ <li>
57
+ <p>Vadim Tropashko, <cite><a href="https://example.com/path/to/article?id=200" title="Tropashko on relocating subtrees of nested intervals">Relocating Subtrees in Nested Intervals Model</a></cite></p>
58
+ </li>
59
+ </ul>
60
+ EOS
61
+ expected = <<-EOS
62
+ <ul>
63
+ <li>
64
+ <p>Vadim Tropashko, <cite><a href="https://example.com/path/to/article?id=100" title="Tropashko on nested intervals">Trees in SQL: Nested Sets and Mate­ri­al­ized Path</a></cite></p>
65
+ </li>
66
+ <li>
67
+ <p>Vadim Tropashko, <cite><a href="https://example.com/path/to/article?id=200" title="Tropashko on relocating subtrees of nested intervals">Relo­cat­ing Sub­trees in Nested Inter­vals Model</a></cite></p>
68
+ </li>
69
+ </ul>
70
+ EOS
71
+ hyphenated = Jekyll::HyphenateFilter::Hyphenator.new(selector: "p").hyphenate(content)
72
+ assert_equal(expected, hyphenated)
73
+ end
74
+
75
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-hyphenate_filter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michael Glaesemann
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: text-hyphen
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Jekyll Hyphenation Filter
56
+ email:
57
+ - grzm@seespotcode.net
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files:
61
+ - LICENSE
62
+ - README.markdown
63
+ files:
64
+ - CHANGELOG.markdown
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - LICENSE
68
+ - README.markdown
69
+ - jekyll-hyphenate_filter.gemspec
70
+ - lib/jekyll/hyphenate_filter.rb
71
+ - lib/jekyll/hyphenate_filter/hyphenator.rb
72
+ - lib/jekyll/hyphenate_filter/version.rb
73
+ - rakefile
74
+ - test/test_hyphenate.rb
75
+ homepage: http://rubygems.org/gems/jekyll-hyphenate_filter
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.4.5
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: jekyll-hyphenate_filter
99
+ test_files:
100
+ - test/test_hyphenate.rb