class Dato::Dump::SsgDetector
Constants
- HUGO
- NODE
- PYTHON
- RUBY
Attributes
path[R]
Public Class Methods
new(path)
click to toggle source
# File lib/dato/dump/ssg_detector.rb, line 34 def initialize(path) @path = path end
Public Instance Methods
detect()
click to toggle source
# File lib/dato/dump/ssg_detector.rb, line 38 def detect ruby_generator || node_generator || python_generator || hugo || "unknown" end
Private Instance Methods
hugo()
click to toggle source
# File lib/dato/dump/ssg_detector.rb, line 87 def hugo HUGO.any? do |option| config_path = File.join(path, option[:file]) if File.exist?(config_path) config = option[:loader].call(File.read(config_path)) config.key? "baseurl" end end && "hugo" rescue JSON::ParserError nil end
node_generator()
click to toggle source
# File lib/dato/dump/ssg_detector.rb, line 59 def node_generator package_path = File.join(path, "package.json") return unless File.exist?(package_path) package = JSON.parse(File.read(package_path)) deps = package.fetch("dependencies", {}) dev_deps = package.fetch("devDependencies", {}) all_deps = deps.merge(dev_deps) NODE.find do |generator| all_deps.key? generator end rescue JSON::ParserError nil end
python_generator()
click to toggle source
# File lib/dato/dump/ssg_detector.rb, line 76 def python_generator requirements_path = File.join(path, "requirements.txt") return unless File.exist?(requirements_path) requirements = File.read(requirements_path) PYTHON.find do |generator| requirements =~ /^#{generator}(==)?/ end end
ruby_generator()
click to toggle source
# File lib/dato/dump/ssg_detector.rb, line 48 def ruby_generator gemfile_path = File.join(path, "Gemfile") return unless File.exist?(gemfile_path) gemfile = File.read(gemfile_path) RUBY.find do |generator| gemfile =~ /('#{generator}'|"#{generator}")/ end end