class Phlexite::Content::Collection
Public Class Methods
Source
# File lib/phlexite/content/collection.rb, line 11 def initialize(glob, template, prefix: "", out: "") @files = Dir[glob] @prefix = prefix @out = out @template = template end
Public Instance Methods
Source
# File lib/phlexite/content/collection.rb, line 22 def build(site, prefix: @prefix, out: @out) entries.each do |f| next unless f.filename.start_with? prefix out_path = out.is_a?(Proc) ? out[f.filename, prefix] : get_out_path(f.filename, prefix: prefix, out: out) site.page(out_path, renderer(f).new) end end
Source
# File lib/phlexite/content/collection.rb, line 18 def entries(prefix: @prefix, out: @out) @files.map { |f| Entry.new(f, get_out_path(f, prefix: prefix, out: out)) } end
Private Instance Methods
Source
# File lib/phlexite/content/collection.rb, line 34 def get_out_path(file, prefix: @prefix, out: @out) = "#{File.join(out, File.dirname(file).delete_prefix(prefix), File.basename(file, ".*"))}.html" def renderer(entry) = Class.new(@template) do define_method(:initialize) do |*args| @filename = entry.filename parts = entry.read @front_matter = parts.front_matter @content = parts.content super(*args) end end end end
Source
# File lib/phlexite/content/collection.rb, line 36 def renderer(entry) = Class.new(@template) do define_method(:initialize) do |*args| @filename = entry.filename parts = entry.read @front_matter = parts.front_matter @content = parts.content super(*args) end end end
Calls superclass method