Class: SlideEmUp::Presentation

Inherits:
Object
  • Object
show all
Defined in:
lib/slide-em-up/presentation.rb

Defined Under Namespace

Classes: Meta, Section, Slide, Theme

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ Presentation

Returns a new instance of Presentation.



21
22
23
24
25
26
27
28
29
# File 'lib/slide-em-up/presentation.rb', line 21

def initialize(dir)
  infos   = extract_normal_infos(dir) || extract_infos_from_showoff(dir) || {}
  infos   = { "title" => "No title", "theme" => "shower", "duration" => 60 }.merge(infos)
  @meta   = build_meta(infos["title"], dir, infos["author"], infos["duration"])
  @theme  = build_theme(infos["theme"])
  @common = build_theme("common")
  @parts  = infos["sections"] || raise(Exception, "check your presentation.json or showoff.json file")
  @parts  = Hash[@parts.zip @parts] if Array === @parts
end

Instance Attribute Details

#commonObject

Returns the value of attribute common.



19
20
21
# File 'lib/slide-em-up/presentation.rb', line 19

def common
  @common
end

#metaObject

Returns the value of attribute meta.



19
20
21
# File 'lib/slide-em-up/presentation.rb', line 19

def meta
  @meta
end

#partsObject

Returns the value of attribute parts.



19
20
21
# File 'lib/slide-em-up/presentation.rb', line 19

def parts
  @parts
end

#themeObject

Returns the value of attribute theme.



19
20
21
# File 'lib/slide-em-up/presentation.rb', line 19

def theme
  @theme
end

Instance Method Details

#htmlObject



31
32
33
34
# File 'lib/slide-em-up/presentation.rb', line 31

def html
  str = File.read("#{theme.dir}/index.erb")
  Erubis::Eruby.new(str).result(:meta => meta, :theme => theme, :sections => sections)
end

#nb_slidesObject



43
44
45
46
47
48
# File 'lib/slide-em-up/presentation.rb', line 43

def nb_slides
  @parts.inject(0) do |nb,(dir,title)|
    raw = Dir["#{meta.dir}/#{dir}/**/*.md"].map { |f| File.read(f) }.join("\n\n")
    nb += raw.split(/!SLIDE */).length
  end
end

#path_for_asset(asset) ⇒ Object



36
37
38
39
40
41
# File 'lib/slide-em-up/presentation.rb', line 36

def path_for_asset(asset)
  Dir[     "#{meta.dir}#{asset}"].first ||
    Dir[  "#{theme.dir}#{asset}"].first ||
    Dir[ "#{common.dir}#{asset}"].first ||
    Dir["#{meta.dir}/**#{asset}"].first
end