Class: Slices::ContainerParser
- Inherits:
-
Object
- Object
- Slices::ContainerParser
- Defined in:
- lib/slices/container_parser.rb
Defined Under Namespace
Classes: MissingLayoutError
Instance Method Summary collapse
-
#container(name, options = {}) ⇒ String
Define a
containerin a layout, a container holds slices on a page. -
#initialize(path) ⇒ ContainerParser
constructor
A new instance of ContainerParser.
- #method_missing(meth, *args, &block) ⇒ Object
- #parse ⇒ Object
Constructor Details
#initialize(path) ⇒ ContainerParser
Returns a new instance of ContainerParser.
5 6 7 8 9 |
# File 'lib/slices/container_parser.rb', line 5 def initialize(path) raise MissingLayoutError if path.nil? @path = path @containers = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
47 48 49 |
# File 'lib/slices/container_parser.rb', line 47 def method_missing(meth, *args, &block) yield if block_given? end |
Instance Method Details
#container(name, options = {}) ⇒ String
Define a container in a layout, a container holds slices on a page.
This container is called Title and only allows title and You Tube slices
container "title", :only => [TitleSlice, YouTubeSlice]
Here’s a container called body which is the primary and does not allow title slices.
container "body", :primary => true, :except => TitleSlice
37 38 39 40 41 42 43 44 45 |
# File 'lib/slices/container_parser.rb', line 37 def container(name, = {}) [:except, :only].each do |type| if .has_key? type [type] = convert_slice_classes_to_symbols([type]) end end @containers[name] = .reverse_merge name: name.titleize end |
#parse ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/slices/container_parser.rb', line 11 def parse @page = Page.new erb_template = File.read(@path) @erb = ActionView::Template::Handlers::Erubis.new(erb_template) parse_with_block {} @containers end |