class Clerq::Repositories::TextRepository

Public Class Methods

new(path: Dir.pwd, pattern: ['*.md.erb', '*.md.tt']) click to toggle source
# File lib/clerq/repositories/text_repository.rb, line 9
def initialize(path: Dir.pwd, pattern: ['*.md.erb', '*.md.tt'])
  super(path: path, pattern: pattern)
end

Public Instance Methods

find(name) click to toggle source

def find(filename)

inside do
  return filename if File.exist?(filename)
  @patt.each do |p|
    fn = "#{filename}#{p[1..-1]}"
    return fn if File.exist?(fn)
  end
end
''

end

# File lib/clerq/repositories/text_repository.rb, line 34
def find(name)
  inside {
    return name if File.exist?(name) and !File.directory?(name)}
  all = glob
  pos = @patt.map{|p| "#{name}#{p[1..-1]}"}.unshift(name)
  all.find(lambda {''}){|n|
    pos.include?(n) || n.start_with?(*pos) || n.end_with?(*pos)
  }
end
text(name) click to toggle source

Return template body @param name [String]

# File lib/clerq/repositories/text_repository.rb, line 14
def text(name)
  filename = find(name)
  if filename.empty?
    err = "File '#{name}' not found"
    raise StandardError, err
  end
  read(filename)
end