slideshow 0.9.3 → 0.9.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.
- data/lib/slideshow.rb +1 -1
- data/lib/slideshow/config.rb +35 -6
- data/lib/slideshow/filters/slide_filter.rb +1 -0
- data/lib/slideshow/filters/text_filter.rb +1 -1
- data/lib/slideshow/gen.rb +99 -83
- data/lib/slideshow/markdown.rb +25 -1
- metadata +4 -4
data/lib/slideshow.rb
CHANGED
data/lib/slideshow/config.rb
CHANGED
@@ -28,8 +28,34 @@ class Config
|
|
28
28
|
|
29
29
|
# for now builtin has no erb processing; add builtin hash to main hash
|
30
30
|
@hash[ 'builtin' ] = YAML.load_file( config_builtin_file )
|
31
|
+
|
32
|
+
# todo/fix: merge config files
|
33
|
+
# check more locations
|
34
|
+
|
35
|
+
# check for user settings in working folder (check for slideshow.yml)
|
36
|
+
|
37
|
+
config_user_file = "./slideshow.yml"
|
38
|
+
if File.exists?( config_user_file )
|
39
|
+
puts "Loading settings from '#{config_user_file}'..."
|
40
|
+
@hash[ 'user' ] = YAML.load_file( config_user_file )
|
41
|
+
end
|
42
|
+
|
31
43
|
end
|
32
44
|
|
45
|
+
def markdown_to_html_method( lib )
|
46
|
+
method = @hash.fetch( 'user', {} ).fetch( lib, {} ).fetch( 'converter', nil )
|
47
|
+
|
48
|
+
# use default name
|
49
|
+
if method.nil?
|
50
|
+
method = "#{lib.downcase}_to_html"
|
51
|
+
end
|
52
|
+
|
53
|
+
method.tr('-','_').to_sym
|
54
|
+
end
|
55
|
+
|
56
|
+
def markdown_post_processing?( lib )
|
57
|
+
@hash.fetch( 'user', {} ).fetch( lib, {} ).fetch( 'post-processing', true )
|
58
|
+
end
|
33
59
|
|
34
60
|
def known_textile_extnames
|
35
61
|
# returns an array of known file extensions e.g.
|
@@ -39,18 +65,21 @@ class Config
|
|
39
65
|
# textile:
|
40
66
|
# extnames: [ .textile, .t ]
|
41
67
|
|
42
|
-
|
68
|
+
@hash[ 'textile' ][ 'extnames' ] + @hash[ 'builtin' ][ 'textile' ][ 'extnames' ]
|
43
69
|
end
|
44
70
|
|
45
71
|
def known_markdown_extnames
|
46
|
-
|
72
|
+
@hash[ 'markdown' ][ 'extnames' ] + @hash[ 'builtin' ][ 'markdown' ][ 'extnames' ]
|
47
73
|
end
|
48
74
|
|
49
75
|
def known_markdown_libs
|
50
76
|
# returns an array of known markdown engines e.g.
|
51
77
|
# [ pandoc-ruby, rdiscount, rpeg-markdown, maruku, bluecloth, kramdown ]
|
52
78
|
|
53
|
-
|
79
|
+
libs = @hash[ 'markdown' ][ 'libs' ] + @hash[ 'builtin' ][ 'markdown' ][ 'libs' ]
|
80
|
+
user_libs = @hash.fetch( 'user', {} ).fetch( 'markdown', {} ).fetch( 'libs', [] )
|
81
|
+
|
82
|
+
user_libs + libs
|
54
83
|
end
|
55
84
|
|
56
85
|
def known_extnames
|
@@ -61,11 +90,11 @@ class Config
|
|
61
90
|
end
|
62
91
|
|
63
92
|
def text_filters
|
64
|
-
@hash[ 'builtin' ][ 'filters' ] +
|
93
|
+
@hash[ 'builtin' ][ 'filters' ] + @hash[ 'filters' ]
|
65
94
|
end
|
66
95
|
|
67
96
|
def helper_renames
|
68
|
-
@hash[ 'builtin' ][ 'helper' ][ 'renames' ] +
|
97
|
+
@hash[ 'builtin' ][ 'helper' ][ 'renames' ] + @hash[ 'helper' ][ 'renames' ]
|
69
98
|
end
|
70
99
|
|
71
100
|
def helper_unparsed
|
@@ -76,7 +105,7 @@ class Config
|
|
76
105
|
def helper_exprs
|
77
106
|
# allow expression as directives (no need for %end block)
|
78
107
|
# by default directives are assumed statements (e.g. %mydir %end)
|
79
|
-
@hash[ 'builtin' ][ 'helper' ][ 'exprs' ] +
|
108
|
+
@hash[ 'builtin' ][ 'helper' ][ 'exprs' ] + @hash[ 'helper' ][ 'exprs' ]
|
80
109
|
end
|
81
110
|
|
82
111
|
def google_analytics_code
|
@@ -17,7 +17,7 @@ def directives_bang_style_to_percent_style( content )
|
|
17
17
|
|
18
18
|
content.gsub!(/^!(#{unparsed})(.*)$/) do |match|
|
19
19
|
bang_count += 1
|
20
|
-
"<%= #{$1.downcase} '#{$2}' %>"
|
20
|
+
"<%= #{$1.downcase} '#{$2 ? $2 : ''}' %>"
|
21
21
|
end
|
22
22
|
|
23
23
|
puts " Patching !-directives (#{bang_count} #{config.helper_unparsed.join('/')}-directives)..."
|
data/lib/slideshow/gen.rb
CHANGED
@@ -40,11 +40,12 @@ class Gen
|
|
40
40
|
def markdown_to_html( content )
|
41
41
|
# call markdown filter; turn markdown lib name into method_name (mn)
|
42
42
|
# eg. rpeg-markdown => rpeg_markdown_to_html
|
43
|
+
|
44
|
+
# lets you use differnt options/converters for a single markdown lib
|
45
|
+
mn = config.markdown_to_html_method( @markdown_libs.first )
|
46
|
+
|
47
|
+
puts " Converting Markdown-text (#{content.length} bytes) to HTML using library '#{@markdown_libs.first}' calling '#{mn}'..."
|
43
48
|
|
44
|
-
puts " Converting Markdown-text (#{content.length} bytes) to HTML using library '#{@markdown_libs.first}'..."
|
45
|
-
|
46
|
-
mn = @markdown_libs.first.downcase.tr( '-', '_' )
|
47
|
-
mn = "#{mn}_to_html".to_sym
|
48
49
|
send mn, content # call 1st configured markdown engine e.g. kramdown_to_html( content )
|
49
50
|
end
|
50
51
|
|
@@ -424,6 +425,93 @@ class Gen
|
|
424
425
|
end
|
425
426
|
end
|
426
427
|
|
428
|
+
# move into a filter??
|
429
|
+
def post_processing_slides( content )
|
430
|
+
|
431
|
+
# 1) add slide break
|
432
|
+
|
433
|
+
if @markup_type == :markdown && @markdown_libs.first == 'pandoc-ruby'
|
434
|
+
content = add_slide_directive_before_div_h1( content )
|
435
|
+
else
|
436
|
+
content = add_slide_directive_before_h1( content )
|
437
|
+
end
|
438
|
+
|
439
|
+
dump_content_to_file_debug_html( content )
|
440
|
+
|
441
|
+
# 2) use generic slide break processing instruction to
|
442
|
+
# split content into slides
|
443
|
+
|
444
|
+
slide_counter = 0
|
445
|
+
|
446
|
+
slides = []
|
447
|
+
slide_source = ""
|
448
|
+
|
449
|
+
content.each_line do |line|
|
450
|
+
if line.include?( '<!-- _S9SLIDE_' ) then
|
451
|
+
if slide_counter > 0 then # found start of new slide (and, thus, end of last slide)
|
452
|
+
slides << slide_source # add slide to slide stack
|
453
|
+
slide_source = "" # reset slide source buffer
|
454
|
+
end
|
455
|
+
slide_counter += 1
|
456
|
+
end
|
457
|
+
slide_source << line
|
458
|
+
end
|
459
|
+
|
460
|
+
if slide_counter > 0 then
|
461
|
+
slides << slide_source # add slide to slide stack
|
462
|
+
slide_source = "" # reset slide source buffer
|
463
|
+
end
|
464
|
+
|
465
|
+
## split slide source into header (optional) and content/body
|
466
|
+
## plus check for (css style) classes
|
467
|
+
|
468
|
+
slides2 = []
|
469
|
+
slides.each do |slide_source|
|
470
|
+
slide = Slide.new
|
471
|
+
|
472
|
+
## check for css style classes
|
473
|
+
from = 0
|
474
|
+
while (pos = slide_source.index( /<!-- _S9(SLIDE|STYLE)_(.*?)-->/m, from ))
|
475
|
+
logger.debug " adding css classes from pi #{$1.downcase}: #{$2.strip}"
|
476
|
+
|
477
|
+
if slide.classes.nil?
|
478
|
+
slide.classes = $2.strip
|
479
|
+
else
|
480
|
+
slide.classes << " #{$2.strip}"
|
481
|
+
end
|
482
|
+
|
483
|
+
from = Regexp.last_match.end(0)
|
484
|
+
end
|
485
|
+
|
486
|
+
# try to cut off header using non-greedy .+? pattern; tip test regex online at rubular.com
|
487
|
+
# note/fix: needs to get improved to also handle case for h1 wrapped into div
|
488
|
+
# (e.g. extract h1 - do not assume it starts slide source)
|
489
|
+
if slide_source =~ /^\s*(<h1.*?>.*?<\/h\d>)\s*(.*)/m
|
490
|
+
slide.header = $1
|
491
|
+
slide.content = ($2 ? $2 : "")
|
492
|
+
logger.debug " adding slide with header:\n#{slide.header}"
|
493
|
+
else
|
494
|
+
slide.content = slide_source
|
495
|
+
logger.debug " adding slide with *no* header:\n#{slide.content}"
|
496
|
+
end
|
497
|
+
slides2 << slide
|
498
|
+
end
|
499
|
+
|
500
|
+
# for convenience create a string w/ all in-one-html
|
501
|
+
# no need to wrap slides in divs etc.
|
502
|
+
|
503
|
+
content2 = ""
|
504
|
+
slides2.each do |slide|
|
505
|
+
content2 << slide.to_classic_html
|
506
|
+
end
|
507
|
+
|
508
|
+
# make content2 and slide2 available to erb template
|
509
|
+
# -- todo: cleanup variable names and use attr_readers for content and slide
|
510
|
+
|
511
|
+
@slides = slides2 # strutured content
|
512
|
+
@content = content2 # content all-in-one
|
513
|
+
end
|
514
|
+
|
427
515
|
|
428
516
|
def create_slideshow( fn )
|
429
517
|
|
@@ -524,89 +612,17 @@ class Gen
|
|
524
612
|
|
525
613
|
# post-processing
|
526
614
|
|
527
|
-
#
|
615
|
+
# make content2 and slide2 available to erb template
|
616
|
+
# -- todo: cleanup variable names and use attr_readers for content and slide
|
528
617
|
|
529
|
-
if @markup_type == :markdown && @markdown_libs.first ==
|
530
|
-
|
618
|
+
if @markup_type == :markdown && config.markdown_post_processing?( @markdown_libs.first ) == false
|
619
|
+
puts " Skipping post-processing (passing content through as is)..."
|
620
|
+
@content = content # content all-in-one - make it available in erb templates
|
531
621
|
else
|
532
|
-
content
|
622
|
+
# sets @content (all-in-one string) and @slides (structured content; split into slides)
|
623
|
+
post_processing_slides( content )
|
533
624
|
end
|
534
625
|
|
535
|
-
dump_content_to_file_debug_html( content )
|
536
|
-
|
537
|
-
# 2) use generic slide break processing instruction to
|
538
|
-
# split content into slides
|
539
|
-
|
540
|
-
slide_counter = 0
|
541
|
-
|
542
|
-
slides = []
|
543
|
-
slide_source = ""
|
544
|
-
|
545
|
-
content.each_line do |line|
|
546
|
-
if line.include?( '<!-- _S9SLIDE_' ) then
|
547
|
-
if slide_counter > 0 then # found start of new slide (and, thus, end of last slide)
|
548
|
-
slides << slide_source # add slide to slide stack
|
549
|
-
slide_source = "" # reset slide source buffer
|
550
|
-
end
|
551
|
-
slide_counter += 1
|
552
|
-
end
|
553
|
-
slide_source << line
|
554
|
-
end
|
555
|
-
|
556
|
-
if slide_counter > 0 then
|
557
|
-
slides << slide_source # add slide to slide stack
|
558
|
-
slide_source = "" # reset slide source buffer
|
559
|
-
end
|
560
|
-
|
561
|
-
## split slide source into header (optional) and content/body
|
562
|
-
## plus check for (css style) classes
|
563
|
-
|
564
|
-
slides2 = []
|
565
|
-
slides.each do |slide_source|
|
566
|
-
slide = Slide.new
|
567
|
-
|
568
|
-
## check for css style classes
|
569
|
-
from = 0
|
570
|
-
while (pos = slide_source.index( /<!-- _S9(SLIDE|STYLE)_(.*?)-->/m, from ))
|
571
|
-
logger.debug " adding css classes from pi #{$1.downcase}: #{$2.strip}"
|
572
|
-
|
573
|
-
if slide.classes.nil?
|
574
|
-
slide.classes = $2.strip
|
575
|
-
else
|
576
|
-
slide.classes << " #{$2.strip}"
|
577
|
-
end
|
578
|
-
|
579
|
-
from = Regexp.last_match.end(0)
|
580
|
-
end
|
581
|
-
|
582
|
-
# try to cut off header using non-greedy .+? pattern; tip test regex online at rubular.com
|
583
|
-
# note/fix: needs to get improved to also handle case for h1 wrapped into div
|
584
|
-
# (e.g. extract h1 - do not assume it starts slide source)
|
585
|
-
if slide_source =~ /^\s*(<h1.*?>.*?<\/h\d>)\s*(.*)/m
|
586
|
-
slide.header = $1
|
587
|
-
slide.content = ($2 ? $2 : "")
|
588
|
-
logger.debug " adding slide with header:\n#{slide.header}"
|
589
|
-
else
|
590
|
-
slide.content = slide_source
|
591
|
-
logger.debug " adding slide with *no* header:\n#{slide.content}"
|
592
|
-
end
|
593
|
-
slides2 << slide
|
594
|
-
end
|
595
|
-
|
596
|
-
# for convenience create a string w/ all in-one-html
|
597
|
-
# no need to wrap slides in divs etc.
|
598
|
-
|
599
|
-
content2 = ""
|
600
|
-
slides2.each do |slide|
|
601
|
-
content2 << slide.to_classic_html
|
602
|
-
end
|
603
|
-
|
604
|
-
# make content2 and slide2 available to erb template
|
605
|
-
# -- todo: cleanup variable names and use attr_readers for content and slide
|
606
|
-
|
607
|
-
@slides = slides2 # strutured content
|
608
|
-
@content = content2 # content all-in-one
|
609
|
-
|
610
626
|
|
611
627
|
manifest.each do |entry|
|
612
628
|
outname = entry[0]
|
data/lib/slideshow/markdown.rb
CHANGED
@@ -3,7 +3,31 @@ module Slideshow
|
|
3
3
|
|
4
4
|
def pandoc_ruby_to_html( content )
|
5
5
|
content = PandocRuby.new( content, :from => :markdown, :to => :html ).convert
|
6
|
-
|
6
|
+
end
|
7
|
+
|
8
|
+
def pandoc_ruby_to_html_incremental( content )
|
9
|
+
content = PandocRuby.new( content, :from => :markdown, :to => :html ).convert
|
10
|
+
content = content.gsub(/<(ul|ol)/) do |match|
|
11
|
+
"#{Regexp.last_match(0)} class='step'"
|
12
|
+
end
|
13
|
+
content
|
14
|
+
end
|
15
|
+
|
16
|
+
# sample how to use your own converter
|
17
|
+
# configure in slideshow.yml
|
18
|
+
# pandoc-ruby:
|
19
|
+
# converter: pandoc-ruby-to-s5
|
20
|
+
|
21
|
+
def pandoc_ruby_to_s5( content )
|
22
|
+
content = PandocRuby.new( content, {:from => :markdown, :to => :s5}, :smart ).convert
|
23
|
+
content = content.gsub(/class="incremental"/,'class="step"')
|
24
|
+
# content = content.to_a[13..-1].join # remove the layout div
|
25
|
+
end
|
26
|
+
|
27
|
+
def pandoc_ruby_to_s5_incremental( content )
|
28
|
+
content = PandocRuby.new( content, {:from => :markdown, :to => :s5 }, :incremental, :smart ).convert
|
29
|
+
content = content.gsub(/class="incremental"/,'class="step"')
|
30
|
+
# content = content.to_a[13..-1].join # remove the layout div
|
7
31
|
end
|
8
32
|
|
9
33
|
def rdiscount_to_html( content )
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slideshow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 51
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 4
|
10
|
+
version: 0.9.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gerald Bauer
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-14 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|