Module: Slippery::ProcessorHelpers

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.asset_uri(path) ⇒ Object



7
8
9
# File 'lib/slippery/processor_helpers.rb', line 7

def asset_uri(path)
  "file://" + Slippery::ROOT.join('assets', path).to_s
end

.included(klz) ⇒ Object



3
4
5
# File 'lib/slippery/processor_helpers.rb', line 3

def self.included(klz)
  klz.extend ClassMethods
end

Instance Method Details

#call(doc) ⇒ Object



36
37
38
# File 'lib/slippery/processor_helpers.rb', line 36

def call(doc)
  doc.process(*self.class.processors.map {|name| send(name) })
end

#data_attributes(attrs) ⇒ Object



28
29
30
# File 'lib/slippery/processor_helpers.rb', line 28

def data_attributes(attrs)
  Hash[*attrs.flat_map { |k, v| ["data-#{k}", v] }]
end

#hash_to_js(hsh) ⇒ Object



32
33
34
# File 'lib/slippery/processor_helpers.rb', line 32

def hash_to_js(hsh)
  hsh.map { |k, v| "#{k}:#{v.inspect}" }.join(',') #:(
end

#include_local_css(element, path) ⇒ Object



16
17
18
# File 'lib/slippery/processor_helpers.rb', line 16

def include_local_css(element, path)
  element.add stylesheet_link_tag(asset_uri(path))
end

#include_local_javascript(element, path) ⇒ Object



12
13
14
# File 'lib/slippery/processor_helpers.rb', line 12

def include_local_javascript(element, path)
  element.add javascript_include_tag(asset_uri(path))
end

#javascript_include_tag(path) ⇒ Object



20
21
22
# File 'lib/slippery/processor_helpers.rb', line 20

def javascript_include_tag(path)
  H[:script, {src: path, type: 'text/javascript'}]
end


24
25
26
# File 'lib/slippery/processor_helpers.rb', line 24

def stylesheet_link_tag(path)
  H[:link, {href: path, rel: 'stylesheet'}]
end