From 0bfa6407740e027d1684b14beb521874b3f6ed4f Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 13 Feb 2012 11:32:46 -0500 Subject: [PATCH] be able to create a presentation and use thor for cli --- README.md | 14 +++++++ bin/attentive | 41 +++++++++++++++++-- lib/assets/javascripts/attentive.js.coffee | 8 +++- lib/attentive.rb | 10 ++++- skel/assets/javascripts/application.js.coffee | 2 + skel/assets/stylesheets/application.css.scss | 5 +++ skel/presentation.rb | 4 ++ skel/presentation/01_hello.slides | 32 +++++++++++++++ skel/views/_header.haml | 4 ++ 9 files changed, 115 insertions(+), 5 deletions(-) create mode 100644 skel/assets/javascripts/application.js.coffee create mode 100644 skel/assets/stylesheets/application.css.scss create mode 100644 skel/presentation.rb create mode 100644 skel/presentation/01_hello.slides create mode 100644 skel/views/_header.haml diff --git a/README.md b/README.md index a8e493c..276b6ed 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,17 @@ Attentive is a new take on Ruby presentation software. It provides lots of smart * Pygments for syntax highlighting. * Simple slide syntax, really really similar to how Showoff does it. +Here's what you can do: + +`attentive create ` + +Create a new presentation. + +`attentive` + +Run the presentation that's in the current directory on port 9393. + +`attentive start -p ` + +Run the current presentation on another port. + diff --git a/bin/attentive b/bin/attentive index 4d22ac4..92d369b 100755 --- a/bin/attentive +++ b/bin/attentive @@ -16,12 +16,47 @@ require 'pygments' require 'coffee_script' require 'sass' -load 'presentation.rb' +begin + load 'presentation.rb' +rescue LoadError => e +end # make sure pygments is ready Pygments.highlight("attentive") -Rack::Handler::WEBrick.run(Attentive::Server, :Port => 9393) do |server| - trap(:INT) { server.shutdown } +class Attentive::CLI < Thor + include Thor::Actions + + default_task :start + + desc "start", "Start a Rack server for previewing the presentation" + method_options [ :port, '-p' ] => 9393 + def start + if Attentive.has_presentation? + Rack::Handler::WEBrick.run(Attentive::Server, :Port => options[:port]) do |server| + trap(:INT) { server.shutdown } + end + else + raise Attentive::NoPresentationError + end + end + + def self.source_root + File.expand_path('../../skel', __FILE__) + end + + desc "create", "Create a new skeleton presentation" + def create(name) + self.destination_root = File.join(Dir.pwd, name) + + Dir[File.join(self.class.source_root, '**/*')].each do |file| + if File.file?(file) + filename = file.gsub(self.class.source_root + '/', '') + + template filename, filename + end + end + end end +Attentive::CLI.start diff --git a/lib/assets/javascripts/attentive.js.coffee b/lib/assets/javascripts/attentive.js.coffee index d4051a2..0744bf6 100644 --- a/lib/assets/javascripts/attentive.js.coffee +++ b/lib/assets/javascripts/attentive.js.coffee @@ -2,6 +2,12 @@ #= require fathom $(-> - $('#slides').fathom(displayMode: 'multi', scrollLength: 250) + fathom = new Fathom('#slides', displayMode: 'multi', scrollLength: 250) + + setTimeout( + -> + $(window).trigger('resize') + , 250 + ) ) diff --git a/lib/attentive.rb b/lib/attentive.rb index c04c889..85007b1 100644 --- a/lib/attentive.rb +++ b/lib/attentive.rb @@ -4,14 +4,22 @@ module Attentive autoload :Server, 'attentive/server' class << self - attr_accessor :title + attr_accessor :title, :has_presentation + + def has_presentation? + @has_presentation == true + end end def self.configure yield self + + Attentive.has_presentation = true end def self.root Pathname(File.expand_path('../..', __FILE__)) end + + class NoPresentationError < StandardError ; end end diff --git a/skel/assets/javascripts/application.js.coffee b/skel/assets/javascripts/application.js.coffee new file mode 100644 index 0000000..8dc5c39 --- /dev/null +++ b/skel/assets/javascripts/application.js.coffee @@ -0,0 +1,2 @@ +#= require attentive + diff --git a/skel/assets/stylesheets/application.css.scss b/skel/assets/stylesheets/application.css.scss new file mode 100644 index 0000000..e268f2b --- /dev/null +++ b/skel/assets/stylesheets/application.css.scss @@ -0,0 +1,5 @@ +@import 'attentive'; + +h1, h2, h3, li, p { + font-family: Nunito, sans-serif; +} diff --git a/skel/presentation.rb b/skel/presentation.rb new file mode 100644 index 0000000..7d55b7e --- /dev/null +++ b/skel/presentation.rb @@ -0,0 +1,4 @@ +Attentive.configure do |c| + c.title = "My presentation" +end + diff --git a/skel/presentation/01_hello.slides b/skel/presentation/01_hello.slides new file mode 100644 index 0000000..5872b09 --- /dev/null +++ b/skel/presentation/01_hello.slides @@ -0,0 +1,32 @@ +!SLIDE +# Hello! Welcome to Attentive. + +!SLIDE +# You can put Markdown in these slides... + +!SLIDE +

...or HTML

+ +!SLIDE +# or code! + +``` ruby +class Cat + def meow + "meow" + end +end +``` + +!SLIDE +# Easily style your slides using Sass & Compass... + +!SLIDE +# Add other interactivity (if you want) with CoffeeScript... + +!SLIDE +# Configure your presentation with Ruby! + +!SLIDE +## [github.com/johnbintz/attentive](http://github.com/johnbintz/attentive) + diff --git a/skel/views/_header.haml b/skel/views/_header.haml new file mode 100644 index 0000000..f12c221 --- /dev/null +++ b/skel/views/_header.haml @@ -0,0 +1,4 @@ +- # this file gets included in the output, inside the tags +- # use it for including things like Web fonts +%link{:href => 'http://fonts.googleapis.com/css?family=Nunito', :rel => 'stylesheet', :type => 'text/css'}/ +