Class: MagicReveal::ProjectConfig
- Inherits:
-
Object
- Object
- MagicReveal::ProjectConfig
- Defined in:
- lib/magic_reveal/project_config.rb
Constant Summary collapse
- DEFAULT_TEMPLATE =
File.('../template-config.json', __FILE__)
Instance Attribute Summary collapse
-
#json ⇒ Object
readonly
Returns the value of attribute json.
Instance Method Summary collapse
- #dependencies ⇒ Object
-
#initialize(io_or_path) ⇒ ProjectConfig
constructor
A new instance of ProjectConfig.
- #to_js ⇒ Object
Constructor Details
#initialize(io_or_path) ⇒ ProjectConfig
Returns a new instance of ProjectConfig.
9 10 11 12 |
# File 'lib/magic_reveal/project_config.rb', line 9 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 |
Instance Attribute Details
#json ⇒ Object (readonly)
Returns the value of attribute json.
7 8 9 |
# File 'lib/magic_reveal/project_config.rb', line 7 def json @json end |
Instance Method Details
#dependencies ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/magic_reveal/project_config.rb', line 14 def dependencies out = [] # you always want this out << '{ src: "lib/js/classList.js", condition: function() { return !document.body.classList; } }' if json['plugins'].include? 'highlight' out << '{ src: "plugin/highlight/highlight.js", async: true, callback: function() { hljs.initHighlightingOnLoad(); } }' end if json['plugins'].include? 'zoom' out << '{ src: "plugin/zoom-js/zoom.js", async: true, condition: function() { return !!document.body.classList; } }' end if json['plugins'].include? 'notes' out << '{ src: "plugin/notes/notes.js", async: true, condition: function() { return !!document.body.classList; } }' end "\"dependencies\": [\n#{out.join(",\n")}\n]" end |
#to_js ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/magic_reveal/project_config.rb', line 32 def to_js var = [] keys = json.keys.reject { |k| ['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 |