jekyll-curse 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a52025f800aae283202635bfc21d33bb85d97a05
4
+ data.tar.gz: 65b3aacf197853c2f1fd85589b69ccfa8d5dd161
5
+ SHA512:
6
+ metadata.gz: 269932e1220cea8847589ebd0d6839d1f219acfe61a8ca06d7538d3fb026bf12664d4bb8a077e72bd8d179dfff7e7a0ed4b25e2f984c9e9a3fc15e3981073932
7
+ data.tar.gz: 95a8ee5d1859b58c41c627dc013c1e222c08c26a8f4f48b1c709f1056af25f76b5b139611414e2c5e07ade799d757a7c957cb1ae587822858faccf65335202b3
@@ -0,0 +1,8 @@
1
+ words: [
2
+ 'fuck',
3
+ 'shit',
4
+ 'shite',
5
+ 'cunt',
6
+ 'crap',
7
+ 'dick'
8
+ ]
@@ -0,0 +1,91 @@
1
+ require 'yaml'
2
+
3
+ module Jekyll
4
+ class CurseWords < Jekyll::Generator
5
+ @@not_allowed_extensions = [
6
+ '.scss',
7
+ '.less',
8
+ '.xml',
9
+ '.js',
10
+ '.coffee'
11
+ ]
12
+
13
+ @@replace_chars = ['*', '$', '%', '!', '#', '&']
14
+
15
+ def generate(site)
16
+ # Load up the yaml file containing all the curse words
17
+ load_words
18
+
19
+ # Remove curse words in all pages
20
+ site.pages.each do |page|
21
+ not_allowed = page_not_allowed(page.name)
22
+
23
+ page.content = remove_curse_word(page.content) if !not_allowed
24
+ end
25
+
26
+ # Remove curse words in all pots
27
+ site.posts.each do |post|
28
+ not_allowed = page_not_allowed(post.name)
29
+
30
+ post.content = remove_curse_word(post.content) if !not_allowed
31
+ end
32
+ end
33
+
34
+ # Private: Loads the YAML file with the curse words
35
+ def load_words
36
+ @@curse_words = YAML::load_file(File.join(__dir__, 'curse-words.yml'))['words']
37
+ end
38
+
39
+ # Private: Checks if the page should be checked based on not allowed extensions
40
+ #
41
+ # name - The name of the page
42
+ #
43
+ # Returns true/false on whether the page is allowed
44
+ def page_not_allowed(name)
45
+ @@not_allowed_extensions.any? do |word|
46
+ name.include?(word)
47
+ end
48
+ end
49
+
50
+ # Private: Removes any of the curse words from the content
51
+ #
52
+ # content - The page content
53
+ #
54
+ # Returns the content minus any curse words
55
+ def remove_curse_word(content)
56
+ # Search for any of the curse words
57
+ @@curse_words.each do |word|
58
+ regex = /#{word}/i
59
+ if found = content.match(regex)
60
+ # Mask the curse word
61
+ content = content.gsub!("#{found}", mask_curse_word(found.to_s))
62
+ puts content
63
+ end
64
+ end
65
+
66
+ content
67
+ end
68
+
69
+ # Private: Masks the curse word found
70
+ #
71
+ # word - Found curse word
72
+ #
73
+ # Returns the masked curse word
74
+ def mask_curse_word(word)
75
+ "#{word[0]}#{replace_letters(word[1..-2])}#{word[-1]}"
76
+ end
77
+
78
+ # Private: Replace letters with random characters
79
+ #
80
+ # letter - Letters to replace
81
+ #
82
+ # Returns the letters replace with chars
83
+ def replace_letters(letters)
84
+ l = letters.split('').map do |letter|
85
+ @@replace_chars.sample
86
+ end
87
+
88
+ l.join('')
89
+ end
90
+ end
91
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-curse
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Phil Hughes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - me@iamphill.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/curse-words.yml
21
+ - lib/jekyll-curse.rb
22
+ homepage: http://github.com/iamphill/jekyll-curse
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.4.2
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Remove curse words from Jekyll pages & posts.
46
+ test_files: []