Class: Dynasnip

Inherits:
Vanilla::Renderers::Base show all
Defined in:
lib/vanilla/dynasnip.rb

Instance Attribute Summary collapse

Attributes inherited from Vanilla::Renderers::Base

#app

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Vanilla::Renderers::Base

#default_layout_snip, escape_curly_braces, #include_snips, #initialize, #layout_for, #link_to, #parse_snip_reference, #prepare, #process_text, #raw_content, render, #render, #render_missing_snip, #render_without_including_snips, snip_regexp, #soup, #url_to

Constructor Details

This class inherits a constructor from Vanilla::Renderers::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/vanilla/dynasnip.rb', line 52

def method_missing(method, *args)
  if snip
    snip.__send__(method)
  elsif part = self.class.attribute(method)
    part
  else
    super
  end
end

Instance Attribute Details

#enclosing_snipObject

Returns the value of attribute enclosing_snip.



50
51
52
# File 'lib/vanilla/dynasnip.rb', line 50

def enclosing_snip
  @enclosing_snip
end

Class Method Details

.allObject



6
7
8
# File 'lib/vanilla/dynasnip.rb', line 6

def self.all
  ObjectSpace.enum_for(:each_object, class << self; self; end).to_a - [self]
end

.attribute(attribute_name, attribute_value = nil) ⇒ Object



10
11
12
13
14
# File 'lib/vanilla/dynasnip.rb', line 10

def self.attribute(attribute_name, attribute_value=nil)
  @attributes ||= {}
  @attributes[attribute_name.to_sym] = attribute_value if attribute_value
  @attributes[attribute_name.to_sym]
end

.default_snip_nameObject



16
17
18
19
20
21
22
23
24
# File 'lib/vanilla/dynasnip.rb', line 16

def self.default_snip_name
  # borrowed from ActiveSupport
  formatted_name = self.name.
    split("::").last.
    gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
    gsub(/([a-z\d])([A-Z])/,'\1_\2').
    tr("-", "_").
    downcase
end

.snip_attributesObject



45
46
47
48
# File 'lib/vanilla/dynasnip.rb', line 45

def self.snip_attributes
  full_snip_attributes = {:name => snip_name, :content => self.name, :render_as => "Ruby"}
  @attributes ? full_snip_attributes.merge!(@attributes) : full_snip_attributes
end

.snip_name(new_name = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/vanilla/dynasnip.rb', line 26

def self.snip_name(new_name=nil)
  if new_name.nil?
    if name = attribute(:snip_name)
      name
    else
      name = default_snip_name
      attribute :snip_name, name
      name
    end
  else
    attribute :snip_name, new_name
    new_name
  end
end

.usage(str = nil) ⇒ Object



41
42
43
# File 'lib/vanilla/dynasnip.rb', line 41

def self.usage(str=nil)
  attribute :usage, str
end