Class: Shining::Preso

Inherits:
Object
  • Object
show all
Defined in:
lib/shining/preso.rb

Constant Summary collapse

SLIDE_FORMATS =
%w(haml markdown html)
TEMPLATE_FORMATS =
SLIDE_FORMATS - ['html']

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir, fresh = true) ⇒ Preso

Returns a new instance of Preso.



14
15
16
17
18
19
20
21
# File 'lib/shining/preso.rb', line 14

def initialize dir, fresh = true
  @path   = expand(dir)
  if fresh
    new_dir dir
    copy_templates
  end
  @config = json(@path/'config.json')
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



9
10
11
# File 'lib/shining/preso.rb', line 9

def path
  @path
end

Class Method Details

.open(dir) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/shining/preso.rb', line 23

def self.open dir
  begin
    new dir, false
  rescue
    raise "#{dir} is not a Shining presentation!"
  end
end

Instance Method Details

#compile_templates!Object



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/shining/preso.rb', line 70

def compile_templates!
  templates.each do |template|
    begin
      target   = basename(template).sub(extname(template), '.html')
      rendered = Tilt.new(path/'slides'/template).render
      new_file path/'slides'/target do rendered end
    rescue RuntimeError
      Shining.error "Tilt coult not compile #{File.basename template}. Skipping."
    end
  end
end

#config(refresh = false) ⇒ Object



31
32
33
# File 'lib/shining/preso.rb', line 31

def config refresh = false
  refresh ? @config = json(path/'config.json') : @config
end

#copy_templatesObject



40
41
42
43
44
45
46
# File 'lib/shining/preso.rb', line 40

def copy_templates
  %w(config.json slides).each do |template|
    copy Shining.templates_path/template, @path + '/'
  end
  new_file @path/'index.html' do erb(Shining.templates_path/'index.html') end
  true
end

#new_slide(file, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


52
53
54
55
56
57
58
59
60
# File 'lib/shining/preso.rb', line 52

def new_slide file, options = {}
  file = basename(file)
  name, format = basename(file, extname(file)), extname(file).sub(/^./, '')
  raise ArgumentError, "Format needs to be #{SLIDE_FORMATS.join(' or ')}." unless SLIDE_FORMATS.include? format
  new_file path/'slides'/file do Shining.sample_content_for(format) end
  new_file path/'slides'/"#{name}.css"  if options[:with].include?('styles') rescue nil
  new_file path/'slides'/"#{name}.js"   if options[:with].include?('script') rescue nil
  config['slides'] << name and save_config!
end

#save_config!Object



35
36
37
38
# File 'lib/shining/preso.rb', line 35

def save_config!
  new_file path/'config.json' do JSON.pretty_generate(@config) end
  true
end

#slidesObject



62
63
64
# File 'lib/shining/preso.rb', line 62

def slides
  @config['slides']
end

#templatesObject



48
49
50
# File 'lib/shining/preso.rb', line 48

def templates
  Dir[path/'slides'/"*.{#{TEMPLATE_FORMATS.join(',')}}"].map { |template| basename(template) }
end

#unvendorize!Object



95
96
97
98
# File 'lib/shining/preso.rb', line 95

def unvendorize!
  delete! @path/'vendor'
  copy_templates
end

#vendorize!Object



82
83
84
85
86
87
88
89
# File 'lib/shining/preso.rb', line 82

def vendorize!
  new_dir @path/'vendor'
  %w(lib css images themes).each do |required|
    copy Shining.root/required, @path/'vendor/'
  end
  new_file @path/'index.html' do erb(Shining.templates_path/'index.html') end
  true
end

#vendorized?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/shining/preso.rb', line 91

def vendorized?
  dir? @path/'vendor'
end