Module: Pasta::Ingredients::ClassMethods
- Defined in:
- lib/pasta/ingredients.rb
Constant Summary collapse
- @@grammars =
{}
Instance Method Summary collapse
Instance Method Details
#grammar(name, &rules) ⇒ Object
Public. The DSL for declaring grammar rules in a recipe.
Recipes contain grammars that are defined in ordered arrays. Grammars are recursively matched in a top down
fashion where the array elements match ingredients. Grammar matching is done on a first match basis so that
the last rule can be a catch-all one.
name - a Symbol naming the grammar rules - a block defining the grammar
Example
grammar(:html) { [:blockquotes, :paragraphs] }
grammar(:blockquote) { [:blockquote, :paragraphs] }
grammar(:paragraph) { [:links, :emphasis, :bold, :text] }
Returns nothing
43 44 45 46 |
# File 'lib/pasta/ingredients.rb', line 43 def grammar(name, &rules) rules.call.each { |rule| require "pasta/ingredients/#{rule.to_s}" } @@grammars[name] = rules.call end |
#grammars ⇒ Object
24 25 26 |
# File 'lib/pasta/ingredients.rb', line 24 def grammars @@grammars end |