Class: Bridgetown::PluginContentReader
- Inherits:
-
Object
- Object
- Bridgetown::PluginContentReader
- Defined in:
- lib/bridgetown-core/readers/plugin_content_reader.rb
Instance Attribute Summary collapse
-
#content_dir ⇒ Object
readonly
Returns the value of attribute content_dir.
-
#manifest ⇒ Object
readonly
Returns the value of attribute manifest.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Instance Method Summary collapse
- #add_to(content_type, klass) ⇒ Object
-
#initialize(site, manifest) ⇒ PluginContentReader
constructor
A new instance of PluginContentReader.
- #read ⇒ Object
- #read_content_file(path) ⇒ Object
Constructor Details
#initialize(site, manifest) ⇒ PluginContentReader
Returns a new instance of PluginContentReader.
9 10 11 12 13 14 |
# File 'lib/bridgetown-core/readers/plugin_content_reader.rb', line 9 def initialize(site, manifest) @site = site @manifest = manifest @content_dir = manifest.content @content_files = Set.new end |
Instance Attribute Details
#content_dir ⇒ Object (readonly)
Returns the value of attribute content_dir.
5 6 7 |
# File 'lib/bridgetown-core/readers/plugin_content_reader.rb', line 5 def content_dir @content_dir end |
#manifest ⇒ Object (readonly)
Returns the value of attribute manifest.
5 6 7 |
# File 'lib/bridgetown-core/readers/plugin_content_reader.rb', line 5 def manifest @manifest end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
5 6 7 |
# File 'lib/bridgetown-core/readers/plugin_content_reader.rb', line 5 def site @site end |
Instance Method Details
#add_to(content_type, klass) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/bridgetown-core/readers/plugin_content_reader.rb', line 42 def add_to(content_type, klass) existing_paths = content_type.filter_map(&:relative_path) @content_files.select { |item| item.is_a?(klass) }.each do |item| content_type << item unless existing_paths.include?(item.relative_path) end end |
#read ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/bridgetown-core/readers/plugin_content_reader.rb', line 16 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) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/bridgetown-core/readers/plugin_content_reader.rb', line 30 def read_content_file(path) dir = File.dirname(path.sub("#{content_dir}/", "")) name = File.basename(path) @content_files << if Utils.has_yaml_header?(path) || Utils.has_rbfm_header?(path) site.collections.pages.read_resource(path, manifest: manifest) else Bridgetown::StaticFile.new(site, content_dir, "/#{dir}", name) end add_to(site.static_files, Bridgetown::StaticFile) end |