exports
This commit is contained in:
parent
2f76f2cac5
commit
4723f8754d
@ -33,5 +33,7 @@ Gem::Specification.new do |gem|
|
|||||||
gem.add_dependency 'thor'
|
gem.add_dependency 'thor'
|
||||||
gem.add_dependency 'backbone-rails'
|
gem.add_dependency 'backbone-rails'
|
||||||
gem.add_dependency 'rack', '~> 1.4.0'
|
gem.add_dependency 'rack', '~> 1.4.0'
|
||||||
|
|
||||||
|
gem.add_dependency 'selenium-webdriver'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -113,6 +113,47 @@ class Attentive::CLI < Thor
|
|||||||
system %{git commit -a -m "Update published site"}
|
system %{git commit -a -m "Update published site"}
|
||||||
system %{git checkout master}
|
system %{git checkout master}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc 'export', 'Export each slide as a .png file using Selenium'
|
||||||
|
def export
|
||||||
|
puts "Exporting to static HTML..."
|
||||||
|
|
||||||
|
static
|
||||||
|
|
||||||
|
require 'selenium-webdriver'
|
||||||
|
|
||||||
|
browser = Selenium::WebDriver.for(:firefox)
|
||||||
|
|
||||||
|
browser.navigate.to "file://#{Dir.pwd}/_site/index.html"
|
||||||
|
|
||||||
|
browser.execute_script('window.resizeTo(1024, 768)')
|
||||||
|
|
||||||
|
get_current_slide = lambda { ((browser.execute_script('return document.location.href') || '')[%r{#(\d+)$}, 1] || -1).to_i }
|
||||||
|
|
||||||
|
FileUtils.rm_rf '_export'
|
||||||
|
FileUtils.mkdir_p '_export'
|
||||||
|
|
||||||
|
while (current_slide = get_current_slide.call) == -1
|
||||||
|
sleep 0.1
|
||||||
|
end
|
||||||
|
|
||||||
|
while true do
|
||||||
|
browser.save_screenshot("_export/#{current_slide}.png")
|
||||||
|
|
||||||
|
browser.find_element(:css, 'body').click
|
||||||
|
|
||||||
|
sleep 1
|
||||||
|
|
||||||
|
next_slide = get_current_slide.call
|
||||||
|
|
||||||
|
break if next_slide == current_slide
|
||||||
|
|
||||||
|
current_slide = next_slide
|
||||||
|
end
|
||||||
|
ensure
|
||||||
|
browser.close if browser
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Attentive::CLI.start
|
Attentive::CLI.start
|
||||||
|
|
||||||
|
@ -34,8 +34,9 @@ class Attentive.Presentation
|
|||||||
start: ->
|
start: ->
|
||||||
@timer.render()
|
@timer.render()
|
||||||
|
|
||||||
document.addEventListener('click', @handleClick, false)
|
|
||||||
document.addEventListener('keydown', @handleKeyDown, false)
|
document.addEventListener('keydown', @handleKeyDown, false)
|
||||||
|
document.addEventListener('mousedown', @handleMouseDown, false)
|
||||||
|
document.addEventListener('mouseup', @handleMouseUp, false)
|
||||||
window.addEventListener('resize', _.throttle(@calculate, 500), false)
|
window.addEventListener('resize', _.throttle(@calculate, 500), false)
|
||||||
|
|
||||||
imageWait = null
|
imageWait = null
|
||||||
@ -59,7 +60,17 @@ class Attentive.Presentation
|
|||||||
handlePopState: (e) =>
|
handlePopState: (e) =>
|
||||||
this.advanceTo(this.slideFromLocation())
|
this.advanceTo(this.slideFromLocation())
|
||||||
|
|
||||||
handleClick: (e) =>
|
handleMouseDown: (e) =>
|
||||||
|
@startSwipeX = e.x
|
||||||
|
|
||||||
|
handleMouseUp: (e) =>
|
||||||
|
distance = @startSwipeX - e.x
|
||||||
|
if Math.abs(distance) > 10
|
||||||
|
if distance < 0
|
||||||
|
this.advance(-1)
|
||||||
|
else
|
||||||
|
this.advance(1)
|
||||||
|
else
|
||||||
this.advance() if e.target.tagName != 'A'
|
this.advance() if e.target.tagName != 'A'
|
||||||
|
|
||||||
handleKeyDown: (e) =>
|
handleKeyDown: (e) =>
|
||||||
|
@ -2,6 +2,7 @@ require "attentive/version"
|
|||||||
|
|
||||||
module Attentive
|
module Attentive
|
||||||
autoload :Server, 'attentive/server'
|
autoload :Server, 'attentive/server'
|
||||||
|
autoload :Export, 'attentive/export'
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
attr_accessor :title, :has_presentation, :use_pygments_command_line
|
attr_accessor :title, :has_presentation, :use_pygments_command_line
|
||||||
|
@ -7,6 +7,7 @@ require 'sinatra'
|
|||||||
require 'nokogiri'
|
require 'nokogiri'
|
||||||
require 'rdiscount'
|
require 'rdiscount'
|
||||||
require 'sinatra/base'
|
require 'sinatra/base'
|
||||||
|
require 'pygments'
|
||||||
|
|
||||||
require 'rack/builder'
|
require 'rack/builder'
|
||||||
|
|
||||||
@ -30,13 +31,12 @@ module Attentive
|
|||||||
@sprockets_env ||= Sprockets::EnvironmentWithVendoredGems.new
|
@sprockets_env ||= Sprockets::EnvironmentWithVendoredGems.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.start(options)
|
def self.start(options, &block)
|
||||||
require 'rack'
|
require 'rack'
|
||||||
require 'coffee_script'
|
require 'coffee_script'
|
||||||
require 'sass'
|
require 'sass'
|
||||||
|
|
||||||
require 'tilt/coffee'
|
require 'tilt/coffee'
|
||||||
require 'pygments'
|
|
||||||
|
|
||||||
if !Attentive.use_pygments_command_line?
|
if !Attentive.use_pygments_command_line?
|
||||||
# make sure pygments is ready before starting a new thread
|
# make sure pygments is ready before starting a new thread
|
||||||
@ -44,6 +44,8 @@ module Attentive
|
|||||||
end
|
end
|
||||||
|
|
||||||
Rack::Handler.default.run(Attentive::Server, :Port => options[:port]) do |server|
|
Rack::Handler.default.run(Attentive::Server, :Port => options[:port]) do |server|
|
||||||
|
block.call(server) if block
|
||||||
|
|
||||||
trap(:INT) do
|
trap(:INT) do
|
||||||
server.shutdown if server.respond_to?(:server)
|
server.shutdown if server.respond_to?(:server)
|
||||||
server.stop if server.respond_to?(:stop)
|
server.stop if server.respond_to?(:stop)
|
||||||
|
Loading…
Reference in New Issue
Block a user