lib/frontman/app.rb in frontman-ssg-0.0.3 vs lib/frontman/app.rb in frontman-ssg-0.0.4
- old
+ new
@@ -1,10 +1,11 @@
# typed: ignore
# frozen_string_literal: false
require 'frontman/sitemap_tree'
require 'frontman/data_store'
+require 'frontman/errors'
require 'singleton'
require 'sorbet-runtime'
module Frontman
class App
@@ -92,15 +93,19 @@
sig { params(key: String, value: String).returns(String) }
def add_to_manifest(key, value)
@assets_manifest[key] = '/' + value.sub(%r{^/}, '')
end
- sig { params(dirs: Array).void }
+ sig { params(dirs: T.any(Array, Hash)).void }
def register_data_dirs(dirs)
- dirs.each do |dir|
- define_singleton_method dir.to_sym do
- @data_dirs[dir] ||= DataStore.new(File.join(Dir.pwd, dir))
+ if dirs.is_a?(Array)
+ dirs = dirs.map { |dir| [dir.split('/').last, dir] }.to_h
+ end
+
+ dirs.each do |name, dir|
+ define_singleton_method name do
+ @data_dirs[name] ||= DataStore.new(File.join(Dir.pwd, dir))
end
end
end
sig do
@@ -125,10 +130,19 @@
mode: mode,
delay: delay
)
end
+ sig { params(file_path: String).void }
+ def import_config(file_path)
+ if !file_path.end_with?('.rb') && !File.exist?(file_path)
+ return import_config("#{file_path}.rb")
+ end
+
+ run File.read(file_path)
+ end
+
def method_missing(method_id, *_)
from_view_data = get_from_view_data(method_id)
return from_view_data unless from_view_data.nil?
from_current_page = get_from_current_page(method_id)
@@ -161,15 +175,8 @@
return @view_data.last[key] unless @view_data.last[key].nil?
local_data = @view_data.last[:locals]
local_data[key] unless local_data.nil?
- end
-
- class ExistingResourceError < StandardError
- def self.create(url, resource)
- new("Unable to redirect for #{url},
- the resource #{resource.file_path} already exists on this URL")
- end
end
end
end