Class: Stupeflix::Definition

Inherits:
Nokogiri::XML::Builder
  • Object
show all
Defined in:
lib/stupeflix.rb

Constant Summary collapse

EFFECTS =
%w(kenburns flower rectangles none)
FONTS =
%w(arial arialbold arialroundedmtbold comicsansms couriernew landspeedrecord saddlebag timesnewroman verdana)
DIRECTIONS =
%w(left right up down)
TRANSITIONS =
%w(circle crossfade cube move over radial scan scans spiral strip swirl under waterdrop)
TRANSITIONS_WITH_DIR =
%w(cube move over scan spiral under)

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Definition

Returns a new instance of Definition.



65
66
67
68
69
70
71
72
73
# File 'lib/stupeflix.rb', line 65

def initialize &block
  super({}, Nokogiri::XML::Document.new) do |x|
    x.movie(service: 'craftsman-1.0') {
      x.body {
        yield x if block_given?
      }
    }
  end
end

Instance Method Details

#add_image(url, options = {}) ⇒ Object



97
98
99
100
101
# File 'lib/stupeflix.rb', line 97

def add_image url, options={}
  effect({ type: EFFECTS.sample }.merge options) {
    image filename: url
  }
end

#add_map(map) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/stupeflix.rb', line 84

def add_map map
  overlay(right: '0.0', bottom: '0.0', width:'0.25') {
    effect(type: 'none') {
      image filename: map
      filter type: 'frame', color: '#FFFFFFFF', width: '0.02'
      # could also use <image type="map" center="38.6436469,0.0456876" zoom="11" markers="38.6436469,0.0456876" size="250x150" mapkey="GMAPS_API_KEY" maptype="map"/>
      # as documented here: http://wiki.stupeflix.com/doku.php?id=gmapsimage
    }
    animator type: 'slide-in', direction: 'up', duration:'1.0'
    animator type: 'slide-out', direction: 'down', 'margin-start' => '6.0'
  }
end

#add_slide(url, caption, options = {}) ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/stupeflix.rb', line 75

def add_slide url, caption, options={}
  options = { duration: 1 }.merge options
  add_transition
  stack(duration: options[:duration]) {
    add_image url
    add_text_overlay caption if caption.length > 0 rescue nil
  }
end

#add_text(caption, options = {}) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/stupeflix.rb', line 103

def add_text caption, options={}
  return unless caption.length > 0 rescue nil
  defaults = { type: 'zone', vector: 'true', align: 'left,bottom' }
  long_caption = caption.length > 30
  #defaults[:align] = 'center,top'
  defaults[:fontsize] = 30 unless long_caption # prevent auto-scale from filling screen with huge text
  text_(defaults.merge options) {
    text caption
    filter(type: 'distancemap', distanceWidth: 40.0)
    filter type: 'distancecolor', distanceWidth: 40.0, color: '#de7316',
           strokeColor: '#000000', strokeOpacity: 1.0, strokeWidth: 0.02,
           dropShadowColor: '#00000044', dropShadowOpacity: 1.0, dropShadowBlurWidth: '0.9',
           dropShadowPosition: '0.01,-0.01', outerGlowColor: '#ffffff44', outerGlowOpacity: 1.0, outerGlowBlurWidth: 0.7
  }
end

#add_text_overlay(caption, options = {}) ⇒ Object



119
120
121
122
123
# File 'lib/stupeflix.rb', line 119

def add_text_overlay caption, options={}
  overlay {
    add_text caption, options
  }
end

#add_transition(options = {}) ⇒ Object



125
126
127
128
129
# File 'lib/stupeflix.rb', line 125

def add_transition options={}
  defaults = { type: TRANSITIONS.sample }
  defaults[:direction] = DIRECTIONS.sample if TRANSITIONS_WITH_DIR.include? defaults[:type]
  transition defaults.merge(options)
end