Class: Dynasnip
- Inherits:
-
Vanilla::Renderers::Base
- Object
- Vanilla::Renderers::Base
- Dynasnip
- Defined in:
- lib/vanilla/dynasnip.rb
Direct Known Subclasses
Comments, CurrentSnip, Debug, EditLink, EditSnip, Index, Kind, LinkTo, LinkToCurrentSnip, Login, NewSnip, Notes, RandomNumber, ShowContentInPreTag, ShowRawContent, UrlTo
Instance Attribute Summary collapse
-
#enclosing_snip ⇒ Object
Returns the value of attribute enclosing_snip.
Attributes inherited from Vanilla::Renderers::Base
Class Method Summary collapse
- .all ⇒ Object
- .attribute(attribute_name, attribute_value = nil) ⇒ Object
- .snip_attributes ⇒ Object
- .snip_name(new_name = nil) ⇒ Object
- .usage(str) ⇒ Object
Instance Method Summary collapse
Methods inherited from Vanilla::Renderers::Base
escape_curly_braces, #include_snips, #initialize, #parse_snip_reference, #prepare, #process_text, #raw_content, #render, render, #render_without_including_snips, snip_regexp, #soup
Methods included from Vanilla::Routes
#edit_link, #existing_link, #link_to, #new_link, #url_to, #url_to_raw
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
39 40 41 42 43 44 45 46 47 |
# File 'lib/vanilla/dynasnip.rb', line 39 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_snip ⇒ Object
Returns the value of attribute enclosing_snip.
37 38 39 |
# File 'lib/vanilla/dynasnip.rb', line 37 def enclosing_snip @enclosing_snip end |
Class Method Details
.all ⇒ Object
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
22 23 24 25 26 |
# File 'lib/vanilla/dynasnip.rb', line 22 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 |
.snip_attributes ⇒ Object
32 33 34 35 |
# File 'lib/vanilla/dynasnip.rb', line 32 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
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/vanilla/dynasnip.rb', line 10 def self.snip_name(new_name=nil) if new_name @snip_name = new_name.to_s else # borrowed from ActiveSupport @snip_name ||= self.name.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end end |
.usage(str) ⇒ Object
28 29 30 |
# File 'lib/vanilla/dynasnip.rb', line 28 def self.usage(str) attribute :usage, escape_curly_braces(str).strip end |