slideshow-models 2.4.0

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 (39) hide show
  1. checksums.yaml +7 -0
  2. data/HISTORY.md +171 -0
  3. data/Manifest.txt +37 -0
  4. data/README.md +23 -0
  5. data/Rakefile +37 -0
  6. data/config/slideshow.builtin.yml +8 -0
  7. data/config/slideshow.index.yml +69 -0
  8. data/config/slideshow.yml +76 -0
  9. data/lib/slideshow/commands/fetch.rb +123 -0
  10. data/lib/slideshow/commands/gen.rb +330 -0
  11. data/lib/slideshow/commands/list.rb +72 -0
  12. data/lib/slideshow/commands/plugins.rb +46 -0
  13. data/lib/slideshow/commands/quick.rb +88 -0
  14. data/lib/slideshow/config.rb +243 -0
  15. data/lib/slideshow/filters/debug_filter.rb +75 -0
  16. data/lib/slideshow/filters/headers_filter.rb +46 -0
  17. data/lib/slideshow/filters/slide_filter.rb +114 -0
  18. data/lib/slideshow/filters/text_filter.rb +140 -0
  19. data/lib/slideshow/headers.rb +89 -0
  20. data/lib/slideshow/helpers/background_helper.rb +151 -0
  21. data/lib/slideshow/helpers/capture_helper.rb +138 -0
  22. data/lib/slideshow/helpers/directive_helper.rb +45 -0
  23. data/lib/slideshow/helpers/markdown_helper.rb +20 -0
  24. data/lib/slideshow/helpers/source_helper.rb +41 -0
  25. data/lib/slideshow/helpers/step_helper.rb +35 -0
  26. data/lib/slideshow/helpers/syntax/coderay_helper.rb +86 -0
  27. data/lib/slideshow/helpers/syntax/sh_helper.rb +63 -0
  28. data/lib/slideshow/helpers/syntax/uv_helper.rb +92 -0
  29. data/lib/slideshow/helpers/text_helper.rb +132 -0
  30. data/lib/slideshow/manifest_helpers.rb +99 -0
  31. data/lib/slideshow/markup/markdown.rb +20 -0
  32. data/lib/slideshow/markup/mediawiki.rb +40 -0
  33. data/lib/slideshow/markup/rest.rb +19 -0
  34. data/lib/slideshow/markup/textile.rb +70 -0
  35. data/lib/slideshow/models.rb +98 -0
  36. data/lib/slideshow/plugin_helpers.rb +64 -0
  37. data/lib/slideshow/slide.rb +120 -0
  38. data/lib/slideshow/version.rb +28 -0
  39. metadata +197 -0
