slideshow-models 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
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,114 @@
1
+ # encoding: utf-8
2
+
3
+ module Slideshow
4
+ module SlideFilter
5
+
6
+
7
+ def takahashi_slide_breaks( content )
8
+
9
+ inline_count = 0
10
+ line_count = 0
11
+
12
+ ###########################
13
+ ## allows one // two // three
14
+
15
+ content.gsub!( /\b[ ]+\/{2}[ ]+\b/) do |match|
16
+ inline_count += 1
17
+ ## todo: use slide('') directive helper?
18
+ "\n\n<!-- _S9SLIDE_ -->\n\n"
19
+ end
20
+
21
+ ############################
22
+ ## allows
23
+ ##
24
+ ## one
25
+ ## //
26
+ ## two
27
+ ## //
28
+ ## three
29
+
30
+ content.gsub!( /^[ ]*\/{2}[ ]*$/ ) do |match|
31
+ line_count += 1
32
+ ## todo: use slide('') directive helper?
33
+ "\n\n<!-- _S9SLIDE_ -->\n\n"
34
+ end
35
+
36
+ puts " Adding #{inline_count+line_count} takahashi slide breaks (#{inline_count} //-inline, #{line_count} //-line)..."
37
+
38
+ content
39
+ end
40
+
41
+
42
+ # add slide directive before h1 (tells slideshow gem where to break slides)
43
+ #
44
+ # e.g. changes:
45
+ # <h1 id='optional' class='optional'>
46
+ # to
47
+ # html comment -> _S9SLIDE_ (note: rdoc can't handle html comments?)
48
+ # <h1 id='optional' class='optional'>
49
+
50
+ def add_slide_directive_before_h1( content )
51
+
52
+ # mark h1 for getting wrapped into slide divs
53
+ # note: use just <h1 since some processors add ids e.g. <h1 id='x'>
54
+
55
+ slide_count = 0
56
+
57
+ content.gsub!( /<h1/ ) do |match|
58
+ slide_count += 1
59
+ "\n<!-- _S9SLIDE_ -->\n#{Regexp.last_match(0)}"
60
+ end
61
+
62
+ puts " Adding #{slide_count} slide breaks (using h1 rule)..."
63
+
64
+ content
65
+ end
66
+
67
+ def add_slide_directive_before_h2( content )
68
+
69
+ slide_count = 0
70
+
71
+ content.gsub!( /<h2/ ) do |match|
72
+ slide_count += 1
73
+ "\n<!-- _S9SLIDE_ -->\n#{Regexp.last_match(0)}"
74
+ end
75
+
76
+ puts " Adding #{slide_count} slide breaks (using h2 rule)..."
77
+
78
+ content
79
+ end
80
+
81
+
82
+
83
+ # add slide directive before div h1 (for pandoc-generated html)
84
+ #
85
+ # e.g. changes:
86
+ # <div id='header'>
87
+ # <h1 id='optional' class='optional'>
88
+ # to
89
+ # html comment -> _S9SLIDE_
90
+ # <div id='header'>
91
+ # <h1 id='optional' class='optional'>
92
+
93
+
94
+ def add_slide_directive_before_div_h1( content )
95
+
96
+ slide_count = 0
97
+
98
+ content.gsub!( /<div[^>]*>\s*<h1/ ) do |match|
99
+ slide_count += 1
100
+ "\n<!-- _S9SLIDE_ -->\n#{Regexp.last_match(0)}"
101
+ end
102
+
103
+ puts " Adding #{slide_count} slide breaks (using div_h1 rule)..."
104
+
105
+ content
106
+ end
107
+
108
+
109
+ end # module SlideFilter
110
+ end # module Slideshow
111
+
112
+ class Slideshow::Gen
113
+ include Slideshow::SlideFilter
114
+ end
@@ -0,0 +1,140 @@
1
+ # encoding: utf-8
2
+
3
+ # builtin text filters
4
+ # called before text_to_html
5
+ #
6
+ # use web filters for processing html/hypertext
7
+
8
+ module Slideshow
9
+ module TextFilter
10
+
11
+ include TextUtils::Filter # include comments_percent_style, skip_end_directive, etc. filters
12
+
13
+ alias_method :old_comments_percent_style, :comments_percent_style
14
+
15
+ def comments_percent_style( content )
16
+
17
+ # skip filter for pandoc
18
+ # - pandoc uses % for its own markdown extension
19
+ return content if @markup_type == :markdown && Markdown.lib == 'pandoc-ruby'
20
+
21
+ old_comments_percent_style( content )
22
+ end
23
+
24
+ def directives_bang_style_to_percent_style( content )
25
+
26
+ # for compatibility allow !SLIDE/!STYLE as an alternative to %slide/%style-directive
27
+
28
+ bang_count = 0
29
+
30
+ # get unparsed helpers e.g. SLIDE|STYLE
31
+ unparsed = config.helper_unparsed.map { |item| item.upcase }.join( '|' )
32
+
33
+ content.gsub!(/^!(#{unparsed})(.*)$/) do |match|
34
+ bang_count += 1
35
+ "<%= #{$1.downcase} '#{$2 ? $2 : ''}' %>"
36
+ end
37
+
38
+ puts " Patching !-directives (#{bang_count} #{config.helper_unparsed.join('/')}-directives)..."
39
+
40
+ content
41
+ end
42
+
43
+ def directives_percent_style( content )
44
+
45
+ # skip filter for pandoc
46
+ # - pandoc uses % for its own markdown extension
47
+ # - don't process % pass it along/through to pandoc
48
+
49
+ return content if @markup_type == :markdown && Markdown.lib == 'pandoc-ruby'
50
+
51
+
52
+ directive_unparsed = 0
53
+ directive_expr = 0
54
+ directive_block_beg = 0
55
+ directive_block_end = 0
56
+
57
+ # process directives (plus skip %begin/%end comment-blocks)
58
+
59
+ inside_block = 0
60
+ inside_helper = false
61
+
62
+ content2 = ""
63
+
64
+ content.each_line do |line|
65
+ if line =~ /^%([a-zA-Z][a-zA-Z0-9_]*)(.*)/
66
+ directive = $1.downcase
67
+ params = $2
68
+
69
+ logger.debug "processing %-directive: #{directive}"
70
+
71
+ # slide, style
72
+ if config.helper_unparsed.include?( directive )
73
+ directive_unparsed += 1
74
+ content2 << "<%= #{directive} '#{params ? params : ''}' %>"
75
+ elsif config.helper_exprs.include?( directive )
76
+ directive_expr += 1
77
+ content2 << "<%= #{directive} #{params ? erb_simple_params(directive,params) : ''} %>"
78
+ elsif inside_helper && directive == 'end'
79
+ inside_helper = false
80
+ directive_block_end += 1
81
+ content2 << "%>"
82
+ elsif inside_block > 0 && directive == 'end'
83
+ inside_block -= 1
84
+ directive_block_end += 1
85
+ content2 << "<% end %>"
86
+ elsif [ 'comment', 'comments', 'begin', 'end' ].include?( directive ) # skip begin/end comment blocks
87
+ content2 << line
88
+ elsif [ 'helper', 'helpers' ].include?( directive )
89
+ inside_helper = true
90
+ directive_block_beg += 1
91
+ content2 << "<%"
92
+ else
93
+ inside_block += 1
94
+ directive_block_beg += 1
95
+ content2 << "<% #{directive} #{params ? erb_simple_params(directive,params) : ''} do %>"
96
+ end
97
+ else
98
+ content2 << line
99
+ end
100
+ end
101
+
102
+ puts " Preparing %-directives (" +
103
+ "#{directive_unparsed} #{config.helper_unparsed.join('/')} directives, " +
104
+ "#{directive_expr} #{config.helper_exprs.join('/')} expr-directives, " +
105
+ "#{directive_block_beg}/#{directive_block_end} block-directives)..."
106
+
107
+ content2
108
+ end
109
+
110
+ ######################
111
+ # todo: fix move to textutils gem (including helpers and config)
112
+ #
113
+
114
+
115
+ def erb_rename_helper_hack( content )
116
+ # note: include is a ruby keyword; rename to s9_include so we can use it
117
+
118
+ rename_counter = 0
119
+
120
+ # turn renames into something like:
121
+ # include|class etc.
122
+ renames = config.helper_renames.join( '|' )
123
+
124
+ content.gsub!( /<%=[ \t]*(#{renames})/ ) do |match|
125
+ rename_counter += 1
126
+ "<%= s9_#{$1}"
127
+ end
128
+
129
+ puts " Patching embedded Ruby (erb) code for aliases (#{rename_counter} #{config.helper_renames.join('/')}-aliases)..."
130
+
131
+ content
132
+ end
133
+
134
+
135
+ end # module TextFilter
136
+ end # module Slideshow
137
+
138
+ class Slideshow::Gen
139
+ include Slideshow::TextFilter
140
+ end
@@ -0,0 +1,89 @@
1
+ # encoding: utf-8
2
+
3
+ module Slideshow
4
+
5
+ class Headers
6
+
7
+ def initialize( config )
8
+ @hash = {}
9
+ @config = config
10
+ end
11
+
12
+ ## todo: rename put to store like std hash method
13
+ def put( key, value )
14
+ key = normalize_key( key )
15
+ setter = "#{key}=".to_sym
16
+
17
+ if respond_to?( setter )
18
+ send( setter, value )
19
+ else
20
+ @hash[ key ] = value
21
+ end
22
+ end
23
+
24
+ def gradient=( line )
25
+ # split into theme (first value) and colors (everything else)
26
+ # e.g. diagonal red black
27
+
28
+ # todo/check: translate value w/ v.tr( '-', '_' ) ??
29
+
30
+ values = line.split( ' ' )
31
+
32
+ put( 'gradient-theme', values.first ) if values.size > 0
33
+ put( 'gradient-colors', values[ 1..-1].join( ' ' ) ) if values.size > 1
34
+ end
35
+
36
+ def has_gradient?
37
+ # has user defined gradient (using headers)? (default values do NOT count)
38
+ @hash.has_key?( :gradient_theme ) || @hash.has_key?( :gradient_colors )
39
+ end
40
+
41
+ def []( key )
42
+ value = get( key )
43
+
44
+ if value.nil?
45
+ puts "** Warning: header '#{key}' undefined"
46
+ value = "- #{key} not found -"
47
+ end
48
+ value
49
+ end
50
+
51
+ def code_engine
52
+ get( 'code-engine' )
53
+ end
54
+
55
+ def code_txmt
56
+ get( 'code-txmt' )
57
+ end
58
+
59
+
60
+ ## todo: rename get to fetch??
61
+ def get( key, default=nil )
62
+ key = normalize_key(key)
63
+ value = @hash.fetch( key, nil )
64
+ value = @config.header( key ) if value.nil? # try lookup in config properties next
65
+ if value.nil?
66
+ default
67
+ else
68
+ value
69
+ end
70
+ end
71
+
72
+ def get_boolean( key, default )
73
+ value = get( key, default )
74
+ if value.nil?
75
+ default
76
+ else
77
+ (value == true || value =~ /t|true|yes|on/i) ? true : false
78
+ end
79
+ end
80
+
81
+ private
82
+
83
+ def normalize_key( key )
84
+ key.to_s.downcase.tr('-', '_').to_sym
85
+ end
86
+
87
+ end # class Headers
88
+
89
+ end # module Slideshow
@@ -0,0 +1,151 @@
1
+ # encoding: utf-8
2
+
3
+ module Slideshow
4
+ module BackgroundHelper
5
+
6
+ def gradient_from_headers( *args )
7
+
8
+ return "" unless headers.has_gradient? # do nothing if use hasn't set gradient headers (ignore defaults)
9
+
10
+ # lets you use headers (gradient, gradient-theme, gradient-colors)
11
+ # to define gradient (see http://slideshow.rubyforge.org/themes.html for predefined themes)
12
+
13
+ theme = headers[ :gradient_theme ]
14
+ colors = headers[ :gradient_colors ].split(' ') # colors as space separated all-in-one string
15
+
16
+ buf = ""
17
+
18
+ if theme == 'diagonal'
19
+ buf << "linear-gradient( top left, #{colors.join(', ')} )"
20
+ elsif theme == 'top-bottom'
21
+ buf << "linear-gradient( top, #{colors.join(', ')} )"
22
+ elsif theme == 'left-right'
23
+ buf << "linear-gradient( left, #{colors.join(', ')} )"
24
+ elsif theme == 'repeat'
25
+ buf << "repeating-linear-gradient( -60deg, #{colors.join(', ')} 10% )"
26
+ elsif theme == 'radial'
27
+ buf << "radial-gradient( #{colors.join(', ')} )"
28
+ elsif theme == 'radial-off-center'
29
+ buf << "radial-gradient( 70% 70%, ellipse, #{colors.join(', ')} )"
30
+ elsif theme == 'radial-repeat'
31
+ buf << "repeating-radial-gradient( 60% 60%, ellipse, #{colors.join(', ')} 10% )"
32
+ else
33
+ buf << "linear-gradient( #{colors.join(', ')} )"
34
+ puts "warning: unknown gradient themes #{theme} - falling back to default"
35
+ end
36
+
37
+ puts " Adding CSS for gradient background style rule using headers..."
38
+ puts " gradient-theme: #{theme}"
39
+ puts " gradient-colors: #{colors.join(' ')}"
40
+
41
+ content_for( :css, <<-EOS )
42
+ /****
43
+ * generated by gradient_from_headers helper; using headers:
44
+ * gradient-theme: #{theme}
45
+ * gradient-colors: #{colors.join(' ')}
46
+ */
47
+ .slide { background-image: -webkit-#{buf};
48
+ background-image: -moz-#{buf};
49
+ background-image: -ms-#{buf};
50
+ background-image: -o-#{buf};
51
+ background-image: #{buf};
52
+ }
53
+ EOS
54
+ end
55
+
56
+ def gradient( *args )
57
+
58
+ # check for optional hash for options
59
+ opts = args.last.kind_of?(Hash) ? args.pop : {}
60
+
61
+ colors = args
62
+
63
+ clazz = opts[:class] || ( 's9_gradient_linear_'+colors.join('_').gsub( /[(), ]/, '_' ).gsub( /_{2,}/, '_').gsub( /[^-\w]/, '' ) )
64
+
65
+
66
+ ## generate code
67
+
68
+ buf = "linear-gradient(top, #{colors.join(', ')} )"
69
+
70
+
71
+ puts " Adding CSS for background style rule..."
72
+ content_for( :css, <<-EOS )
73
+ .#{clazz} { background-image: -webkit-#{buf};
74
+ background-image: -moz-#{buf};
75
+ background-image: -ms-#{buf};
76
+ background-image: -o-#{buf};
77
+ background-image: #{buf};
78
+ }
79
+ EOS
80
+
81
+ # add processing instruction to get style class added to slide
82
+
83
+ puts " Adding HTML PI for background style class '#{clazz}'..."
84
+ "<!-- _S9STYLE_ #{clazz} -->\n"
85
+ end
86
+
87
+ def background( *args )
88
+
89
+ # make everyting optional; use it like:
90
+ # background( code, opts={} )
91
+
92
+ # check for optional hash for options
93
+ opts = args.last.kind_of?(Hash) ? args.pop : {}
94
+
95
+ # check for optional style rule code
96
+ code = args.last.kind_of?(String) ? args.pop : ''
97
+
98
+ clazz = opts[:class] || ( 's9'+code.strip.gsub( /[(), ]/, '_' ).gsub( /_{2,}/, '_').gsub( /[^-\w]/, '' ) )
99
+
100
+ # 1) add background rule to css
101
+ # e.g. .simple { background: -moz-linear-gradient(top, blue, white); }
102
+
103
+ unless code.empty?
104
+ puts " Adding CSS for background style rule..."
105
+ content_for( :css, <<-EOS )
106
+ .#{clazz} { background: #{code}; }
107
+ EOS
108
+ end
109
+
110
+ # 2) add processing instruction to get style class added to slide
111
+
112
+ puts " Adding HTML PI for background style class '#{clazz}'..."
113
+ "<!-- _S9STYLE_ #{clazz} -->\n"
114
+ end
115
+
116
+ def color( *args )
117
+
118
+ # make everyting optional; use it like:
119
+ # color( code, opts={} )
120
+
121
+ # check for optional hash for options
122
+ opts = args.last.kind_of?(Hash) ? args.pop : {}
123
+
124
+ # check for optional style rule code
125
+ code = args.last.kind_of?(String) ? args.pop : ''
126
+
127
+ clazz = opts[:class] || ( 's9'+code.strip.gsub( /[(), ]/, '_' ).gsub( /_{2,}/, '_').gsub( /[^-\w]/, '' ) )
128
+
129
+ # 1) add color rule to css
130
+ # e.g. .simple { color: #fff; }
131
+
132
+ unless code.empty?
133
+ puts " Adding CSS for color style rule..."
134
+ content_for( :css, <<-EOS )
135
+ .#{clazz} { color: #{code}; }
136
+ EOS
137
+ end
138
+
139
+ # 2) add processing instruction to get style class added to slide
140
+
141
+ puts " Adding HTML PI for color style class '#{clazz}'..."
142
+ "<!-- _S9STYLE_ #{clazz} -->\n"
143
+ end
144
+
145
+
146
+ end # module BackgroundHelper
147
+ end # module Slideshow
148
+
149
+ class Slideshow::Gen
150
+ include Slideshow::BackgroundHelper
151
+ end