Module: Ciridiri::Finders

Included in:
Page
Defined in:
lib/ciridiri/finders.rb

Instance Method Summary collapse

Instance Method Details

#allObject

Return an array of all ‘Page`s excluding backups



16
17
18
19
20
21
# File 'lib/ciridiri/finders.rb', line 16

def all
  Dir.chdir(content_dir) do
    files = Dir.glob(File.join("**", "*#{SOURCE_FILE_EXT}")).delete_if {|p| p =~ Regexp.new("\\.[0-9]+\\#{SOURCE_FILE_EXT}$")}
    files.collect {|f| Page.new(uri_from_path(f), File.open(f, 'r') {|b| b.read})}
  end
end

#find_by_uri(uri) ⇒ Object

Convert ‘uri` to a path and return a new `Page` instance if the corresponding file exists. Return nil otherwise



5
6
7
8
# File 'lib/ciridiri/finders.rb', line 5

def find_by_uri(uri)
  content_path = path_from_uri(uri)
  File.exists?(content_path) ? Page.new(uri, File.open(content_path).read) : nil
end

#find_by_uri_or_empty(uri) ⇒ Object

Return a new empty ‘Page` instance if the corresponding file doesn’t exists



11
12
13
# File 'lib/ciridiri/finders.rb', line 11

def find_by_uri_or_empty(uri)
  find_by_uri(uri) or Page.new(uri, '')
end