slideshow 0.3.1 → 0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/slideshow.rb +105 -8
  2. metadata +20 -2
data/lib/slideshow.rb CHANGED
@@ -3,6 +3,9 @@ require 'erb'
3
3
  require 'redcloth'
4
4
  require 'maruku'
5
5
  require 'logger'
6
+ require 'fileutils'
7
+ require 'hpricot'
8
+ require 'uv'
6
9
 
7
10
 
8
11
  module Slideshow
@@ -21,6 +24,20 @@ class Params
21
24
 
22
25
  end
23
26
 
27
+ def Slideshow.cache_dir
28
+ PLATFORM =~ /win32/ ? win32_cache_dir : File.join(File.expand_path("~"), ".slideshow")
29
+ end
30
+
31
+ def Slideshow.win32_cache_dir
32
+ unless File.exists?(home = ENV['HOMEDRIVE'] + ENV['HOMEPATH'])
33
+ puts "No HOMEDRIVE or HOMEPATH environment variable. Set one to save a" +
34
+ "local cache of stylesheets for syntax highlighting and more."
35
+ return false
36
+ else
37
+ return File.join(home, 'slideshow')
38
+ end
39
+ end
40
+
24
41
  def Slideshow.load_template( name )
25
42
 
26
43
  templatesdir = "#{File.dirname(__FILE__)}/templates"
@@ -69,13 +86,29 @@ def Slideshow.create_slideshow( fn )
69
86
  cssname = "#{basename}.css"
70
87
 
71
88
  logger.debug "inname=#{inname}"
89
+
90
+ content = File.read( inname )
91
+
92
+ # read source document
93
+ # strip leading optional headers (key/value pairs) including optional empty lines
72
94
 
73
- puts "Preparing slideshow stylesheet '#{cssname}'..."
95
+ read_headers = true
96
+ content = ""
74
97
 
75
- out = File.new( cssname, "w+" )
76
- out << render_template( styledoc, params.params_binding )
77
- out.flush
78
- out.close
98
+ File.open( inname ).readlines.each do |line|
99
+ if read_headers && line =~ /^\s*(\w[\w-]*)[ \t]*:[ \t]*(.*)/
100
+ key = $1.downcase
101
+ value = $2.strip
102
+
103
+ logger.debug " adding option: key=>#{key}< value=>#{value}<"
104
+ store_option( key, value )
105
+ elsif line =~ /^\s*$/
106
+ content << line unless read_headers
107
+ else
108
+ read_headers =false
109
+ content << line
110
+ end
111
+ end
79
112
 
80
113
  puts "Preparing slideshow theme '#{svgname}'..."
81
114
 
@@ -87,8 +120,6 @@ def Slideshow.create_slideshow( fn )
87
120
  puts "Preparing slideshow '#{outname}'..."
88
121
 
89
122
  # convert light-weight markup to hypertext
90
-
91
- content = File.read( inname )
92
123
 
93
124
  if known_markdown_extnames.include?( extname )
94
125
  content = Maruku.new( content, {:on_error => :raise} ).to_html
@@ -114,6 +145,24 @@ def Slideshow.create_slideshow( fn )
114
145
  }
115
146
  content2 << "\n\n</div>" if slide_counter > 0
116
147
 
148
+ include_code_stylesheet = false
149
+ # syntax highlight code
150
+ # todo: can the code handle escaped entities? e.g. &gt;
151
+ doc = Hpricot(content2)
152
+ doc.search("pre.code, pre > code").each do |e|
153
+ if e.inner_html =~ /^\s*#!(\w+)/
154
+ lang = $1.downcase
155
+ logger.debug " lang=#{lang}"
156
+ if Uv.syntaxes.include?(lang)
157
+ e.inner_html = Uv.parse( e.inner_html.sub(/^\s*#!\w+/, '').strip, "xhtml", lang, get_boolean_option( 'code-line-numbers', true ), get_option( 'code-theme', 'amy' ))
158
+ include_code_stylesheet = true
159
+ end
160
+ end
161
+ end
162
+
163
+ content2 = doc.to_s
164
+
165
+
117
166
  out = File.new( outname, "w+" )
118
167
  out << render_template( headerdoc, params.params_binding )
119
168
  out << content2
@@ -121,6 +170,30 @@ def Slideshow.create_slideshow( fn )
121
170
  out.flush
122
171
  out.close
123
172
 
173
+ puts "Preparing slideshow stylesheet '#{cssname}'..."
174
+
175
+ out = File.new( cssname, "w+" )
176
+ out << render_template( styledoc, params.params_binding )
177
+
178
+ if include_code_stylesheet
179
+ logger.debug "cache_dir=#{cache_dir}"
180
+
181
+ FileUtils.mkdir(cache_dir) unless File.exists?(cache_dir) if cache_dir
182
+ Uv.copy_files "xhtml", cache_dir
183
+
184
+ theme = get_option( 'code-theme', 'amy' )
185
+
186
+ theme_content = File.read( "#{cache_dir}/css/#{theme}.css" )
187
+
188
+ out << "/* styles for code syntax highlighting theme '#{theme}' */\n"
189
+ out << "\n"
190
+ out << theme_content
191
+ end
192
+
193
+ out.flush
194
+ out.close
195
+
196
+
124
197
  puts "Done."
125
198
  end
126
199
 
@@ -131,6 +204,30 @@ def Slideshow.logger
131
204
  @@logger
132
205
  end
133
206
 
207
+
208
+
209
+ def Slideshow.store_option( key, value )
210
+ $options[ key ] = value
211
+ end
212
+
213
+ def Slideshow.get_option( key, default )
214
+ value = $options[ key ]
215
+ value.nil? ? default : value
216
+ end
217
+
218
+ def Slideshow.get_boolean_option( key, default )
219
+ value = $options[ key ]
220
+ if value.nil?
221
+ default
222
+ else
223
+ if( value.downcase == 'true' || value.downcase == 'yes' || value.downcase == 'on' )
224
+ true
225
+ else
226
+ false
227
+ end
228
+ end
229
+ end
230
+
134
231
  def Slideshow.main
135
232
 
136
233
  @@logger = nil
@@ -164,7 +261,7 @@ def Slideshow.main
164
261
 
165
262
  opt.parse!
166
263
 
167
- puts "Slide Show (S9) Version: 0.3.1 on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
264
+ puts "Slide Show (S9) Version: 0.4 on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
168
265
 
169
266
  ARGV.each { |fn| Slideshow.create_slideshow( fn ) }
170
267
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slideshow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: "0.4"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-16 00:00:00 -07:00
12
+ date: 2008-05-17 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,6 +30,24 @@ dependencies:
30
30
  - !ruby/object:Gem::Version
31
31
  version: 0.5.8
32
32
  version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: hpricot
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: "0.6"
41
+ version:
42
+ - !ruby/object:Gem::Dependency
43
+ name: ultraviolet
44
+ version_requirement:
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.10.2
50
+ version:
33
51
  description:
34
52
  email: geraldbauer2007@gmail.com
35
53
  executables: