class Bunto::ThemeAssetsReader

Attributes

site[R]

Public Class Methods

new(site) click to toggle source
# File lib/bunto/readers/theme_assets_reader.rb, line 4
def initialize(site)
  @site = site
end

Public Instance Methods

read() click to toggle source
# File lib/bunto/readers/theme_assets_reader.rb, line 8
def read
  return unless site.theme && site.theme.assets_path

  Find.find(site.theme.assets_path) do |path|
    next if File.directory?(path)
    if File.symlink?(path)
      Bunto.logger.warn "Theme reader:", "Ignored symlinked asset: #{path}"
    else
      read_theme_asset(path)
    end
  end
end

Private Instance Methods

append_unless_exists(haystack, new_item) click to toggle source
# File lib/bunto/readers/theme_assets_reader.rb, line 36
def append_unless_exists(haystack, new_item)
  if haystack.any? { |file| file.relative_path == new_item.relative_path }
    Bunto.logger.debug "Theme:",
      "Ignoring #{new_item.relative_path} in theme due to existing file " \
      "with that path in site."
    return
  end

  haystack << new_item
end
read_theme_asset(path) click to toggle source
# File lib/bunto/readers/theme_assets_reader.rb, line 22
def read_theme_asset(path)
  base = site.theme.root
  dir = File.dirname(path.sub("#{site.theme.root}/", ""))
  name = File.basename(path)

  if Utils.has_yaml_header?(path)
    append_unless_exists site.pages,
      Bunto::Page.new(site, base, dir, name)
  else
    append_unless_exists site.static_files,
      Bunto::StaticFile.new(site, base, dir, name)
  end
end