class Bridgetown::PluginContentReader
Attributes
content_dir[R]
site[R]
Public Class Methods
new(site, plugin_content_dir)
click to toggle source
# File lib/bridgetown-core/readers/plugin_content_reader.rb, line 7 def initialize(site, plugin_content_dir) @site = site @content_dir = plugin_content_dir @content_files = Set.new end
Public Instance Methods
add_to(content_type, klass)
click to toggle source
# File lib/bridgetown-core/readers/plugin_content_reader.rb, line 41 def add_to(content_type, klass) existing_paths = content_type.map(&:relative_path).compact @content_files.select { |item| item.is_a?(klass) }.each do |item| content_type << item unless existing_paths.include?(item.relative_path) end end
read()
click to toggle source
# File lib/bridgetown-core/readers/plugin_content_reader.rb, line 13 def read return unless content_dir Find.find(content_dir) do |path| next if File.directory?(path) if File.symlink?(path) Bridgetown.logger.warn "Plugin content reader:", "Ignored symlinked asset: #{path}" else read_content_file(path) end end end
read_content_file(path)
click to toggle source
# File lib/bridgetown-core/readers/plugin_content_reader.rb, line 27 def read_content_file(path) dir = File.dirname(path.sub("#{content_dir}/", "")) name = File.basename(path) @content_files << if Utils.has_yaml_header?(path) Bridgetown::Page.new(site, content_dir, dir, name, from_plugin: true) else Bridgetown::StaticFile.new(site, content_dir, "/#{dir}", name) end add_to(site.pages, Bridgetown::Page) add_to(site.static_files, Bridgetown::StaticFile) end