Class: PageHub::Markdown::Embedder::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/pagehub-markdown/processors/embedder.rb

Overview

class << self

Direct Known Subclasses

GithubWikiProcessor, PageHubProcessor

Instance Method Summary collapse

Constructor Details

#initialize(keys) ⇒ Processor

Processors apply to “keys” which can be written manually in Markdown by the user, or are found in the host portion of the resource URI

IE, a Github Wiki processor would bind to the keys: “github-wiki”, or/and /github.com.*\/wiki\//

Manual keys are injected after the !include keyword: [!include github-wiki!](github.com/some-dude/wiki/Home)



125
126
127
128
# File 'lib/pagehub-markdown/processors/embedder.rb', line 125

def initialize(keys)
  @keys = keys
  super()
end

Instance Method Details

#applies_to?(keys) ⇒ Boolean

Returns:

  • (Boolean)


134
135
136
137
# File 'lib/pagehub-markdown/processors/embedder.rb', line 134

def applies_to?(keys)
  @keys.each { |h| keys.each { |k| return true if h.match k } }
  false
end

#process(content, uri, args = "") ⇒ Object

Raises:

  • (NotImplementedError)


130
131
132
# File 'lib/pagehub-markdown/processors/embedder.rb', line 130

def process(content, uri, args = "")
  raise NotImplementedError
end

#stamp(node, uri, key) ⇒ Object

Node should be the root node that contains the embedded content, which will be stripped of all attributes and injected with new ones:

  1. data-embed-uri containing the URI of the embedded resource

  2. data-embed-src the name of the processor used for embedding

All children nodes that have an @id attribute will have that attribute removed as well.



146
147
148
149
150
151
# File 'lib/pagehub-markdown/processors/embedder.rb', line 146

def stamp(node, uri, key)
  node.xpath("//*[@id]").each { |node| node.remove_attribute "id" }
  node.attributes.each_pair { |name,_| node.remove_attribute name }
  node['data-embed-uri'] = uri
  node['data-embed-src'] = key
end