Module: Staticpress::Content::ResourceContent

Included in:
Category, Index, Page, Page, Post, Tag, Theme, Theme
Defined in:
lib/staticpress/content/resource_content.rb

Instance Method Summary collapse

Instance Method Details

#find_supported_extensions(path) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/staticpress/content/resource_content.rb', line 5

def find_supported_extensions(path)
  file = path.file? ? path : Dir["#{path}.*"].first
  return [] if file.nil?

  # TODO stop looping when no more supported extensions
  Pathname(file).sub("#{file.to_s}.", '').to_s.split('.').map(&:to_sym).select do |extension|
    Staticpress::Content::StaticContent.supported_extensions.include? extension
  end.reverse
end

#gather_resources_from(paths) ⇒ Object



15
16
17
18
19
# File 'lib/staticpress/content/resource_content.rb', line 15

def gather_resources_from(paths)
  spider_map paths do |resource|
    find_by_path resource
  end.flatten.compact
end

#load_resource(base, stub, params) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/staticpress/content/resource_content.rb', line 21

def load_resource(base, stub, params)
  catch :resource do
    Staticpress::Content::StaticContent.supported_extensions.each do |extension|
      path = base + "#{stub}.#{extension}"
      throw :resource, new(params) if path.file?
    end

    nil
  end
end