Module: ContentDirectory

Defined in:
lib/content_directory.rb,
lib/content_directory/entry.rb,
lib/content_directory/version.rb

Defined Under Namespace

Classes: Entry

Constant Summary collapse

VERSION =
"0.1.2"

Class Method Summary collapse

Class Method Details

.find(path = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/content_directory.rb', line 19

def self.find(path=nil)
  result = {}
  valid_entry_extensions = %w(.md .markdown .txt .text)
  valid_entry_extensions_regex = /.*(#{valid_entry_extensions.join('|\\').prepend('\\')})$/i

  begin
    entries = Dir.entries "#{root}/#{path}"
  rescue Exception => e
    return nil
  end

  entries.reject! do |entry|
    entry[0] == "." || entry.include?(".") && !entry.match(valid_entry_extensions_regex)
  end

  entries.each do |entry|
    if entry.include? "."
      result[entry.split(".")[0]] = Entry.new "#{path}/#{entry}"
    else
      result[entry] = find("#{path}/#{entry}")
    end
  end

  return result
end

.rootObject



9
10
11
12
13
14
15
16
17
# File 'lib/content_directory.rb', line 9

def self.root
  if @root
    @root
  elsif defined? Rails
    "#{Rails.root}/content"
  else
    "content"
  end
end

.root=(path) ⇒ Object



5
6
7
# File 'lib/content_directory.rb', line 5

def self.root=(path)
  @root = path
end