djanowski-snippets 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/snippet.rb +31 -2
- metadata +1 -1
data/lib/snippet.rb
CHANGED
@@ -7,7 +7,6 @@ class Snippet < ActiveRecord::Base
|
|
7
7
|
class << self
|
8
8
|
def get(slug, options = {})
|
9
9
|
snippet = find_by_slug(slug.to_s.downcase) || create!(options.merge(:slug => slug))
|
10
|
-
snippet.compiled_text.to_s if snippet
|
11
10
|
end
|
12
11
|
|
13
12
|
def parse(text, parser = nil)
|
@@ -22,7 +21,37 @@ class Snippet < ActiveRecord::Base
|
|
22
21
|
end
|
23
22
|
|
24
23
|
def to_s
|
25
|
-
|
24
|
+
compiled_text.to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
def %(*args)
|
28
|
+
if args.size == 1 && args.first.kind_of?(Hash)
|
29
|
+
text = to_s
|
30
|
+
|
31
|
+
args.first.each do |key,value|
|
32
|
+
text = text.gsub("{{#{key}}}", value)
|
33
|
+
end
|
34
|
+
|
35
|
+
text
|
36
|
+
else
|
37
|
+
sprintf(to_s, *args)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def empty?
|
42
|
+
to_s.empty?
|
43
|
+
end
|
44
|
+
|
45
|
+
def blank?
|
46
|
+
to_s.blank?
|
47
|
+
end
|
48
|
+
|
49
|
+
def inspect
|
50
|
+
to_s.inspect
|
51
|
+
end
|
52
|
+
|
53
|
+
def ==(other)
|
54
|
+
to_s.eql?(other)
|
26
55
|
end
|
27
56
|
|
28
57
|
private
|