showoff 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -276,6 +276,7 @@ added where your cursor was. Binding this to a keybinding can allow you to add
276
276
  [<tt>create</tt>] Create new showoff presentation
277
277
  [<tt>help</tt>] Shows list of commands or help for one command
278
278
  [<tt>heroku</tt>] Setup your presentation to serve on Heroku
279
+ [<tt>github</tt>] Setup your presentation to serve on GitHub Pages
279
280
  [<tt>serve</tt>] Serves the showoff presentation in the current directory
280
281
  [<tt>static</tt>] Generate static version of presentation
281
282
 
@@ -320,6 +321,10 @@ Setup your presentation to serve on Heroku
320
321
 
321
322
  Creates the Gemfile and config.ru file needed to push a showoff pres to heroku. It will then run heroku create for you to register the new project on heroku and add the remote for you. Then all you need to do is commit the new created files and run git push heroku to deploy.
322
323
 
324
+ === <tt>github</tt>
325
+
326
+ Generates a static version of your site and puts it in a gh-pages branch for static serving on GitHub.
327
+
323
328
  ==== Options
324
329
  These options are specified *after* the command.
325
330
 
data/bin/showoff CHANGED
@@ -7,6 +7,14 @@ require 'gli'
7
7
 
8
8
  include GLI
9
9
 
10
+ desc 'Show ShowOff version'
11
+ long_desc 'This command shows the currently installed version of ShowOff'
12
+ command [:version] do |c|
13
+ c.action do |global_options,options,args|
14
+ puts "ShowOff Version " + ShowOff::Version
15
+ end
16
+ end
17
+
10
18
  desc 'Create new showoff presentation'
11
19
  arg_name 'dir_name'
12
20
  long_desc 'This command helps start a new showoff presentation by setting up the proper directory structure for you. It takes the directory name you would like showoff to create for you.'
@@ -25,6 +33,14 @@ command [:create,:init] do |c|
25
33
  end
26
34
  end
27
35
 
36
+ desc 'Puts your showoff presentation into a gh-pages branch'
37
+ long_desc 'Generates a static version of your presentation into your gh-pages branch for publishing to GitHub Pages'
38
+ command :github do |c|
39
+ c.action do |global_options,options,args|
40
+ ShowOffUtils.github
41
+ end
42
+ end
43
+
28
44
  desc 'Serves the showoff presentation in the current directory'
29
45
  desc 'Setup your presentation to serve on Heroku'
30
46
  arg_name 'heroku_name'
data/lib/showoff.rb CHANGED
@@ -9,13 +9,13 @@ require 'fileutils'
9
9
  begin
10
10
  require 'RMagick'
11
11
  rescue LoadError
12
- puts 'image sizing disabled - install RMagick'
12
+ $stderr.puts 'image sizing disabled - install RMagick'
13
13
  end
14
14
 
15
15
  begin
16
16
  require 'pdfkit'
17
17
  rescue LoadError
18
- puts 'pdf generation disabled - install PDFKit'
18
+ $stderr.puts 'pdf generation disabled - install PDFKit'
19
19
  end
20
20
 
21
21
  begin
@@ -26,9 +26,10 @@ rescue LoadError
26
26
  end
27
27
  require 'pp'
28
28
 
29
-
30
29
  class ShowOff < Sinatra::Application
31
30
 
31
+ Version = VERSION = '0.3.4'
32
+
32
33
  attr_reader :cached_image_size
33
34
 
34
35
  set :views, File.dirname(__FILE__) + '/../views'
@@ -125,7 +126,7 @@ class ShowOff < Sinatra::Application
125
126
  paths.pop
126
127
  path = paths.join('/')
127
128
  replacement_prefix = static ?
