lib/prez/helpers.rb in prez-0.1.0 vs lib/prez/helpers.rb in prez-0.1.1
- old
+ new
@@ -3,10 +3,11 @@
module Prez
module Helpers
protected
def reset_helpers!
+ @launch = :choose
@duration = nil
end
def duration(value)
if @duration
@@ -48,10 +49,22 @@
else
seconds.to_s
end
end
+ def launch(new_window: true)
+ if new_window
+ @launch = :new_window
+ else
+ @launch = :current_window
+ end
+ end
+
+ def launch_type
+ @launch
+ end
+
def html_escape(value = nil, &block)
if block
value = capture &block
end
@@ -74,36 +87,63 @@
@output_buffer = old_buffer
end
def slide(options = {})
classes = ["prez-slide"]
+ classes << options[:class] if options[:class]
align = options.fetch :align, :center
case align
when :left
classes << "left-aligned"
when :right
classes << "right-aligned"
when :center
- # Nothing needed
+ classes << "center-aligned"
else
raise Prez::Error.new("Invalid slide align: #{align.inspect}")
end
+ attributes = [%{class="#{classes.join " "}"}]
+
+ if options[:id]
+ attributes << %{id="#{options[:id]}"}
+ end
+
+ if options[:style]
+ attributes << %{style="#{options[:style]}"}
+ end
+
if options[:duration]
- duration_attribute = %{ data-duration="#{options[:duration]}"}
+ attributes << %{data-duration="#{options[:duration]}"}
end
- concat %{<div class="#{classes.join " "}"#{duration_attribute}>}
+ concat %{<div #{attributes.join " "}>}
yield
concat %{</div>}
end
def element(options = {})
tag = options.fetch :tag, :div
- concat %{<#{tag} class="prez-element">}
+ classes = ["prez-element"]
+ classes << options[:class] if options[:class]
+ attributes = [%{class="#{classes.join " "}"}]
+
+ if options[:id]
+ attributes << %{id="#{options[:id]}"}
+ end
+
+ if options[:style]
+ attributes << %{style="#{options[:style]}"}
+ end
+
+ concat %{<#{tag} #{attributes.join " "}>}
yield
concat %{</#{tag}>}
+ end
+
+ def element_js(up:, down:)
+ concat Prez::JavascriptElement.new(capture(&up), capture(&down)).to_s
end
def notes
concat %{<div class="prez-notes">}
yield