class Slices::ContainerParser
Public Class Methods
new(path)
click to toggle source
# File lib/slices/container_parser.rb, line 5 def initialize(path) raise MissingLayoutError if path.nil? @path = path @containers = {} end
Public Instance Methods
container(name, options = {})
click to toggle source
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
@param [String] name Name of container @param [Hash] options @option options [Boolean] :primary (false) Is this container the primary @option options [Class,Array] :except Disallow these slice(s) from this container @option options [Class,Array] :only Only allow these slice(s) from this container @return [String]
# 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
method_missing(meth, *args) { || ... }
click to toggle source
# File lib/slices/container_parser.rb, line 47 def method_missing(meth, *args, &block) yield if block_given? end
parse()
click to toggle source
# 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
Private Instance Methods
convert_slice_class_to_symbol(klass)
click to toggle source
# File lib/slices/container_parser.rb, line 65 def convert_slice_class_to_symbol(klass) klass.name.underscore.split('_')[0 .. -2].join('_').to_sym end
convert_slice_classes_to_symbols(options = [])
click to toggle source
# File lib/slices/container_parser.rb, line 57 def convert_slice_classes_to_symbols(options = []) [options].flatten.select do |klass| klass.is_a?(Class) end.map do |klass| convert_slice_class_to_symbol(klass) end end
parse_with_block(&block)
click to toggle source
# File lib/slices/container_parser.rb, line 53 def parse_with_block(&block) @erb.result(binding) end