Sha256: d312842c2d077744133a1f5b9973a49c5cd59254122e357452fa1a0e2bad4263

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

require 'seory'
require 'seory/page_contents'
require 'seory/repository'

module Seory
  module Dsl

    def describe(&block)
      @repository = Repository.new
      Descriptor.new(@repository).describe(&block)
    end

    def lookup(controller)
      @repository.lookup(controller)
    end

    class PageContentsBuilder
      def initialize(*conditions)
        @page_contents = PageContents.new(*conditions)
      end

      def build!(&block)
        instance_exec(&block)

        @page_contents
      end

      def misc(name, val = nil, &block)
        @page_contents.define(name, val, &block)
      end

      Seory::CONTENTS.each do |name|
        define_method(name) {|val = nil, &block| misc(name, val, &block) }
      end
    end

    class Descriptor
      def initialize(repository)
        @repository = repository
      end

      def describe(&block)
        instance_exec(&block)

        @repository
      end

      def match(*conditions, &def_builder)
        @repository << PageContentsBuilder.new(*conditions).build!(&def_builder)
      end

      def default(&def_builder)
        match(:default, &def_builder)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
seory-0.0.3 lib/seory/dsl.rb