Sha256: 0e44cdc6437b2a3567f4010506b28a05f04300060eea66e0932fce6c19eceefa

Contents?: true

Size: 1.6 KB

Versions: 8

Compression:

Stored size: 1.6 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
    include Retrieve
    attr_reader :author, :title, :theme, :transition
    attr_reader :config

    def initialize(args)
      @slides = []
      @config = retrieve(:config, args)
    end

    def theme(theme)
      config.theme = theme
    end

    def transition(transition)
      config.transition = transition
    end

    def title(title)
      config.title = title
    end

    def author(author)
      config.author = author
    end

    def revealjs_config(key, value)
      config.revealjs_config[key] = value
    end

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

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

    def build
      presentation = RevealCK::Presentation.new config: config
      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(self, &block).build
    end

    def self.load(args)
      file = retrieve(:file, args)
      config = retrieve(:config, args)
      builder = PresentationDSL.new config: config
      contents = File.open(file).read
      builder.instance_eval(contents)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
reveal-ck-3.8.0 lib/reveal-ck/presentation_dsl.rb
reveal-ck-3.7.0 lib/reveal-ck/presentation_dsl.rb
reveal-ck-3.6.0 lib/reveal-ck/presentation_dsl.rb
reveal-ck-3.5.1 lib/reveal-ck/presentation_dsl.rb
reveal-ck-3.5.0 lib/reveal-ck/presentation_dsl.rb
reveal-ck-3.4.0 lib/reveal-ck/presentation_dsl.rb
reveal-ck-3.3.1 lib/reveal-ck/presentation_dsl.rb
reveal-ck-3.3.0 lib/reveal-ck/presentation_dsl.rb