Class: Shining::Preso
- Inherits:
-
Object
- Object
- Shining::Preso
- Defined in:
- lib/shining/preso.rb
Constant Summary collapse
- SLIDE_FORMATS =
%w(markdown md html)
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #config(refresh = false) ⇒ Object
- #copy_templates ⇒ Object
-
#initialize(dir, fresh = true) ⇒ Preso
constructor
A new instance of Preso.
- #new_slide(file, options = {}) ⇒ Object
- #remove_slide(file) ⇒ Object
- #save_config! ⇒ Object
- #slides ⇒ Object
- #vendorize! ⇒ Object
Constructor Details
#initialize(dir, fresh = true) ⇒ Preso
Returns a new instance of Preso.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/shining/preso.rb', line 12 def initialize dir, fresh = true @path = (dir) if fresh new_dir dir copy_templates vendorize! end @config = json(@path/'config.json') @name = @config['title'] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/shining/preso.rb', line 8 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/shining/preso.rb', line 8 def path @path end |
Class Method Details
.open(dir) ⇒ Object
23 24 25 |
# File 'lib/shining/preso.rb', line 23 def self.open dir new dir, false end |
Instance Method Details
#config(refresh = false) ⇒ Object
27 28 29 |
# File 'lib/shining/preso.rb', line 27 def config refresh = false refresh ? @config = json(path/'config.json') : @config end |
#copy_templates ⇒ Object
36 37 38 39 40 41 |
# File 'lib/shining/preso.rb', line 36 def copy_templates %w(config.json slides index.html).each do |template| copy Shining.templates_path/template, @path + '/' end true end |
#new_slide(file, options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/shining/preso.rb', line 43 def file, = {} 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 [:with].include?('styles') rescue nil new_file path/'slides'/"#{name}.js" if [:with].include?('script') rescue nil config['slides'] << file and save_config! end |
#remove_slide(file) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/shining/preso.rb', line 53 def file file = basename(file) name, format = basename(file, extname(file)), extname(file).sub(/^./, '') delete! path/'slides'/file delete! path/'slides'/"#{name}.css" delete! path/'slides'/"#{name}.js" config['slides'].delete file and save_config! end |
#save_config! ⇒ Object
31 32 33 34 |
# File 'lib/shining/preso.rb', line 31 def save_config! new_file path/'config.json' do JSON.pretty_generate(@config) end true end |
#slides ⇒ Object
62 63 64 |
# File 'lib/shining/preso.rb', line 62 def @config['slides'] end |
#vendorize! ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/shining/preso.rb', line 66 def vendorize! new_dir @path/'vendor' new_dir @path/'vendor'/'lib' copy Shining.root/'lib'/'config.ru', @path + '/' copy Shining.root/'lib'/'*.js', @path/'vendor'/'lib' copy Shining.root/'lib'/'plugins', @path/'vendor'/'lib/' %w(css images themes).each do |required| copy Shining.root/required, @path/'vendor/' end true end |