Class: Slices::ContainerParser

Inherits:
Object
  • Object
show all
Defined in:
lib/slices/container_parser.rb

Defined Under Namespace

Classes: MissingLayoutError

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ContainerParser

Returns a new instance of ContainerParser.

Raises:



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

Parameters:

  • name (String)

    Name of container

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :primary (Boolean) — default: false

    Is this container the primary

  • :except (Class, Array)

    Disallow these slice(s) from this container

  • :only (Class, Array)

    Only allow these slice(s) from this container

Returns:

  • (String)


37
38
39
40
41
42
43
44
45
# File 'lib/slices/container_parser.rb', line 37

def container(name, options = {})
  [:except, :only].each do |type|
    if options.has_key? type
      options[type] = convert_slice_classes_to_symbols(options[type])
    end
  end

  @containers[name] = options.reverse_merge name: name.titleize
end

#parseObject



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