lib/slide_hero/slide.rb in slide_hero-0.0.9 vs lib/slide_hero/slide.rb in slide_hero-0.0.10
- old
+ new
@@ -1,55 +1,26 @@
module SlideHero
class Slide
- attr_reader :headline, :headline_size, :transition, :background_color
- def initialize(headline=nil, headline_size: :medium, transition: :default, background_color: nil, &point_block)
+ include Compilable
+ extend Pluggable
+
+ attr_reader :headline, :headline_size, :transition, :background
+ def initialize(headline=nil, headline_size: :medium, transition: :default, background: nil, &point_block)
@headline = headline
@headline_size = headline_size
@transition = transition
- @background_color = background_color
+ @background= background
instance_eval(&point_block) if block_given?
end
- def compile
- Tilt::ERBTemplate.new(File.join(SlideHero.template_path,
- 'lib/slide_hero/views/slide.html.erb')).
- render(self)
- end
+ create_plugs_for Note, Point, List, Code, Image, RemoteImage, Media
- def point(text, animation: nil)
- points << Point.new(text, animation: animation).compile
- end
-
- def list(style=:unordered, &block)
- points << List.new(style, &block).compile
- end
-
- def code(*args, &code)
- points << Code.new(*args, &code).compile
- end
-
def points
@points ||= []
end
- def note(text)
- points << Note.new(text).compile
- end
-
- def image(*args, **kwargs)
- points << Image.new(*args, **kwargs).compile
- end
-
- def remote_image(*args, **kwargs)
- points << RemoteImage.new(*args, **kwargs).compile
- end
-
- def media(*args, **kwargs)
- points << Media.new(*args, **kwargs).compile
- end
-
private
def size_to_markup
{
large: :h1,
medium: :h2,
@@ -57,11 +28,17 @@
}[headline_size]
end
def data_attributes
"data-transition=\"#{transition}\"".tap do |attr|
- if background_color
- attr << " data-background=\"#{background_color}\""
+ case
+ when String(background).start_with?('http')
+ attr << " data-background=\"#{background}\""
+ when String(background).include?('.')
+ filename = background.gsub(/\s/, "%20")
+ attr << " data-background=\"/images/#{filename}\""
+ when background
+ attr << " data-background=\"#{background}\""
end
end
end
end
end