Class: Jekyll::IssueMentions

Inherits:
Generator
  • Object
show all
Defined in:
lib/jekyll-issue-mentions.rb

Instance Method Summary collapse

Constructor Details

#initialize(config = Hash.new) ⇒ IssueMentions

Returns a new instance of IssueMentions.



9
10
11
# File 'lib/jekyll-issue-mentions.rb', line 9

def initialize(config = Hash.new)
  @filter = HTML::Pipeline::IssueMentionFilter.new(nil, {:base_url => base_url(config['jekyll-issue-mentions']) })
end

Instance Method Details

#base_url(configs) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/jekyll-issue-mentions.rb', line 28

def base_url(configs)
  case configs
  when nil, NilClass
    raise ArgumentError.new("Your jekyll-issue-mentions config has to configured.")
  when String
    configs.to_s
  when Hash
    base_url = configs['base_url']
    if base_url.nil?
      raise ArgumentError.new("Your jekyll-issue-mentions is missing base_url configuration.")
    else
      base_url
    end
  else
    raise ArgumentError.new("Your jekyll-issue-mentions config has to either be a string or a hash! It's a #{configs.class} right now.")
  end
end

#generate(site) ⇒ Object



13
14
15
16
17
# File 'lib/jekyll-issue-mentions.rb', line 13

def generate(site)
  site.pages.each { |page| mentionify page if html_page?(page) }
  site.posts.each { |post| mentionify post }
  site.docs_to_write.each { |doc| mentionify doc }
end

#html_page?(page) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/jekyll-issue-mentions.rb', line 24

def html_page?(page)
  page.html? || page.url.end_with?('/')
end

#mentionify(page) ⇒ Object



19
20
21
22
# File 'lib/jekyll-issue-mentions.rb', line 19

def mentionify(page)
  return unless page.content.include?('#')
  page.content = @filter.mention_link_filter(page.content, @filter.base_url, @filter.issueid_pattern)
end