128
- %(img src="file://#{options.pres_dir}/#{path}) :
129
+ %(img src="./file/#{path}) :
129
130
  %(img src="/image/#{path})
130
131
  slide.gsub(/img src=\"(.*?)\"/) do |s|
131
132
  img_path = File.join(path, $1)
@@ -241,7 +242,7 @@ class ShowOff < Sinatra::Application
241
242
  if static
242
243
  @title = ShowOffUtils.showoff_title
243
244
  @slides = get_slides_html(static)
244
- @asset_path = "."
245
+ @asset_path = "./"
245
246
  end
246
247
  erb :index
247
248
  end
@@ -273,14 +274,14 @@ class ShowOff < Sinatra::Application
273
274
  href = clean_link(link['src'])
274
275
  assets << href if href
275
276
  end
276
-
277
+
277
278
  css = Dir.glob("#{options.public}/**/*.css").map { |path| path.gsub(options.public + '/', '') }
278
279
  assets << css
279
280
 
280
281
  js = Dir.glob("#{options.public}/**/*.js").map { |path| path.gsub(options.public + '/', '') }
281
282
  assets << js
282
283
 
283
- assets.uniq.join("\n")
284
+ assets.uniq.join("\n")
284
285
  end
285
286
 
286
287
  def slides(static=false)
@@ -325,7 +326,7 @@ class ShowOff < Sinatra::Application
325
326
  else
326
327
  out = "#{path}/#{name}/static"
327
328
  # First make a directory
328
- FileUtils.makedirs("#{out}")
329
+ FileUtils.makedirs(out)
329
330
  # Then write the html
330
331
  file = File.new("#{out}/index.html", "w")
331
332
  file.puts(data)
@@ -342,6 +343,23 @@ class ShowOff < Sinatra::Application
342
343
  next unless File.directory?(subpath) || base.match(/\.(css|js)$/)
343
344
  FileUtils.copy_entry(subpath, "#{out}/#{base}")
344
345
  }
346
+
347
+ # Set up file dir
348
+ file_dir = File.join(out, 'file')
349
+ FileUtils.makedirs(file_dir)
350
+ pres_dir = showoff.options.pres_dir
351
+
352
+ # ..., copy all user-defined styles and javascript files
353
+ Dir.glob("#{pres_dir}/*.{css,js}").each { |path|
354
+ FileUtils.copy(path, File.join(file_dir, File.basename(path)))
355
+ }
356
+
357
+ # ... and copy all needed image files
358
+ data.scan(/img src=\".\/file\/(.*?)\"/).flatten.each do |path|
359
+ dir = File.dirname(path)
360
+ FileUtils.makedirs(File.join(file_dir, dir))
361
+ FileUtils.copy(File.join(pres_dir, path), File.join(file_dir, path))
362
+ end
345
363
  end
346
364
  end
347
365
 
data/lib/showoff_utils.rb CHANGED
@@ -91,6 +91,25 @@ class ShowOffUtils
91
91
  end
92
92
  end
93
93
 
94
+ # generate a static version of the site into the gh-pages branch
95
+ def self.github
96
+ puts "Generating static content"
97
+ ShowOff.do_static(nil)
98
+ `git add static`
99
+ sha = `git write-tree`.chomp
100
+ tree_sha = `git rev-parse #{sha}:static`.chomp
101
+ `git read-tree HEAD` # reset staging to last-commit
102
+ ghp_sha = `git rev-parse gh-pages 2>/dev/null`.chomp
103
+ extra = ghp_sha != 'gh-pages' ? "-p #{ghp_sha}" : ''
104
+ commit_sha = `echo 'static presentation' | git commit-tree #{tree_sha} #{extra}`.chomp
105
+ `git update-ref refs/heads/gh-pages #{commit_sha}`
106
+ puts "I've updated your 'gh-pages' branch with the static version of your presentation."
107
+ puts "Push it to GitHub to publish it. Probably something like:"
108
+ puts
109
+ puts " git push origin gh-pages"
110
+ puts
111
+ end
112
+
94
113
  # Makes a slide as a string.
95
114
  # [title] title of the slide
96
115
  # [classes] any "classes" to include, such as 'smaller', 'transition', etc.
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: showoff
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 3
10
- version: 0.3.3
9
+ - 4
10
+ version: 0.3.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Scott Chacon