Class: Snippet
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Snippet
- Defined in:
- lib/snippet.rb
Class Method Summary collapse
Instance Method Summary collapse
- #%(*args) ⇒ Object
- #==(other) ⇒ Object
- #blank? ⇒ Boolean
- #empty? ⇒ Boolean
- #inspect ⇒ Object
- #to_s ⇒ Object
Class Method Details
.default_parser ⇒ Object
18 19 20 |
# File 'lib/snippet.rb', line 18 def default_parser 'html' end |
.get(slug, options = {}) ⇒ Object
8 9 10 |
# File 'lib/snippet.rb', line 8 def get(slug, = {}) snippet = find_by_slug(slug.to_s.downcase) || create!(.merge(:slug => slug)) end |
.parse(text, parser = nil) ⇒ Object
12 13 14 15 16 |
# File 'lib/snippet.rb', line 12 def parse(text, parser = nil) parser = Snippet.default_parser if parser.blank? klass = Simplesnippets::Parsers.const_get(parser.to_s.classify) klass.parse(text) end |
Instance Method Details
#%(*args) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/snippet.rb', line 27 def %(*args) if args.size == 1 && args.first.kind_of?(Hash) text = to_s args.first.each do |key,value| text = text.gsub("{{#{key}}}", value) end text else sprintf(to_s, *args) end end |
#==(other) ⇒ Object
53 54 55 |
# File 'lib/snippet.rb', line 53 def ==(other) to_s.eql?(other) end |
#blank? ⇒ Boolean
45 46 47 |
# File 'lib/snippet.rb', line 45 def blank? to_s.blank? end |
#empty? ⇒ Boolean
41 42 43 |
# File 'lib/snippet.rb', line 41 def empty? to_s.empty? end |
#inspect ⇒ Object
49 50 51 |
# File 'lib/snippet.rb', line 49 def inspect to_s.inspect end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/snippet.rb', line 23 def to_s compiled_text.to_s end |