Class: Showoff::Presentation
- Inherits:
-
Object
- Object
- Showoff::Presentation
- Defined in:
- lib/showoff/presentation.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#sections ⇒ Object
readonly
Returns the value of attribute sections.
Instance Method Summary collapse
-
#assets ⇒ Object
Generates a list of all image/font/etc files used by the presentation.
- #compile ⇒ Object
- #css_files ⇒ Object
- #erb(template) ⇒ Object
-
#index ⇒ Object
The index page does not contain content; just a placeholder div that’s dynamically loaded after the page is displayed.
-
#initialize(options) ⇒ Presentation
constructor
A new instance of Presentation.
- #js_files ⇒ Object
-
#language_names ⇒ Object
@todo: backwards compatibility shim.
-
#mapped_keys(action, klass = 'key') ⇒ Object
return a list of keys associated with a given action in the keymap.
-
#master_presenter? ⇒ Boolean
@todo: this should be part of the server.
- #slides ⇒ Object
- #static ⇒ Object
-
#user_translations ⇒ Object
@todo: backwards compatibility shim.
-
#valid_presenter_cookie? ⇒ Boolean
@todo: this should be part of the server.
Constructor Details
#initialize(options) ⇒ Presentation
Returns a new instance of Presentation.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/showoff/presentation.rb', line 9 def initialize() @options = @sections = Showoff::Config.sections.map do |name, files| Showoff::Presentation::Section.new(name, files) end # weird magic variables the presentation expects @baseurl = nil # this doesn't appear to have ever been used @title = Showoff::Config.get('name') || I18n.t('name') @favicon = Showoff::Config.get('favicon') || 'favicon.ico' @feedback = Showoff::Config.get('feedback') # note: the params check is obsolete @pause_msg = Showoff::Config.get('pause_msg') @language = Showoff::Locale.translations @edit = Showoff::Config.get('edit') if [:review] # invert the logic to maintain backwards compatibility of interactivity on by default @interactive = ! [:standalone] # Load up the default keymap, then merge in any customizations keymapfile = File.(File.join('~', '.showoff', 'keymap.json')) @keymap = Keymap.default @keymap.merge! JSON.parse(File.read(keymapfile)) rescue {} # map keys to the labels we're using @keycode_dictionary = Keymap.keycodeDictionary @keycode_shifted_keys = Keymap.shiftedKeyDictionary @highlightStyle = Showoff::Config.get('highlight') || 'default' if Showoff::State.get(:supplemental) @wrapper_classes = ['supplemental'] end end |
Instance Attribute Details
#sections ⇒ Object (readonly)
Returns the value of attribute sections.
7 8 9 |
# File 'lib/showoff/presentation.rb', line 7 def sections @sections end |
Instance Method Details
#assets ⇒ Object
Generates a list of all image/font/etc files used by the presentation. This will only identify the sources of <img> tags and files referenced by the CSS url() function.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/showoff/presentation.rb', line 95 def assets # This singleton guard removes ordering coupling between assets() & static() @doc ||= compile # matches url(<path>) and returns the path as a capture group urlsrc = /url\([\"\']?(.*?)(?:[#\?].*)?[\"\']?\)/ # get all image and url() sources files = @doc.search('img').map {|img| img[:src] } @doc.search('*').each do |node| next unless node[:style] next unless matches = node[:style].match(urlsrc) files << matches[1] end # add in images from css files too css_files.each do |css_path| data = File.read(File.join(Showoff::Config.root, css_path)) # @todo: This isn't perfect. It will match commented out styles. But its # worst case behavior is displaying a warning message, so that's ok for now. data.scan(urlsrc).flatten.each do |path| # resolve relative paths in the stylesheet path = File.join(File.dirname(css_path), path) unless path.start_with? '/' files << path end end # also all user-defined styles and javascript files files.concat css_files files.concat js_files files.uniq end |
#compile ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/showoff/presentation.rb', line 43 def compile Showoff::State.reset([:slide_count, :section_major, :section_minor]) # @todo For now, we reparse the html so that we can generate content via slide # templates. This adds a bit of extra time, but not too much. Perhaps # we'll change that at some point. html = @sections.map(&:render).join("\n") doc = Nokogiri::HTML::DocumentFragment.parse(html) Showoff::Compiler::TableOfContents.generate!(doc) Showoff::Compiler::Glossary.generatePage!(doc) doc end |
#css_files ⇒ Object
133 134 135 136 137 |
# File 'lib/showoff/presentation.rb', line 133 def css_files base = Dir.glob("#{Showoff::Config.root}/*.css").map { |path| File.basename(path) } extra = Array(Showoff::Config.get('styles')) base + extra end |
#erb(template) ⇒ Object
129 130 131 |
# File 'lib/showoff/presentation.rb', line 129 def erb(template) ERB.new(File.read(File.join(Showoff::GEMROOT, 'views', "#{template}.erb")), nil, '-').result(binding) end |
#index ⇒ Object
The index page does not contain content; just a placeholder div that’s dynamically loaded after the page is displayed. This increases perceived responsiveness.
61 62 63 |
# File 'lib/showoff/presentation.rb', line 61 def index ERB.new(File.read(File.join(Showoff::GEMROOT, 'views','index.erb')), nil, '-').result(binding) end |
#js_files ⇒ Object
139 140 141 142 143 |
# File 'lib/showoff/presentation.rb', line 139 def js_files base = Dir.glob("#{Showoff::Config.root}/*.js").map { |path| File.basename(path) } extra = Array(Showoff::Config.get('scripts')) base + extra end |
#language_names ⇒ Object
@todo: backwards compatibility shim
165 166 167 |
# File 'lib/showoff/presentation.rb', line 165 def language_names Showoff::Locale.contentLanguages end |
#mapped_keys(action, klass = 'key') ⇒ Object
return a list of keys associated with a given action in the keymap
146 147 148 149 150 151 152 153 154 |
# File 'lib/showoff/presentation.rb', line 146 def mapped_keys(action, klass='key') list = @keymap.select { |key,value| value == action }.keys if klass list.map { |val| "<span class=\"#{klass}\">#{val}</span>" }.join else list.join ', ' end end |
#master_presenter? ⇒ Boolean
@todo: this should be part of the server. Move there with the least disruption.
171 172 173 |
# File 'lib/showoff/presentation.rb', line 171 def master_presenter? false end |
#slides ⇒ Object
65 66 67 |
# File 'lib/showoff/presentation.rb', line 65 def compile.to_html end |
#static ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/showoff/presentation.rb', line 69 def static # This singleton guard removes ordering coupling between assets() & static() @doc ||= compile @slides = @doc.to_html # All static snapshots should be non-interactive by definition @interactive = false case Showoff::State.get(:format) when 'web' template = 'index.erb' when 'print', 'supplemental', 'pdf' template = 'onepage.erb' end ERB.new(File.read(File.join(Showoff::GEMROOT, 'views', template)), nil, '-').result(binding) end |
#user_translations ⇒ Object
@todo: backwards compatibility shim
160 161 162 |
# File 'lib/showoff/presentation.rb', line 160 def user_translations Showoff::Locale.userTranslations end |
#valid_presenter_cookie? ⇒ Boolean
@todo: this should be part of the server. Move there with the least disruption.
176 177 178 |
# File 'lib/showoff/presentation.rb', line 176 def false end |