class MagicReveal::ProjectConfig

A Project's configuration

Constants

DEFAULT_TEMPLATE
DEPENDENCY_ENABLER_JS

Attributes

json[R]

Public Class Methods

new(io_or_path) click to toggle source
# File lib/magic_reveal/project_config.rb, line 16
def initialize(io_or_path)
  io = io_or_path.respond_to?(:read) ? io_or_path : Pathname.new(io_or_path)
  @json = JSON.load(io.read)
end

Public Instance Methods

dependencies() click to toggle source
# File lib/magic_reveal/project_config.rb, line 21
def dependencies
  out = []
  # you always want this
  out << '{ src: "lib/js/classList.js", condition: function() { return !document.body.classList; } }'

  DEPENDENCY_ENABLER_JS.keys.each do |plugin|
    out << DEPENDENCY_ENABLER_JS[plugin] if json['plugins'].include?(plugin)
  end

  "\"dependencies\": [\n#{out.join(",\n")}\n]"
end
to_js() click to toggle source
# File lib/magic_reveal/project_config.rb, line 33
def to_js # rubocop:disable MethodLength
  var = []
  keys = json.keys.reject { |k| %w{ 'dependencies', 'github' }.include?(k) }
  keys.each do |key|
    value = json[key]
    var << "  #{key}: #{value.to_json}"
  end

  out = []
  out << "/* Generated at #{Time.now} */"
  out << 'var config = {'
  out << "#{var.join(",\n")},\n#{dependencies}"
  out << "\n};"
  out << 'Reveal.initialize(config);'
  out.join("\n")
end