djanowski-snippets 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/snippet.rb +31 -2
  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
- slug
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: djanowski-snippets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damian Janowski