jekyll-mentions 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jekyll-mentions.rb +60 -27
  3. metadata +8 -23
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de119f82d968911efc9dd29bd45b94786f8f5aee
4
- data.tar.gz: 57e52a1c7b2df33f8d2b93a74331fb36f499bea8
3
+ metadata.gz: 3c627b00d759842a74836656d975af42eda10beb
4
+ data.tar.gz: 89ec283cdfa10d508e9c5853a9324b2bc7da5a02
5
5
  SHA512:
6
- metadata.gz: a7350185007b5a8b1ab764747a9b4b3f240dbe5fc6da8893c91f84117e33fe10190765b36cf5c736e099e951a571a39070b867fef36303ff78b9ad53ddc43207
7
- data.tar.gz: 29a45a3f2d6921050011213f03086e5136bdad8dee7e12719b71faad006eab02256372055d710b688fb80877e849b61e4d809ce02ba7eb8df2be1e0073c1376b
6
+ metadata.gz: 4b83bf2888de733d34a7611e15fcd712d4d69bec82e131a6b4a5f8f8f4987a4851745df8a3fae91f97c04dee5dd4f2917941b9c53dc04b7cbe63bd8b0977735a
7
+ data.tar.gz: 1a83a5c422315eff654a828e3d223bb7fc98b951519a09294b0f5a2fb215c9c8e196baeca6e449f7beb0dff539ba3861bb444e3cf5f06db786efd8d021c998ec
@@ -2,40 +2,73 @@ require 'jekyll'
2
2
  require 'html/pipeline'
3
3
 
4
4
  module Jekyll
5
- class Mentions < Jekyll::Generator
6
- safe true
5
+ class Mentions
6
+ GITHUB_DOT_COM = "https://github.com".freeze
7
7
 
8
- DEFAULT_URL = "https://github.com"
8
+ InvalidJekyllMentionConfig = Class.new(Jekyll::Errors::FatalException)
9
9
 
10
- def initialize(config = Hash.new)
11
- @filter = HTML::Pipeline::MentionFilter.new(nil, {:base_url => base_url(config['jekyll-mentions']) })
12
- end
10
+ class << self
11
+ def mentionify(doc)
12
+ src = mention_base(doc.site.config)
13
+ doc.output = filter_with_mention(src).call(doc.output)[:output].to_s
14
+ end
13
15
 
14
- def generate(site)
15
- site.pages.each { |page| mentionify page if html_page?(page) }
16
- site.docs_to_write.each { |doc| mentionify doc }
17
- end
16
+ # Public: Create or fetch the filter for the given {{src}} base URL.
17
+ #
18
+ # src - the base URL (e.g. https://github.com)
19
+ #
20
+ # Returns an HTML::Pipeline instance for the given base URL.
21
+ def filter_with_mention(src)
22
+ filters[src] ||= HTML::Pipeline.new([
23
+ HTML::Pipeline::MentionFilter
24
+ ], { :base_url => src })
25
+ end
18
26
 
19
- def mentionify(page)
20
- return unless page.content.include?('@')
21
- page.content = @filter.mention_link_filter(page.content)
22
- end
27
+ # Public: Filters hash where the key is the mention base URL.
28
+ # Effectively a cache.
29
+ def filters
30
+ @filters ||= {}
31
+ end
23
32
 
24
- def html_page?(page)
25
- page.html? || page.url.end_with?('/')
26
- end
33
+ # Public: Calculate the base URL to use for mentioning.
34
+ # The custom base URL can be defined in the config as
35
+ # jekyll-mentions.base_url or jekyll-mentions, and must
36
+ # be a valid URL (i.e. it must include a protocol and valid domain)
37
+ # It should _not_ have a trailing slash.
38
+ #
39
+ # config - the hash-like configuration of the document's site
40
+ #
41
+ # Returns a URL to use as the base URL for mentions.
42
+ # Defaults to the https://github.com.
43
+ def mention_base(config = {})
44
+ mention_config = config['jekyll-mentions']
45
+ case mention_config
46
+ when nil, NilClass
47
+ GITHUB_DOT_COM
48
+ when String
49
+ mention_config.to_s
50
+ when Hash
51
+ mention_config.fetch('base_url', GITHUB_DOT_COM)
52
+ else
53
+ raise InvalidJekyllMentionConfig,
54
+ "Your jekyll-mentions config has to either be a" \
55
+ " string or a hash. It's a #{mention_config.class} right now."
56
+ end
57
+ end
27
58
 
28
- def base_url(configs)
29
- case configs
30
- when nil, NilClass
31
- DEFAULT_URL
32
- when String
33
- configs.to_s
34
- when Hash
35
- configs.fetch('base_url', DEFAULT_URL)
36
- else
37
- raise ArgumentError.new("Your jekyll-mentions config has to either be a string or a hash! It's a #{configs.class} right now.")
59
+ # Public: Defines the conditions for a document to be emojiable.
60
+ #
61
+ # doc - the Jekyll::Document or Jekyll::Page
62
+ #
63
+ # Returns true if the doc is written & is HTML.
64
+ def mentionable?(doc)
65
+ (doc.class == Jekyll::Page || doc.write?) &&
66
+ doc.output_ext == ".html" || (doc.permalink && doc.permalink.end_with?("/"))
38
67
  end
39
68
  end
40
69
  end
41
70
  end
71
+
72
+ Jekyll::Hooks.register [:pages, :documents], :post_render do |doc|
73
+ Jekyll::Mentions.mentionify(doc) if Jekyll::Mentions.mentionable?(doc)
74
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-mentions
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-16 00:00:00.000000000 Z
11
+ date: 2016-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -67,33 +67,19 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: shoulda
70
+ name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: minitest
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
73
+ - - "~>"
88
74
  - !ruby/object:Gem::Version
89
- version: '0'
75
+ version: '3.0'
90
76
  type: :development
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
- - - ">="
80
+ - - "~>"
95
81
  - !ruby/object:Gem::Version
96
- version: '0'
82
+ version: '3.0'
97
83
  description:
98
84
  email: support@github.com
99
85
  executables: []
@@ -121,9 +107,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
107
  version: '0'
122
108
  requirements: []
123
109
  rubyforge_project:
124
- rubygems_version: 2.5.2
110
+ rubygems_version: 2.5.1
125
111
  signing_key:
126
112
  specification_version: 4
127
113
  summary: "@mention support for your Jekyll site"
128
114
  test_files: []
129
- has_rdoc: