Class: Pasta::Recipes::Base
- Inherits:
-
Object
- Object
- Pasta::Recipes::Base
- Includes:
- Ingredients
- Defined in:
- lib/pasta/recipes/base.rb
Direct Known Subclasses
Constant Summary
Constants included from Ingredients
Ingredients::ANYTHING, Ingredients::ATX_HEADING, Ingredients::AUTOMATIC_LINKS, Ingredients::BLOCKQUOTE, Ingredients::CODE, Ingredients::CODEBLOCK, Ingredients::EMPHASIS, Ingredients::EMPTY_LINE, Ingredients::HTML_ENTITIES, Ingredients::LINKS, Ingredients::LINK_DEFINITION, Ingredients::LIST, Ingredients::PAGE_BREAK, Ingredients::PARAGRAPH, Ingredients::SETEXT_HEADING
Instance Method Summary collapse
Methods included from Ingredients
#anything, #atx_headings, #automatic_links, #blockquotes, #clean_link_definitions, #code, #codeblocks, #emphasis, #empty_lines, #find_link_definitions, #grammars, #html_entities, included, #links, #list_items, #lists, #page_breaks, #paragraphs, #parse_link, #setext_headings
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Public. Generic to_x parser that converts a string to the specified output format.
Uses a depth first strategy to parse a text according to incredient rules as defined in a grammar
Raises a Pasta::Error if a grammar has not been defined
text - a String to be parsed
Example
to_html('some yummy text')
# => '<p>some yummy text</p>'
Returns a String
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/pasta/recipes/base.rb', line 20 def method_missing(method, *args, &block) if method.to_s =~ /^to_(.+)$/ # ensure a grammar has been defined raise Pasta::Error.new "A grammar for #{$1} has not been defined in recipe #{self.class.name}" if grammars($1.to_sym).nil? # Depth first parsing - each ingredient should accept and return an input and output input, output = args[0], '' while input != "" do grammars($1.to_sym).each do |rule| input, output = send(rule, input, output) end end output.strip # remove any trailing whitespace else super end end |