lib/prez/helpers.rb in prez-0.0.2 vs lib/prez/helpers.rb in prez-0.0.3
- old
+ new
@@ -4,23 +4,89 @@
module Prez
module Helpers
protected
+ def duration(value)
+ if @duration
+ raise Prez::Error.new("The duration helper can only be called once!")
+ end
+
+ if value.kind_of?(String) && value.split(":").size > 3
+ raise Prez::Eror.new("Only hours:minutes:seconds are supported for the duration!")
+ end
+
+ @duration = value
+ nil
+ end
+
+ def duration_amount
+ return if @duration.nil? || @duration.to_i <= 0
+
+ # Ensure it is an integer first... then we can normalize based
+ # on standard times (ie, no 70 seconds, or 100 minutes)
+ if @duration.kind_of? String
+ @duration = @duration.split ":"
+ @duration.map! &:to_i
+ value = @duration.pop || 0
+ value += (@duration.pop || 0) * 60
+ value += (@duration.pop || 0) * 60 * 60
+ @duration = value
+ end
+
+ # Ensure we don't have a floating point number
+ @duration = @duration.to_i
+ seconds = @duration % 60
+ minutes = (@duration / 60) % 60
+ hours = @duration / 60 / 60
+
+ if hours > 0
+ "%d:%02d:%02d" % [hours, minutes, seconds]
+ elsif minutes > 0
+ "%2d:%02d" % [minutes, seconds]
+ else
+ seconds.to_s
+ end
+ end
+
def html_escape(value)
CGI.escape_html value
end
- def slide
- concat %{<div class="prez-slide">}
+ def slide(options = {})
+ classes = ["prez-slide"]
+ align = options.fetch :align, :center
+
+ case align
+ when :left
+ classes << "left-aligned"
+ when :right
+ classes << "right-aligned"
+ when :center
+ # Nothing needed
+ else
+ raise Prez::Error.new("Invalid slide align: #{align.inspect}")
+ end
+
+ if options[:duration]
+ duration_attribute = %{ data-duration="#{options[:duration]}"}
+ end
+
+ concat %{<div class="#{classes.join " "}"#{duration_attribute}>}
yield
concat %{</div>}
end
def notes
concat %{<div class="prez-notes">}
yield
concat %{</div>}
+ end
+
+ def image(name, options = {})
+ Prez::Assets.image name, options
+ rescue Prez::Files::MissingError
+ raise Prez::Error.new("Could not find image file: '#{name}'")
end
def javascript(name)
Prez::Assets.javascript name
rescue Prez::Files::MissingError