Class: Slippery::Processors::ImpressJs::AddImpressJs

Inherits:
Object
  • Object
show all
Includes:
Slippery::ProcessorHelpers
Defined in:
lib/slippery/processors/impress_js/add_impress_js.rb

Constant Summary collapse

DEFAULT_ATTRS =
{
  'transition-duration' => 1000
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Slippery::ProcessorHelpers

#data_attributes, #include_local_css, #include_local_javascript, included, #javascript_include_tag, #stylesheet_link_tag

Constructor Details

#initialize(path_composer, attributes = {}) ⇒ AddImpressJs

Returns a new instance of AddImpressJs.



17
18
19
20
# File 'lib/slippery/processors/impress_js/add_impress_js.rb', line 17

def initialize(path_composer, attributes = {})
  @path_composer = path_composer
  @attributes = DEFAULT_ATTRS.merge(attributes).freeze
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



11
12
13
# File 'lib/slippery/processors/impress_js/add_impress_js.rb', line 11

def attributes
  @attributes
end

Class Method Details

.call(doc) ⇒ Object



7
8
9
# File 'lib/slippery/processors/impress_js/add_impress_js.rb', line 7

def self.call(doc)
  self.new.call(doc)
end

Instance Method Details

#call(doc) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/slippery/processors/impress_js/add_impress_js.rb', line 22

def call(doc)
  doc.replace('body') do |body|
    include_local_javascript(body, @path_composer.call('impress.js/js/impress.js'))
      .set_attrs({id: 'impress'}.merge(data_attributes(attributes)))
      .add H[:script, 'impress().init();']
  end
end