Module: Meem::Templates
- Defined in:
- lib/meem/templates.rb
Constant Summary collapse
- PATHS =
[ Pathname.new("#{ENV['HOME']}/.meem/"), Pathname.new("#{DIRECTORY}/../templates/") ]
Class Method Summary collapse
-
.find(template) ⇒ Object
Find a given template.
-
.list ⇒ Object
List templates.
-
.load(template) ⇒ Object
Load a template from file or the internet.
Class Method Details
.find(template) ⇒ Object
Find a given template.
template - A String describing a template.
Return a Pathname instance.
25 26 27 |
# File 'lib/meem/templates.rb', line 25 def self.find template list.find { |file| file.basename.to_s =~ /#{template}/ } end |
.list ⇒ Object
List templates.
Returns an Array of Pathname instances.
13 14 15 16 17 18 |
# File 'lib/meem/templates.rb', line 13 def self.list PATHS.map do |path| next unless File.exists?(path) path.children.select { |child| child.extname == ".jpg" } end.compact.flatten end |
.load(template) ⇒ Object
Load a template from file or the internet.
template - A String describing a template.
Returns a File.
34 35 36 37 38 39 40 |
# File 'lib/meem/templates.rb', line 34 def self.load template if template[/(^https?:\/\/)|(\/)/] return open template else find template end end |