Class: MarkdownServer::Plugins::BibleCitations

Inherits:
Object
  • Object
show all
Includes:
MarkdownServer::Plugin
Defined in:
lib/markdown_server/plugins/bible_citations/plugin.rb,
lib/markdown_server/plugins/bible_citations/helpers.rb

Defined Under Namespace

Modules: Helpers

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MarkdownServer::Plugin

#browser_render, included

Class Method Details

.enabled_by_default?Boolean

Returns:

  • (Boolean)


13
# File 'lib/markdown_server/plugins/bible_citations/plugin.rb', line 13

def self.enabled_by_default? = false

Instance Method Details

#post_render(html, meta, app) ⇒ Object



52
53
54
# File 'lib/markdown_server/plugins/bible_citations/plugin.rb', line 52

def post_render(html, meta, app)
  app.inject_pronunciation_icon(html, meta)
end

#process_fetch(url, html, app) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/markdown_server/plugins/bible_citations/plugin.rb', line 37

def process_fetch(url, html, app)
  if url.match?(/blueletterbible\.org\/lexicon\//i)
    raw = app.page_title(html)
    title = raw.match(/^([GH]\d+ - \w+)/i)&.[](1)&.sub(" - ", "") ||
            raw.sub(/ [-–] .*/, "").strip
    { title: title, html: app.blueletterbible_html(html, url) }
  elsif url.match?(%r{/definitions/[^/]+\.md(\?|#|\z)}i)
    title = app.page_title(html).sub(/ [-–] .*/, "").strip
    { title: title, html: app.markdownr_html(html) }
  elsif url.match?(/scrip\.risensavior\.com/i) || html.match?(/<div\s+class="passage-text/i)
    title = app.page_title(html).sub(/ [-–] .*/, "").strip
    { title: title, html: app.scrip_html(html, url) }
  end
end

#setup(config) ⇒ Object



15
16
17
18
19
20
# File 'lib/markdown_server/plugins/bible_citations/plugin.rb', line 15

def setup(config)
  @version = config.fetch("version", Citations::DEFAULT_VERSION)
  @link_target = config.fetch("link_target", "scrip")
  MarkdownServer::App.set :dictionary_url, config["dictionary_url"] if config["dictionary_url"]
  MarkdownServer::App.helpers(Helpers)
end

#transform_html(html, app = nil) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/markdown_server/plugins/bible_citations/plugin.rb', line 28

def transform_html(html, app = nil)
  html = Citations.link_citations_html(html) do |canonical, verse, citation|
    url = citation_url(canonical, verse)
    %(<a href="#{CGI.escapeHTML(url)}">#{CGI.escapeHTML(citation)}</a>)
  end
  html = app.inject_strongs_urls(html) if app.respond_to?(:inject_strongs_urls)
  html
end

#transform_markdown(text) ⇒ Object



22
23
24
25
26
# File 'lib/markdown_server/plugins/bible_citations/plugin.rb', line 22

def transform_markdown(text)
  Citations.link_citations(text) do |canonical, verse, citation|
    "[#{citation}](#{citation_url(canonical, verse)})"
  end
end