Sha256: a21a6f7ce16c827356edfaee5a6dc913554e14ad4dc54781cf45eec3e570019f

Contents?: true

Size: 1.27 KB

Versions: 14

Compression:

Stored size: 1.27 KB

Contents

module Trestle
  class Navigation
    class Block
      attr_reader :block, :admin

      def initialize(admin=nil, &block)
        @admin = admin
        @block = block
      end

      def items(context)
        context = Evaluator.new(@admin, context)
        context.instance_exec(@admin, &block)
        context.items
      end

      class Evaluator
        include EvaluationContext

        attr_reader :items

        def initialize(admin=nil, context=nil)
          @admin, @context = admin, context
          @items = []
        end

        def default_path
          @admin ? @admin.path : nil
        end

        def item(name, path=nil, options={})
          if path.is_a?(Hash)
            options = path
            path = nil
          end

          if options[:group]
            group = Group.new(options[:group])
          elsif @current_group
            group = @current_group
          end

          options = options.merge(group: group) if group
          options = options.merge(admin: @admin) if @admin

          items << Item.new(name, path || default_path, options)
        end

        def group(name, options={})
          @current_group = Group.new(name, options)
          yield
        ensure
          @current_group = nil
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
trestle-0.10.0 lib/trestle/navigation/block.rb
trestle-0.10.0.pre2 lib/trestle/navigation/block.rb
trestle-0.10.0.pre lib/trestle/navigation/block.rb
trestle-0.9.8 lib/trestle/navigation/block.rb
trestle-0.9.7 lib/trestle/navigation/block.rb
trestle-0.9.6 lib/trestle/navigation/block.rb
trestle-0.9.5 lib/trestle/navigation/block.rb
trestle-0.9.4 lib/trestle/navigation/block.rb
trestle-0.9.3 lib/trestle/navigation/block.rb
trestle-0.9.2 lib/trestle/navigation/block.rb
trestle-0.9.1 lib/trestle/navigation/block.rb
trestle-0.9.0 lib/trestle/navigation/block.rb
trestle-0.8.13 lib/trestle/navigation/block.rb
trestle-0.8.12 lib/trestle/navigation/block.rb