Sha256: bac9938937355b5fc1b1305dff14ddc8b05e7afdd09dee8f2ed59608b7fecece

Contents?: true

Size: 1.28 KB

Versions: 3

Compression:

Stored size: 1.28 KB

Contents

module RevealCK
  #
  # Public: A PresentationDSL defines the DSL behind a
  # presentation. It also knows how to load file containing the DSL.
  #
  class PresentationDSL

    attr_reader :author, :title, :theme, :transition

    def initialize
      @slides = []
    end

    def theme(theme)
      @theme = theme
    end

    def transition(transition)
      @transition = transition
    end

    def title(title)
      @title = title
    end

    def author(author)
      @author = author
    end

    def slide(template, variables = {})
      variables[:template] = template
      @slides << RevealCK::Slide.new(variables)
    end

    def contents_of(path)
      File.open(path).read
    end

    def build
      presentation = RevealCK::Presentation.new
      presentation.theme = @theme if @theme
      presentation.transition = @transition if @transition
      presentation.author = @author if @author
      presentation.title = @title if @title
      @slides.each { |slide| presentation.add slide }
      presentation
    end

    require 'docile'

    def presentation(&block)
      Docile.dsl_eval(PresentationDSL.new, &block).build
    end

    def self.load(file)
      builder = PresentationDSL.new
      contents = File.open(file).read
      builder.instance_eval(contents)
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
reveal-ck-0.2.0 lib/reveal-ck/presentation_dsl.rb
reveal-ck-0.1.8 lib/reveal-ck/presentation_dsl.rb
reveal-ck-0.1.7 lib/reveal-ck/presentation_dsl.rb