mattmatt-showoff 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +280 -0
  3. data/Rakefile +15 -0
  4. data/bin/showoff +115 -0
  5. data/lib/princely.rb +84 -0
  6. data/lib/showoff.rb +346 -0
  7. data/lib/showoff_utils.rb +259 -0
  8. data/public/css/fg.menu.css +114 -0
  9. data/public/css/onepage.css +44 -0
  10. data/public/css/pdf.css +12 -0
  11. data/public/css/reset.css +53 -0
  12. data/public/css/sh_style.css +66 -0
  13. data/public/css/showoff.css +258 -0
  14. data/public/css/spinner_bar.gif +0 -0
  15. data/public/css/theme/images/ui-bg_diagonals-small_100_f0efea_40x40.png +0 -0
  16. data/public/css/theme/images/ui-bg_flat_35_f0f0f0_40x100.png +0 -0
  17. data/public/css/theme/images/ui-bg_glass_55_fcf0ba_1x400.png +0 -0
  18. data/public/css/theme/images/ui-bg_glow-ball_25_2e2e28_600x600.png +0 -0
  19. data/public/css/theme/images/ui-bg_highlight-soft_100_f0efea_1x100.png +0 -0
  20. data/public/css/theme/images/ui-bg_highlight-soft_25_327E04_1x100.png +0 -0
  21. data/public/css/theme/images/ui-bg_highlight-soft_25_5A9D1A_1x100.png +0 -0
  22. data/public/css/theme/images/ui-bg_highlight-soft_95_ffedad_1x100.png +0 -0
  23. data/public/css/theme/images/ui-bg_inset-soft_22_3b3b35_1x100.png +0 -0
  24. data/public/css/theme/images/ui-icons_808080_256x240.png +0 -0
  25. data/public/css/theme/images/ui-icons_8DC262_256x240.png +0 -0
  26. data/public/css/theme/images/ui-icons_cd0a0a_256x240.png +0 -0
  27. data/public/css/theme/images/ui-icons_e7e6e4_256x240.png +0 -0
  28. data/public/css/theme/images/ui-icons_eeeeee_256x240.png +0 -0
  29. data/public/css/theme/images/ui-icons_ffffff_256x240.png +0 -0
  30. data/public/css/theme/ui.accordion.css +9 -0
  31. data/public/css/theme/ui.all.css +2 -0
  32. data/public/css/theme/ui.base.css +9 -0
  33. data/public/css/theme/ui.core.css +37 -0
  34. data/public/css/theme/ui.datepicker.css +62 -0
  35. data/public/css/theme/ui.dialog.css +13 -0
  36. data/public/css/theme/ui.progressbar.css +4 -0
  37. data/public/css/theme/ui.resizable.css +13 -0
  38. data/public/css/theme/ui.slider.css +17 -0
  39. data/public/css/theme/ui.tabs.css +9 -0
  40. data/public/css/theme/ui.theme.css +245 -0
  41. data/public/favicon.ico +0 -0
  42. data/public/js/fg.menu.js +645 -0
  43. data/public/js/jTypeWriter.js +26 -0
  44. data/public/js/jquery-1.4.min.js +151 -0
  45. data/public/js/jquery-print.js +109 -0
  46. data/public/js/jquery.batchImageLoad.js +56 -0
  47. data/public/js/jquery.cookie.js +96 -0
  48. data/public/js/jquery.cycle.all.js +1284 -0
  49. data/public/js/jquery.doubletap-0.1.js +105 -0
  50. data/public/js/jquery.uuid.js +24 -0
  51. data/public/js/jquery.ws-0.3pre.js +201 -0
  52. data/public/js/onepage.js +5 -0
  53. data/public/js/sh_lang/sh_bison.min.js +1 -0
  54. data/public/js/sh_lang/sh_c.min.js +1 -0
  55. data/public/js/sh_lang/sh_caml.min.js +1 -0
  56. data/public/js/sh_lang/sh_changelog.min.js +1 -0
  57. data/public/js/sh_lang/sh_cpp.min.js +1 -0
  58. data/public/js/sh_lang/sh_csharp.min.js +1 -0
  59. data/public/js/sh_lang/sh_css.min.js +1 -0
  60. data/public/js/sh_lang/sh_desktop.min.js +1 -0
  61. data/public/js/sh_lang/sh_diff.min.js +1 -0
  62. data/public/js/sh_lang/sh_flex.min.js +1 -0
  63. data/public/js/sh_lang/sh_glsl.min.js +1 -0
  64. data/public/js/sh_lang/sh_haxe.min.js +1 -0
  65. data/public/js/sh_lang/sh_html.min.js +1 -0
  66. data/public/js/sh_lang/sh_java.min.js +1 -0
  67. data/public/js/sh_lang/sh_javascript.min.js +1 -0
  68. data/public/js/sh_lang/sh_javascript_dom.min.js +1 -0
  69. data/public/js/sh_lang/sh_latex.min.js +1 -0
  70. data/public/js/sh_lang/sh_ldap.min.js +1 -0
  71. data/public/js/sh_lang/sh_log.min.js +1 -0
  72. data/public/js/sh_lang/sh_lsm.min.js +1 -0
  73. data/public/js/sh_lang/sh_m4.min.js +1 -0
  74. data/public/js/sh_lang/sh_makefile.min.js +1 -0
  75. data/public/js/sh_lang/sh_oracle.min.js +1 -0
  76. data/public/js/sh_lang/sh_pascal.min.js +1 -0
  77. data/public/js/sh_lang/sh_perl.min.js +1 -0
  78. data/public/js/sh_lang/sh_php.min.js +1 -0
  79. data/public/js/sh_lang/sh_prolog.min.js +1 -0
  80. data/public/js/sh_lang/sh_properties.min.js +1 -0
  81. data/public/js/sh_lang/sh_python.min.js +1 -0
  82. data/public/js/sh_lang/sh_ruby.min.js +1 -0
  83. data/public/js/sh_lang/sh_scala.min.js +1 -0
  84. data/public/js/sh_lang/sh_sh.min.js +1 -0
  85. data/public/js/sh_lang/sh_slang.min.js +1 -0
  86. data/public/js/sh_lang/sh_sml.min.js +1 -0
  87. data/public/js/sh_lang/sh_spec.min.js +1 -0
  88. data/public/js/sh_lang/sh_sql.min.js +1 -0
  89. data/public/js/sh_lang/sh_tcl.min.js +1 -0
  90. data/public/js/sh_lang/sh_xml.min.js +1 -0
  91. data/public/js/sh_lang/sh_xorg.min.js +1 -0
  92. data/public/js/sh_main.min.js +4 -0
  93. data/public/js/showoff.js +441 -0
  94. data/views/index.erb +73 -0
  95. data/views/onepage.erb +36 -0
  96. metadata +198 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Scott Chacon
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,280 @@
1
+ = ShowOff Presentation Software
2
+
3
+ ShowOff is a Sinatra web app that reads simple configuration files for a
4
+ presentation. It is sort of like a Keynote web app engine - think S5 +
5
+ Slidedown. I am using it to do all my talks in 2010, because I have a deep
6
+ hatred in my heart for Keynote and yet it is by far the best in the field.
7
+
8
+ The idea is that you setup your markdown slide files in section subdirectories
9
+ and then startup the showoff server in that directory. It will read in your
10
+ showoff.json file for which sections go in which order and then will give
11
+ you a URL to present from.
12
+
13
+ It can:
14
+
15
+ * show simple text
16
+ * show images
17
+ * show syntax highlighted code
18
+ * bullets with incremental advancing
19
+ * re-enact command line interactions
20
+ * call up a menu of sections/slides at any time to jump around
21
+ * execute javascript or ruby live and display results
22
+ * do simple transitions (instant, fade, slide in)
23
+
24
+ It might will can:
25
+
26
+ * show a timer - elapsed / remaining
27
+ * perform simple animations of images moving between keyframes
28
+ * show syncronized, hidden notes on another browser (like an iphone)
29
+ * show audience questions / comments (twitter or direct)
30
+ * let audience members go back / catch up as you talk
31
+ * let audience members vote on sections (?)
32
+ * broadcast itself on Bonjour
33
+ * let audience members download slides, code samples or other supplementary material
34
+
35
+ Some of the nice things are that you can easily version control it, you
36
+ can easily move sections between presentations, and you can rearrange or
37
+ remove sections easily.
38
+
39
+ = Usage
40
+
41
+ ShowOff is meant to be run in a ShowOff formatted repository - that means that it has a showoff.json file and a number of sections (subdirectories) with markdown files for the slides you're presenting.
42
+
43
+ $ gem install showoff
44
+ $ git clone (showoff-repo)
45
+ $ cd (showoff-repo)
46
+ $ showoff serve
47
+
48
+ If you run 'showoff' in the ShowOff directory itself, it will show an example
49
+ presentation from the 'example' subdirectory, so you can see what it's like.
50
+
51
+ = Slide Format
52
+
53
+ You can break your slides up into sections of however many subdirectories deep
54
+ you need. ShowOff will recursively check all the directories mentioned in
55
+ your showoff.json file for any markdown files (.md). Each markdown file can
56
+ have any number of slides in it, seperating each slide with the '!SLIDE'
57
+ keyword and optional slide styles.
58
+
59
+ For example, if you run 'showoff create my_new_pres' it will create a new
60
+ starter presentation for you with one .md file at one/slide.md which will have
61
+ the following contents:
62
+
63
+ !SLIDE
64
+
65
+ # My Presentation #
66
+
67
+ !SLIDE bullets incremental transition=fade
68
+
69
+ # Bullet Points #
70
+
71
+ * first point
72
+ * second point
73
+ * third point
74
+
75
+ That represents two slides, the first contains just a large title, and the
76
+ second is faded into view showing the title and three bullets that are then
77
+ incrementally shown. In order for ShowOff to see those slides, your
78
+ showoff.json file needs to look something like this:
79
+
80
+ [
81
+ {"section":"one"}
82
+ ]
83
+
84
+ If you have multiple sections in your talk, you can make this json array
85
+ include all the sections you want to show in which order you want to show
86
+ them.
87
+
88
+ Some useful styles for each slide are:
89
+
90
+ * center - centers images on a slide
91
+ * full-page - allows an image to take up the whole slide
92
+ * bullets - sizes and seperates bullets properly (fits up to 5, generally)
93
+ * smbullets - sizes and seperates more bullets (smaller, closer together)
94
+ * subsection - creates a different background for titles
95
+ * command - monospaces h1 title slides
96
+ * commandline - for pasted commandline sections (needs leading '$' for commands, then output on subsequent lines)
97
+ * code - monospaces everything on the slide
98
+ * incremental - can be used with 'bullets' and 'commandline' styles, will incrementally update elements on arrow key rather than switch slides
99
+ * small - make all slide text 80%
100
+ * smaller - make all slide text 70%
101
+ * execute - on js highlighted code slides, you can click on the code to execute it and display the results on the slide
102
+
103
+ Check out the example directory included to see examples of most of these.
104
+
105
+ Transitions can be supplied through the use of transition=tname on the !SLIDE
106
+ definition, where tname is one of the following supported transitions:
107
+
108
+ * blindX
109
+ * blindY
110
+ * blindZ
111
+ * cover
112
+ * curtainX
113
+ * curtainY
114
+ * fade
115
+ * fadeZoom
116
+ * growX
117
+ * growY
118
+ * none (this is the default)
119
+ * scrollUp
120
+ * scrollDown
121
+ * scrollLeft
122
+ * scrollRight
123
+ * scrollHorz
124
+ * scrollVert
125
+ * shuffle
126
+ * slideX
127
+ * slideY
128
+ * toss
129
+ * turnUp
130
+ * turnDown
131
+ * turnLeft
132
+ * turnRight
133
+ * uncover
134
+ * wipe
135
+ * zoom
136
+
137
+ The transitions are provided by jQuery Cycle plugin. See http://www.malsup.com/jquery/cycle/browser.html to view the effects and http://www.malsup.com/jquery/cycle/adv2.html for how to add custom effects.
138
+
139
+ You can manage the presentation with the following keys:
140
+
141
+ * space, cursor right: next slide
142
+ * cursor left: previous slide
143
+ * d: debug mode
144
+ * c: table of contents (vi)
145
+ * f: toggle footer
146
+ * z: toggle help
147
+
148
+ = Editor integration
149
+
150
+ The "add slide" feature can allow you to add the necessary boilerplate from your editor. If you are using vim, you can
151
+
152
+ !showoff add -t code Check This Code
153
+
154
+ And your buffer will get
155
+
156
+ !SLIDE
157
+ # Check This Code #
158
+ @@@ Ruby
159
+ code_here()
160
+
161
+ added where your cursor was. Binding this to a keybinding can allow you to add new slides quickly.
162
+
163
+ = Command Line Interface
164
+
165
+ showoff command_name [command-specific options] [--] arguments...
166
+
167
+ * Use the command +help+ to get a summary of commands
168
+ * Use the command <tt>help command_name</tt> to get a help for +command_name+
169
+ * Use <tt>--</tt> to stop command line argument processing; useful if your arguments have dashes in them
170
+
171
+ == Commands
172
+ [<tt>add</tt>] Add a new slide at the end in a given dir
173
+ [<tt>create</tt>] Create new showoff presentation
174
+ [<tt>help</tt>] Shows list of commands or help for one command
175
+ [<tt>heroku</tt>] Setup your presentation to serve on Heroku
176
+ [<tt>serve</tt>] Serves the showoff presentation in the current directory
177
+
178
+ === <tt>add [title]</tt>
179
+
180
+ Add a new slide at the end in a given dir
181
+
182
+ *Aliases*
183
+ * <tt><b>new</b></tt>
184
+
185
+ Outputs or creates a new slide. With -d and -n, a new slide is created in the given dir, numbered to appear as the last slide in that dir (use -u to avoid numbering). Without those, outputs the slide markdown to stdout (useful for shelling out from your editor). You may also specify a source file to use for a code slide
186
+
187
+ ==== Options
188
+ These options are specified *after* the command.
189
+
190
+ [<tt>-d, --dir=dir</tt>] Slide dir (where to put a new slide file)
191
+ [<tt>-n, --name=basename</tt>] Slide name (name of the new slide file)
192
+ [<tt>-s, --source=path to file</tt>] Include code from the given file as the slide body
193
+ [<tt>-t, --style, --type=valid showoff style/type</tt>] Slide Type/Style <i>( default: <tt>title</tt>)</i>
194
+ [<tt>-u, --nonumber</tt>] Dont number the slide, use the given name verbatim
195
+ === <tt>create dir_name</tt>
196
+
197
+ Create new showoff presentation
198
+
199
+ *Aliases*
200
+ * <tt><b>init</b></tt>
201
+
202
+ 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.
203
+
204
+ ==== Options
205
+ These options are specified *after* the command.
206
+
207
+ [<tt>-d, --slidedir=arg</tt>] sample slide directory name <i>( default: <tt>one</tt>)</i>
208
+ [<tt>-n, --nosamples</tt>] Dont create sample slides
209
+ === <tt>help [command]</tt>
210
+
211
+ Shows list of commands or help for one command
212
+
213
+ === <tt>heroku heroku_name</tt>
214
+
215
+ Setup your presentation to serve on Heroku
216
+
217
+ === <tt>serve </tt>
218
+
219
+ Serves the showoff presentation in the current directory
220
+
221
+
222
+
223
+ ==== Options
224
+ These options are specified *after* the command.
225
+
226
+ [<tt>-p, --port=arg</tt>] Port on which to run <i>( default: <tt>9090</tt>)</i>
227
+ = Real World Usage
228
+
229
+ So far, ShowOff has been used in the following presentations:
230
+
231
+ * LinuxConf.au 2010 - Wrangling Git - Scott Chacon
232
+ http://github.com/schacon/showoff-wrangling-git
233
+ * SF Ruby Meetup - Resque! - Chris Wanstrath
234
+ http://github.com/defunkt/sfruby-meetup-resque
235
+ * RORO Sydney Talk, Feb 2010 - Beyond Actions - Dave Bolton
236
+ http://github.com/lightningdb/roro-syd-beyond-actions
237
+ * LRUG's February meeting - Showing Off with Ruby - Joel Chippindale
238
+ http://github.com/mocoso/showing-off-with-ruby
239
+ * PyCon 2010 - Hg and Git; Can't we all just get along? - Scott Chacon
240
+ http://github.com/schacon/pycon-hg-git
241
+ * PdxJs Tech Talk - Asynchronous Coding For My Tiny Ruby Brain - Rick Olson
242
+ http://github.com/technoweenie/pdxjs-twitter-node
243
+ * RORO Perth Talk - Rails 3; A Brief Introduction Darcy Laycock
244
+ http://github.com/Sutto/roro-perth-rails-3
245
+ * PDXRB Tech Talk - Here's Sinatra - Jesse Cooke
246
+ http://github.com/jc00ke/pdxrb_sinatra
247
+
248
+ If you use it for something, please let me know so I can add it.
249
+
250
+ = Future Plans
251
+
252
+ I really want this to evolve into a dynamic presentation software server,
253
+ that gives the audience a lot of interaction into the presentation -
254
+ helping them decide dynamically what the content of the presentation is,
255
+ ask questions without interupting the presenter, etc. I want the audience
256
+ to be able to download a dynamically generated PDF of either the actual
257
+ talk that was given, or all the available slides, plus supplementary
258
+ material. And I want the presenter (me) to be able to push each
259
+ presentation to Heroku or GitHub pages for archiving super easily.
260
+
261
+ = Why Not S5 or Slidy or Slidedown?
262
+
263
+ S5 and Slidy are really cool, and I was going to use them, but mainly I wanted
264
+ something more dynamic. I wanted Slidy + Slidedown, where I could write my
265
+ slideshows in a structured format in sections, where the sections could easily
266
+ be moved around and between presentations and could be written in Markdown. I
267
+ also like the idea of having interactive presentation system and didn't need
268
+ half the features of S5/Slidy (style based print view, auto-scaling, themes,
269
+ etc).
270
+
271
+ = Requirements
272
+
273
+ * Ruby (duh)
274
+ * Sinatra (and thus Rack)
275
+ * BlueCloth
276
+ * Nokogiri
277
+ * json
278
+ * GLI gem
279
+ * Firefox or Chrome to present
280
+
@@ -0,0 +1,15 @@
1
+ begin
2
+ require 'mg'
3
+ rescue LoadError
4
+ abort "Please `gem install mg`"
5
+ end
6
+
7
+ class MG
8
+ # Monkey patch until http://github.com/defunkt/mg/commit/no_safe_level
9
+ # is merged and released upstream.
10
+ def spec
11
+ @spec ||= eval(File.read(gemspec))
12
+ end
13
+ end
14
+
15
+ MG.new("showoff.gemspec")
@@ -0,0 +1,115 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
+ require 'showoff'
5
+ require 'rubygems'
6
+ require 'gli'
7
+
8
+ include GLI
9
+
10
+ desc 'Create new showoff presentation'
11
+ arg_name 'dir_name'
12
+ 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.'
13
+ command [:create,:init] do |c|
14
+
15
+ c.desc 'Don''t create sample slides'
16
+ c.switch [:n,:nosamples]
17
+
18
+ c.desc 'sample slide directory name'
19
+ c.default_value 'one'
20
+ c.flag [:d,:slidedir]
21
+
22
+ c.action do |global_options,options,args|
23
+ raise "dir_name is required" if args.empty?
24
+ ShowOffUtils.create(args[0],!options[:n],options[:d])
25
+ end
26
+ end
27
+
28
+ desc 'Setup your presentation to serve on Heroku'
29
+ arg_name 'heroku_name'
30
+ long_desc 'Creates the .gems file 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.'
31
+ command :heroku do |c|
32
+ c.action do |global_options,options,args|
33
+ raise "heroku_name is required" if args.empty?
34
+ ShowOffUtils.heroku(args[0])
35
+ end
36
+ end
37
+
38
+ desc 'Serves the showoff presentation in the current directory'
39
+ command :serve do |c|
40
+
41
+ c.desc 'Port on which to run'
42
+ c.default_value "9090"
43
+ c.flag [:p,:port]
44
+
45
+ c.desc 'Host or ip to run on'
46
+ c.default_value "localhost"
47
+ c.flag [:h,:host]
48
+
49
+ c.action do |global_options,options,args|
50
+ ShowOff.run! :host => options[:h], :port => options[:p].to_i
51
+ end
52
+ end
53
+
54
+ desc 'Add a new slide at the end in a given dir'
55
+ arg_name '[title]'
56
+ long_desc 'Outputs or creates a new slide. With -d and -n, a new slide is created in the given dir, numbered to appear as the last slide in that dir (use -u to avoid numbering). Without those, outputs the slide markdown to stdout (useful for shelling out from your editor). You may also specify a source file to use for a code slide'
57
+ command [:add,:new] do |c|
58
+ c.desc 'Don''t number the slide, use the given name verbatim'
59
+ c.switch [:u,:nonumber]
60
+
61
+ c.desc 'Include code from the given file as the slide body'
62
+ c.arg_name 'path to file'
63
+ c.flag [:s,:source]
64
+
65
+ c.desc 'Slide Type/Style'
66
+ c.arg_name 'valid showoff style/type'
67
+ c.default_value 'title'
68
+ c.flag [:t,:type,:style]
69
+
70
+ c.desc 'Slide dir (where to put a new slide file)'
71
+ c.arg_name 'dir'
72
+ c.flag [:d,:dir]
73
+
74
+ c.desc 'Slide name (name of the new slide file)'
75
+ c.arg_name 'basename'
76
+ c.flag [:n,:name]
77
+
78
+ c.action do |global_options,options,args|
79
+ title = args.join(" ")
80
+ ShowOffUtils.add_slide(:dir => options[:d],
81
+ :name => options[:n],
82
+ :title => title,
83
+ :number => !options[:m],
84
+ :code => options[:s],
85
+ :type => options[:t])
86
+ end
87
+ end
88
+
89
+ desc 'Generate static version of presentation'
90
+ arg_name 'name'
91
+ long_desc 'Creates a static, one page version of the presentation as {name}.html'
92
+ command [:static] do |c|
93
+ c.action do |global_options,options,args|
94
+ ShowOff.do_static(args[0])
95
+ end
96
+ end
97
+
98
+ pre do |global,command,options,args|
99
+ # Pre logic here
100
+ # Return true to proceed; false to abourt and not call the
101
+ # chosen command
102
+ true
103
+ end
104
+
105
+ post do |global,command,options,args|
106
+ # Post logic here
107
+ end
108
+
109
+ on_error do |exception|
110
+ # Error logic here
111
+ # return false to skip default error handling
112
+ true
113
+ end
114
+
115
+ GLI.run(ARGV)
@@ -0,0 +1,84 @@
1
+ # PrinceXML Ruby interface.
2
+ # http://www.princexml.com
3
+ #
4
+ # Library by Subimage Interactive - http://www.subimage.com
5
+ #
6
+ #
7
+ # USAGE
8
+ # -----------------------------------------------------------------------------
9
+ # princely = Princely.new()
10
+ # html_string = render_to_string(:template => 'some_document')
11
+ # send_data(
12
+ # princely.pdf_from_string(html_string),
13
+ # :filename => 'some_document.pdf'
14
+ # :type => 'application/pdf'
15
+ # )
16
+ #
17
+ $:.unshift(File.dirname(__FILE__))
18
+
19
+ class Princely
20
+ VERSION = "1.0.0" unless const_defined?("VERSION")
21
+
22
+ attr_accessor :exe_path, :style_sheets, :log_file
23
+
24
+ # Initialize method
25
+ #
26
+ def initialize()
27
+ # Finds where the application lives, so we can call it.
28
+ @exe_path = `which prince`.chomp
29
+ raise "Cannot find prince command-line app in $PATH" if @exe_path.length == 0
30
+ @style_sheets = ''
31
+ @log_file = "/tmp/prince.log"
32
+ end
33
+
34
+ # Sets stylesheets...
35
+ # Can pass in multiple paths for css files.
36
+ #
37
+ def add_style_sheets(*sheets)
38
+ for sheet in sheets do
39
+ @style_sheets << " -s #{sheet} "
40
+ end
41
+ end
42
+
43
+ # Returns fully formed executable path with any command line switches
44
+ # we've set based on our variables.
45
+ #
46
+ def exe_path
47
+ # Add any standard cmd line arguments we need to pass
48
+ @exe_path << " --input=html --server --log=#{@log_file} "
49
+ @exe_path << @style_sheets
50
+ return @exe_path
51
+ end
52
+
53
+ # Makes a pdf from a passed in string.
54
+ #
55
+ # Returns PDF as a stream, so we can use send_data to shoot
56
+ # it down the pipe using Rails.
57
+ #
58
+ def pdf_from_string(string, output_file = '-')
59
+ path = self.exe_path()
60
+ # Don't spew errors to the standard out...and set up to take IO
61
+ # as input and output
62
+ path << ' --silent - -o -'
63
+
64
+ # Actually call the prince command, and pass the entire data stream back.
65
+ pdf = IO.popen(path, "w+")
66
+ pdf.puts(string)
67
+ pdf.close_write
68
+ result = pdf.gets(nil)
69
+ pdf.close_read
70
+ return result
71
+ end
72
+
73
+ def pdf_from_string_to_file(string, output_file)
74
+ path = self.exe_path()
75
+ # Don't spew errors to the standard out...and set up to take IO
76
+ # as input and output
77
+ path << " --silent - -o '#{output_file}' >> '#{@log_file}' 2>> '#{@log_file}'"
78
+
79
+ # Actually call the prince command, and pass the entire data stream back.
80
+ pdf = IO.popen(path, "w+")
81
+ pdf.puts(string)
82
+ pdf.close
83
+ end
84
+ end