Class: Slippery::Processors::RevealJs::AddRevealJs

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

Constant Summary collapse

DEFAULT_OPTIONS =
{theme: 'default'}.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, options = {}) ⇒ AddRevealJs

Returns a new instance of AddRevealJs.



15
16
17
18
# File 'lib/slippery/processors/reveal_js/add_reveal_js.rb', line 15

def initialize(path_composer, options = {})
  @path_composer = path_composer
  @options = DEFAULT_OPTIONS.merge(options).freeze
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



11
12
13
# File 'lib/slippery/processors/reveal_js/add_reveal_js.rb', line 11

def attributes
  @attributes
end

Class Method Details

.call(doc) ⇒ Object



7
8
9
# File 'lib/slippery/processors/reveal_js/add_reveal_js.rb', line 7

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

Instance Method Details

#call(doc) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/slippery/processors/reveal_js/add_reveal_js.rb', line 20

def call(doc)
  doc.process(
    reveal_wrap,
    add_reveal_js,
    add_reveal_css,
    add_theme,
    add_settings
  )
end

#plugin_config(plugin) ⇒ Object



73
74
75
# File 'lib/slippery/processors/reveal_js/add_reveal_js.rb', line 73

def plugin_config(plugin)
  "{ src: #{plugins(plugin).inspect}, async: true, condition: function() { return !!document.body.classList; } }"
end

#plugin_settingsObject



60
61
62
63
64
65
# File 'lib/slippery/processors/reveal_js/add_reveal_js.rb', line 60

def plugin_settings
  'dependencies: [' +
  Array(@options.fetch(:plugins, [])).map do |name|
    plugin_config name
  end.join(',') + ']'
end

#plugins(name) ⇒ Object



67
68
69
70
71
# File 'lib/slippery/processors/reveal_js/add_reveal_js.rb', line 67

def plugins(name)
  {
    notes: 'plugin/notes/notes.js'
  }[name]
end

#settingsObject



56
57
58
# File 'lib/slippery/processors/reveal_js/add_reveal_js.rb', line 56

def settings
  @options.reject { |key, _| [:theme, :plugins].include? key }
end