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)



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

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

Instance Method Details

#applies_to?(keys) ⇒ Boolean

Returns:

  • (Boolean)


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

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)


132
133
134
# File 'lib/pagehub-markdown/processors/embedder.rb', line 132

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.



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

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