@@ -0,0 +1,330 @@
1
+ # encoding: utf-8
2
+
3
+ module Slideshow
4
+
5
+ ## fix:/todo: move generation code out of command into its own class
6
+ ## not residing/depending on cli
7
+
8
+ class Gen ## todo: rename command to build
9
+
10
+ include LogUtils::Logging
11
+
12
+ include ManifestHelper
13
+
14
+ ### fix: remove opts, use config (wrapped!!)
15
+
16
+ def initialize( opts, config, headers )
17
+ @opts = opts
18
+ @config = config
19
+ @headers = headers
20
+
21
+ ## todo: check if we need to use expand_path - Dir.pwd always absolute (check ~/user etc.)
22
+ @usrdir = File.expand_path( Dir.pwd ) # save original (current) working directory
23
+ end
24
+
25
+ attr_reader :usrdir # original working dir (user called slideshow from)
26
+ attr_reader :srcdir, :outdir, :pakdir # NB: "initalized" in create_slideshow
27
+
28
+
29
+ attr_reader :opts, :config, :headers
30
+ attr_reader :session # give helpers/plugins a session-like hash
31
+
32
+ attr_reader :markup_type # :textile, :markdown, :mediawiki, :rest
33
+
34
+ # uses configured markup processor (textile,markdown,rest,mediawiki) to generate html
35
+ def text_to_html( content )
36
+ content = case @markup_type
37
+ when :markdown
38
+ markdown_to_html( content )
39
+ when :textile
40
+ textile_to_html( content )
41
+ when :mediawiki
42
+ mediawiki_to_html( content )
43
+ when :rest
44
+ rest_to_html( content )
45
+ end
46
+ content
47
+ end
48
+
49
+ def guard_text( text )
50
+ # todo/fix 2: note for Textile we need to differentiate between blocks and inline
51
+ # thus, to avoid runs - use guard_block (add a leading newline to avoid getting include in block that goes before)
52
+
53
+ # todo/fix: remove wrap_markup; replace w/ guard_text
54
+ # why: text might be css, js, not just html
55
+
56
+ ## todo: add print depreciation warning
57
+
58
+ wrap_markup( text )
59
+ end
60
+
61
+ def guard_block( text )
62
+ if markup_type == :textile
63
+ # saveguard with notextile wrapper etc./no further processing needed
64
+ # note: add leading newlines to avoid block-runons
65
+ "\n\n<notextile>\n#{text}\n</notextile>\n"
66
+ elsif markup_type == :markdown
67
+ # wrap in newlines to avoid runons
68
+ "\n\n#{text}\n\n"
69
+ elsif markup_type == :mediawiki
70
+ "\n\n<nowiki>\n#{text}\n</nowiki>\n"
71
+ else
72
+ text
73
+ end
74
+ end
75
+
76
+ def guard_inline( text )
77
+ wrap_markup( text )
78
+ end
79
+
80
+
81
+ def wrap_markup( text )
82
+ if markup_type == :textile
83
+ # saveguard with notextile wrapper etc./no further processing needed
84
+ "<notextile>\n#{text}\n</notextile>"
85
+ else
86
+ text
87
+ end
88
+ end
89
+
90
+
91
+ # move into a filter??
92
+ def post_processing_slides( content )
93
+
94
+ # 1) add slide breaks
95
+
96
+ if config.slide? # only allow !SLIDE directives fo slide breaks?
97
+ # do nothing (no extra automagic slide breaks wanted)
98
+ else
99
+ if (@markup_type == :markdown && Markdown.lib == 'pandoc-ruby') || @markup_type == :rest
100
+ content = add_slide_directive_before_div_h1( content )
101
+ else
102
+ if config.header_level == 2
103
+ content = add_slide_directive_before_h2( content )
104
+ else # assume level 1
105
+ content = add_slide_directive_before_h1( content )
106
+ end
107
+ end
108
+ end
109
+
110
+
111
+ dump_content_to_file_debug_html( content )
112
+
113
+ # 2) use generic slide break processing instruction to
114
+ # split content into slides
115
+
116
+ slide_counter = 0
117
+
118
+ slides = []
119
+ slide_buf = ""
120
+
121
+ content.each_line do |line|
122
+ if line.include?( '<!-- _S9SLIDE_' )
123
+ if slide_counter > 0 # found start of new slide (and, thus, end of last slide)
124
+ slides << slide_buf # add slide to slide stack
125
+ slide_buf = "" # reset slide source buffer
126
+ else # slide_counter == 0
127
+ # check for first slide with missing leading SLIDE directive (possible/allowed in takahashi, for example)
128
+ ## remove html comments and whitspaces (still any content?)
129
+ ### more than just whitespace? assume its a slide
130
+ if slide_buf.gsub(/<!--.*?-->/m, '').gsub( /[\n\r\t ]/, '').length > 0
131
+ logger.debug "add slide with missing leading slide directive >#{slide_buf}< with slide_counter == 0"
132
+ slides << slide_buf
133
+ slide_buf = ""
134
+ else
135
+ logger.debug "skipping slide_buf >#{slide_buf}< with slide_counter == 0"
136
+ end
137
+ end
138
+ slide_counter += 1
139
+ end
140
+ slide_buf << line
141
+ end
142
+
143
+ if slide_counter > 0
144
+ slides << slide_buf # add slide to slide stack
145
+ slide_buf = "" # reset slide source buffer
146
+ end
147
+
148
+
149
+ slides2 = []
150
+ slides.each do |source|
151
+ slides2 << Slide.new( source, config )
152
+ end
153
+
154
+
155
+ puts "#{slides2.size} slides found:"
156
+
157
+ slides2.each_with_index do |slide,i|
158
+ print " [#{i+1}] "
159
+ if slide.header.present?
160
+ print slide.header
161
+ else
162
+ # remove html comments
163
+ print "-- no header -- | #{slide.content.gsub(/<!--.*?-->/m, '').gsub(/\n/,'$')[0..40]}"
164
+ end
165
+ puts
166
+ end
167
+
168
+
169
+ # make content2 and slide2 available to erb template
170
+ # -- todo: cleanup variable names and use attr_readers for content and slide
171
+
172
+ ### fix: use class SlideDeck or Deck?? for slides array?
173
+
174
+ content2 = ""
175
+ slides2.each do |slide|
176
+ content2 << slide.to_classic_html
177
+ end
178
+
179
+ @content = content2
180
+ @slides = slides2 # strutured content
181
+ end
182
+
183
+
184
+ def create_slideshow( fn )
185
+
186
+ manifest_path_or_name = opts.manifest
187
+
188
+ # add .txt file extension if missing (for convenience)
189
+ if manifest_path_or_name.downcase.ends_with?( '.txt' ) == false
190
+ manifest_path_or_name << '.txt'
191
+ end
192
+
193
+ logger.debug "manifest=#{manifest_path_or_name}"
194
+
195
+ # check if file exists (if yes use custom template package!) - allows you to override builtin package with same name
196
+ if File.exists?( manifest_path_or_name )
197
+ manifestsrc = manifest_path_or_name
198
+ else
199
+ # check for builtin manifests
200
+ manifests = installed_template_manifests
201
+ matches = manifests.select { |m| m[0] == manifest_path_or_name }
202
+
203
+ if matches.empty?
204
+ puts "*** error: unknown template manifest '#{manifest_path_or_name}'"
205
+ # todo: list installed manifests
206
+ exit 2
207
+ end
208
+
209
+ manifestsrc = matches[0][1]
210
+ end
211
+
212
+ ### todo: use File.expand_path( xx, relative_to ) always with second arg
213
+ ## do NOT default to cwd (because cwd will change!)
214
+
215
+ # Reference src with absolute path, because this can be used with different pwd
216
+ manifestsrc = File.expand_path( manifestsrc, usrdir )
217
+
218
+ # expand output path in current dir and make sure output path exists
219
+ @outdir = File.expand_path( opts.output_path, usrdir )
220
+ logger.debug "setting outdir to >#{outdir}<"
221
+ FileUtils.makedirs( outdir ) unless File.directory? outdir
222
+
223
+ dirname = File.dirname( fn )
224
+ basename = File.basename( fn, '.*' )
225
+ extname = File.extname( fn )
226
+ logger.debug "dirname=#{dirname}, basename=#{basename}, extname=#{extname}"
227
+
228
+ # change working dir to sourcefile dir
229
+ # todo: add a -c option to commandline? to let you set cwd?
230
+
231
+ @srcdir = File.expand_path( dirname, usrdir )
232
+ logger.debug "setting srcdir to >#{srcdir}<"
233
+
234
+ unless usrdir == srcdir
235
+ logger.debug "changing cwd to src - new >#{srcdir}<, old >#{Dir.pwd}<"
236
+ Dir.chdir srcdir
237
+ end
238
+
239
+ puts "Preparing slideshow '#{basename}'..."
240
+
241
+ if config.known_textile_extnames.include?( extname )
242
+ @markup_type = :textile
243
+ elsif config.known_rest_extnames.include?( extname )
244
+ @markup_type = :rest
245
+ elsif config.known_mediawiki_extnames.include?( extname )
246
+ @markup_type = :mediawiki
247
+ else # default/fallback use markdown
248
+ @markup_type = :markdown
249
+ end
250
+
251
+ # shared variables for templates (binding)
252
+ @content_for = {} # reset content_for hash
253
+
254
+ @name = basename
255
+ @extname = extname
256
+
257
+ @session = {} # reset session hash for plugins/helpers
258
+
259
+ inname = "#{basename}#{extname}"
260
+
261
+ logger.debug "inname=#{inname}"
262
+
263
+ content = File.read( inname )
264
+
265
+ # run text filters
266
+
267
+ config.text_filters.each do |filter|
268
+ mn = filter.tr( '-', '_' ).to_sym # construct method name (mn)
269
+ content = send( mn, content ) # call filter e.g. include_helper_hack( content )
270
+ end
271
+
272
+
273
+ if config.takahashi?
274
+ content = takahashi_slide_breaks( content )
275
+ end
276
+
277
+
278
+ # convert light-weight markup to hypertext
279
+
280
+ content = text_to_html( content )
281
+
282
+ # post-processing
283
+
284
+ # make content2 and slide2 available to erb template
285
+ # -- todo: cleanup variable names and use attr_readers for content and slide
286
+
287
+ if @markup_type == :markdown && config.markdown_post_processing?( Markdown.lib ) == false
288
+ puts " Skipping post-processing (passing content through as is)..."
289
+ @content = content # content all-in-one - make it available in erb templates
290
+ else
291
+ # sets @content (all-in-one string) and @slides (structured content; split into slides)
292
+ post_processing_slides( content )
293
+ end
294
+
295
+
296
+ #### pak merge
297
+ # nb: change cwd to template pak root
298
+
299
+ @pakdir = File.dirname( manifestsrc ) # template pak root - make availabe too in erb via binding
300
+ logger.debug " setting pakdir to >#{pakdir}<"
301
+
302
+ # todo/fix: change current work dir (cwd) in pakman gem itself
303
+ # for now lets do it here
304
+
305
+ logger.debug "changing cwd to pak - new >#{pakdir}<, old >#{Dir.pwd}<"
306
+ Dir.chdir( pakdir )
307
+
308
+
309
+ pakpath = outdir
310
+
311
+ logger.debug( "manifestsrc >#{manifestsrc}<, pakpath >#{pakpath}<" )
312
+
313
+ Pakman::Templater.new.merge_pak( manifestsrc, pakpath, binding, basename )
314
+
315
+ logger.debug "restoring cwd to src - new >#{srcdir}<, old >#{Dir.pwd}<"
316
+ Dir.chdir( srcdir )
317
+
318
+ ## pop/restore org (original) working folder/dir
319
+ unless usrdir == srcdir
320
+ logger.debug "restoring cwd to usr - new >#{usrdir}<, old >#{Dir.pwd}<"
321
+ Dir.chdir( usrdir )
322
+ end
323
+
324
+ puts "Done."
325
+ end # method create_slideshow
326
+
327
+
328
+ end # class Gen
329
+
330
+ end # class Slideshow
@@ -0,0 +1,72 @@
1
+ # encoding: utf-8
2
+
3
+ module Slideshow
4
+
5
+ class List
6
+
7
+ include LogUtils::Logging
8
+
9
+ include ManifestHelper
10
+
11
+ ### fix: remove opts, use config (wrapped!!)
12
+
13
+ def initialize( opts, config )
14
+ @opts = opts
15
+ @config = config
16
+ end
17
+
18
+ attr_reader :opts, :config
19
+
20
+ def run
21
+ home = Env.home
22
+ ## replace home w/ ~ (to make out more readable (shorter))
23
+ ## e.g. use gsub( home, '~' )
24
+
25
+ puts ''
26
+ puts 'Installed plugins in search path'
27
+
28
+ installed_plugin_manifest_patterns.each_with_index do |pattern,i|
29
+ puts " [#{i+1}] #{pattern.gsub(home,'~')}"
30
+ end
31
+ puts ' include:'
32
+
33
+ installed_plugin_manifests.each do |manifest|
34
+ pakname = manifest[0].gsub('.txt','').gsub('.plugin','')
35
+ manifestpath = manifest[1].gsub(home,'~')
36
+ puts "%16s (%s)" % [pakname,manifestpath]
37
+ end
38
+
39
+ puts ''
40
+ puts 'Installed quickstarter packs in search path'
41
+
42
+ installed_quick_manifest_patterns.each_with_index do |pattern,i|
43
+ puts " [#{i+1}] #{pattern.gsub(home,'~')}"
44
+ end
45
+ puts ' include:'
46
+
47
+ installed_quick_manifests.each do |manifest|
48
+ pakname = manifest[0].gsub('.txt','').gsub('.quick','')
49
+ manifestpath = manifest[1].gsub(home,'~')
50
+ puts "%16s (%s)" % [pakname,manifestpath]
51
+ end
52
+
53
+
54
+ puts ''
55
+ puts 'Installed template packs in search path'
56
+
57
+ installed_template_manifest_patterns.each_with_index do |pattern,i|
58
+ puts " [#{i+1}] #{pattern.gsub(home,'~')}"
59
+ end
60
+ puts ' include:'
61
+
62
+ installed_template_manifests.each do |manifest|
63
+ pakname = manifest[0].gsub('.txt','')
64
+ manifestpath = manifest[1].gsub(home,'~')
65
+ puts "%16s (%s)" % [pakname,manifestpath]
66
+ end
67
+
68
+ end
69
+
70
+ end # class List
71
+
72
+ end # class Slideshow
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+
3
+ module Slideshow
4
+
5
+ class Plugins
6
+
7
+ include LogUtils::Logging
8
+
9
+ include PluginHelper
10
+
11
+ ### fix: remove opts, use config (wrapped!!)
12
+
13
+ def initialize( opts, config )
14
+ @opts = opts
15
+ @config = config
16
+ end
17
+
18
+ attr_reader :opts, :config
19
+
20
+ def run
21
+ home = Env.home
22
+ ## replace home w/ ~ (to make out more readable (shorter))
23
+ ## e.g. use gsub( home, '~' )
24
+
25
+ puts ''
26
+ puts 'Plugin scripts on the load path'
27
+
28
+ find_plugin_patterns.each_with_index do |pattern,i|
29
+ puts " [#{i+1}] #{pattern.gsub(home,'~')}"
30
+ end
31
+ puts ' include:'
32
+
33
+ plugins = find_plugins
34
+ if plugins.empty?
35
+ puts " -- none --"
36
+ else
37
+ plugins.each do |plugin|
38
+ ## NB: use full_path - since Ruby 1.9.2 - ./ no longer included in load path for security
39
+ plugin_fullpath = File.expand_path( plugin )
40
+ puts " #{plugin.gsub(home,'~')} (#{plugin_fullpath})"
41
+ end
42
+ end
43
+ end
44
+
45
+ end # class Plugins
46
+ end # module Slideshow