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,138 @@
1
+ # encoding: utf-8
2
+
3
+ # Originally based on code from Rails and Merb; adapted from Webby.
4
+
5
+ module Slideshow
6
+ module CaptureHelper
7
+
8
+ # Called in pages and partials to store up content for later use. Takes a
9
+ # string and/or a block. First, the string is evaluated, and then the
10
+ # block is captured using the capture() helper provided by the template
11
+ # languages. The two are concatenated together.
12
+ #
13
+ # Content is retrieved by calling the method without a string or a block.
14
+ #
15
+ # ==== Parameters
16
+ # obj<Object>:: The key in the content_for hash.
17
+ # string<String>:: Textual content. Defaults to nil.
18
+ # &block:: A block to be evaluated and concatenated to string.
19
+ #
20
+ # ==== Returns
21
+ # Any content associated with the key (or nil).
22
+ #
23
+ # ==== Example
24
+ # content_for(:foo, "Foo")
25
+ # content_for(:foo) #=> "Foo"
26
+ # content_for(:foo, "Bar")
27
+ # content_for(:foo) #=> "FooBar"
28
+ #
29
+ def content_for( obj, string = nil, &block )
30
+ return @content_for[obj] unless string || block_given?
31
+
32
+ cur = @content_for[obj].to_s
33
+ new = string.to_s + (block_given? ? capture_erb(&block) : "")
34
+ @content_for[obj] = cur + new
35
+ end
36
+
37
+ # Returns true if there is content for the given key. Otherwise returns
38
+ # false.
39
+ #
40
+ # ==== Parameters
41
+ # obj<Object>:: The key in the conetnt_for hash.
42
+ #
43
+ # ==== Example
44
+ # content_for(:foo, "Foo")
45
+ # content_for?(:foo) #=> true
46
+ # content_for?(:bar) #=> false
47
+ #
48
+ def content_for?( obj )
49
+ @content_for.key?(obj)
50
+ end
51
+
52
+ # Deletes any content associated with the given object in the content_for
53
+ # hash.
54
+ #
55
+ # ==== Parameters
56
+ # obj<Object>:: The key in the conetnt_for hash.
57
+ #
58
+ # ==== Returns
59
+ # Any content associated with the key (or nil).
60
+ #
61
+ # ==== Example
62
+ # content_for(:foo, "Foo")
63
+ # content_for?(:foo) #=> true
64
+ # delete_content_for(:foo)
65
+ # content_for?(:foo) #=> false
66
+ #
67
+ def delete_content_for( obj )
68
+ @content_for.delete(obj)
69
+ end
70
+
71
+ # This method is used to capture content from an ERB filter evaluation. It
72
+ # is useful to helpers that need to process chunks of data during ERB filter
73
+ # processing.
74
+ #
75
+ # ==== Parameters
76
+ # *args:: Arguments to pass to the block.
77
+ # &block:: The ERB block to call.
78
+ #
79
+ # ==== Returns
80
+ # String:: The output of the block.
81
+ #
82
+ # ==== Examples
83
+ # Capture being used in an ERB page:
84
+ #
85
+ # <% @foo = capture_erb do %>
86
+ # <p>Some Foo content!</p>
87
+ # <% end %>
88
+ #
89
+ def capture_erb( *args, &block )
90
+ # get the buffer from the block's binding
91
+ buffer = _erb_buffer(block.binding) rescue nil
92
+
93
+ # If there is no buffer, just call the block and get the contents
94
+ if buffer.nil?
95
+ block.call(*args)
96
+ # If there is a buffer, execute the block, then extract its contents
97
+ else
98
+ pos = buffer.length
99
+ block.call(*args)
100
+
101
+ # extract the block
102
+ data = buffer[pos..-1]
103
+
104
+ # replace it in the original with empty string
105
+ buffer[pos..-1] = ""
106
+
107
+ data
108
+ end
109
+ end
110
+
111
+ # This method is used to concatenate content into the ERB output buffer.
112
+ # It is usefule to helpers that need to insert transformed text back into
113
+ # the ERB output buffer.
114
+ #
115
+ # ==== Parameters
116
+ # string<String>:: The string to insert into the ERB output.
117
+ # the_binding<Binding>:: The binding to pass to the buffer.
118
+ #
119
+ def concat_erb( string, the_binding )
120
+ _erb_buffer(the_binding) << string
121
+ end
122
+
123
+ # Provides direct acccess to the ERB buffer in the conext of the binding.
124
+ #
125
+ # ==== Parameters
126
+ # the_binding<Binding>:: The binding to pass to the buffer.
127
+ #
128
+ # ==== Returns
129
+ # The current ERB output buffer.
130
+ #
131
+ def _erb_buffer( the_binding )
132
+ eval('_erbout', the_binding, __FILE__, __LINE__)
133
+ end
134
+
135
+ end # module CaptureHelper
136
+ end # module Slideshow
137
+
138
+ Slideshow::Gen.__send__( :include, Slideshow::CaptureHelper )
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ module Slideshow
4
+ module DirectiveHelper
5
+
6
+ # css directive:
7
+ #
8
+ # lets you use:
9
+ # %css
10
+ # -- inline css code here
11
+ # %end
12
+ #
13
+ # shortcut for:
14
+ # %content_for :css
15
+ # -- inline css code here
16
+ # %end
17
+ # or
18
+ # <% content_for :css do %>
19
+ # -- inline css code here
20
+ # <% end %>
21
+
22
+ def css( &block )
23
+ content_for( :css, nil, &block )
24
+ end
25
+
26
+ def slide( params )
27
+ # note: to avoid runons with blocks (wrap in double newlines)
28
+
29
+ "\n\n<!-- _S9SLIDE_ #{params ? params : ''} -->\n\n"
30
+ end
31
+
32
+ def style( params )
33
+ # note: to avoid runons with blocks (wrap in double newlines)
34
+
35
+ "\n\n<!-- _S9STYLE_ #{params ? params : ''} -->\n\n"
36
+ end
37
+
38
+
39
+ end # module DirectiveHelper
40
+ end # module Slideshow
41
+
42
+ class Slideshow::Gen
43
+ include Slideshow::DirectiveHelper
44
+ end
45
+
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ module Slideshow
4
+ module MarkdownHelper
5
+
6
+ def s9_class( clazz )
7
+ "{: .#{clazz.strip}}"
8
+ end
9
+
10
+ def clear
11
+ "{: .clear}"
12
+ end
13
+
14
+
15
+ end # module MarkdownHelper
16
+ end # module Slideshow
17
+
18
+ class Slideshow::Gen
19
+ include Slideshow::MarkdownHelper
20
+ end
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ module Slideshow
4
+ module SourceHelper
5
+
6
+
7
+ def source( *args )
8
+
9
+ # make everyting optional; use it like:
10
+ # source( name_or_path, opts={} )
11
+
12
+ # check for optional hash for options
13
+ opts = args.last.kind_of?(Hash) ? args.pop : {}
14
+
15
+ # check for optional name or path
16
+ name_or_path = args.last.kind_of?(String) ? args.pop : "#{@name}#{@extname}"
17
+
18
+ link_text = opts[:text] || '(Source)'
19
+
20
+ # add extra path (e.g. 3rd) if present
21
+ name_or_path = "#{opts[:path]}/#{name_or_path}" if opts[:path]
22
+
23
+ # add file extension if missing (for convenience)
24
+ name_or_path << @extname if File.extname( name_or_path ).empty?
25
+
26
+ base = 'http://github.com/geraldb/slideshow/raw/master/samples'
27
+
28
+ buf = "<a href='#{base}/#{name_or_path}'>#{link_text}</a>"
29
+
30
+ puts " Adding HTML for source link to '#{name_or_path}'..."
31
+
32
+ guard_inline( buf )
33
+ end
34
+
35
+
36
+ end # module SourceHelper
37
+ end # module Slideshow
38
+
39
+ class Slideshow::Gen
40
+ include Slideshow::SourceHelper
41
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+
3
+ module Slideshow
4
+ module StepHelper
5
+
6
+
7
+ def step( opts={}, &blk )
8
+
9
+ puts " Adding HTML div block for step (incremental display)..."
10
+
11
+ text = capture_erb(&blk)
12
+
13
+ before = "<!-- begin step #{opts.inspect} -->\n"
14
+ before << "<div class='step' markdown='block'>\n"
15
+
16
+ after = "</div>\n"
17
+ after << "<!-- end step -->\n"
18
+
19
+ html = ""
20
+ html << guard_block( before )
21
+ html << text
22
+ html << guard_block( after )
23
+
24
+ concat_erb( html, blk.binding )
25
+ return
26
+ end
27
+
28
+
29
+ end # module StepHelper
30
+ end # module Slideshow
31
+
32
+ class Slideshow::Gen
33
+ include Slideshow::StepHelper
34
+ end
35
+
@@ -0,0 +1,86 @@
1
+ # encoding: utf-8
2
+
3
+ require 'coderay'
4
+
5
+ module Slideshow
6
+ module Syntax
7
+ module CodeRayHelper
8
+
9
+ # coderay option defaults
10
+ CR_LANG = 'ruby'
11
+ CR_LINE_NUMBERS = 'table' # table | list | inline
12
+
13
+ def coderay_worker( code, opts )
14
+
15
+ lang = opts.fetch( :lang, CR_LANG )
16
+ line_numbers = opts.fetch( :line_numbers, headers.get('code-line-numbers', CR_LINE_NUMBERS ) )
17
+ line_number_start = opts.fetch( :start, nil )
18
+
19
+ cr_opts = {}
20
+ cr_opts[ :line_numbers ] = line_numbers.to_sym
21
+ cr_opts[ :line_number_start ] = line_number_start.to_i if line_number_start
22
+
23
+ # todo: add options for bold_every, tab_width (any others?)
24
+
25
+ code_highlighted = CodeRay.scan( code, lang.to_sym ).html(cr_opts)
26
+
27
+ # first time? get built-in coderay stylesheet
28
+ cr_first_time = session.fetch( :cr_first_time, true )
29
+ if cr_first_time
30
+ session[ :cr_first_time ] = false
31
+
32
+ theme_content = CodeRay::Encoders[:html]::CSS.new.stylesheet
33
+
34
+ theme_out = %{/* styles for built-in coderay syntax highlighting theme */\n\n}
35
+ theme_out << theme_content
36
+ theme_out << %{\n\n}
37
+
38
+ content_for( :css, theme_out )
39
+ end
40
+
41
+ css_class = 'code'
42
+ css_class_opt = opts.fetch( :class, nil ) # large, small, tiny, etc.
43
+ css_class << " #{css_class_opt}" if css_class_opt # e.g. use/allow multiple classes -> code small, code large, etc.
44
+
45
+ name = opts.fetch( :name, nil )
46
+ txmt_value = opts.fetch( :txmt, headers.code_txmt )
47
+ txmt = (txmt_value =~ /true|yes|on/i) ? true : false
48
+
49
+ out = %{<div class='CodeRay'>}
50
+ out << %{<pre '#{css_class}'>\n}
51
+ out << code_highlighted
52
+ out << %{</pre>}
53
+ out << %{</div>}
54
+
55
+ # add optional href link for textmate
56
+ if name
57
+ out << %{<div class="codeurl">}
58
+ out << %{<a href="txmt://open?url=file://#{File.expand_path(name)}">} if txmt
59
+ out << name
60
+ out << %{</a>} if txmt
61
+ out << %{</div>\n}
62
+ end
63
+
64
+ return out
65
+ end
66
+
67
+ def coderay( *args, &blk )
68
+ # check for optional hash for options
69
+ opts = args.last.kind_of?(Hash) ? args.pop : {}
70
+
71
+ code = capture_erb(&blk)
72
+ return if code.empty?
73
+
74
+ code_highlighted = coderay_worker( code, opts )
75
+
76
+ concat_erb( wrap_markup( code_highlighted ), blk.binding )
77
+ return
78
+ end
79
+
80
+ end # module CodeRayHelper
81
+ end # module Syntax
82
+ end # module Slideshow
83
+
84
+ class Slideshow::Gen
85
+ include Slideshow::Syntax::CodeRayHelper
86
+ end
@@ -0,0 +1,63 @@
1
+ # encoding: utf-8
2
+
3
+ module Slideshow
4
+ module Syntax
5
+ module ShHelper
6
+
7
+ # sh option defaults
8
+ SH_LANG = 'ruby'
9
+ SH_LINE_NUMBERS = 'true'
10
+
11
+ def sh_worker( code, opts )
12
+
13
+ lang = opts.fetch( :lang, headers.get( 'code-language', SH_LANG ))
14
+ line_numbers_value = opts.fetch( :line_numbers, headers.get( 'code-line-numbers', SH_LINE_NUMBERS ))
15
+ line_numbers = (line_numbers_value =~ /true|yes|on/i) ? true : false
16
+
17
+ # note: code gets highlighted at runtime in client (using JavaScript)
18
+ code_highlighted = CGI::escapeHTML( code )
19
+
20
+ css_class = 'code'
21
+ css_class_opt = opts.fetch( :class, nil ) # large, small, tiny, etc.
22
+ css_class << " #{css_class_opt}" if css_class_opt # e.g. use/allow multiple classes -> code small, code large, etc.
23
+
24
+ out = %{<div class='#{css_class}'><pre class='brush: #{lang} toolbar: false gutter: #{line_numbers ? 'true' : 'false'}'>}
25
+ out << code_highlighted
26
+ out << %{</pre></div>\n}
27
+
28
+ name = opts.fetch( :name, nil )
29
+ txmt_value = opts.fetch( :txmt, headers.code_txmt )
30
+ txmt = (txmt_value =~ /true|yes|on/i) ? true : false
31
+
32
+ # add optional href link for textmate
33
+ if name
34
+ out << %{<div class="codeurl">}
35
+ out << %{<a href="txmt://open?url=file://#{File.expand_path(name)}">} if txmt
36
+ out << name
37
+ out << %{</a>} if txmt
38
+ out << %{</div>\n}
39
+ end
40
+
41
+ return out
42
+ end
43
+
44
+ def sv( *args, &blk )
45
+ # check for optional hash for options
46
+ opts = args.last.kind_of?(Hash) ? args.pop : {}
47
+
48
+ code = capture_erb(&blk)
49
+ return if code.empty?
50
+
51
+ code_highlighted = sv_worker( code, opts )
52
+
53
+ concat_erb( guard_block( code_highlighted ), blk.binding )
54
+ return
55
+ end
56
+
57
+ end # module ShHelper
58
+ end # module Syntax
59
+ end # module Slideshow
60
+
61
+ class Slideshow::Gen
62
+ include Slideshow::Syntax::ShHelper
63
+ end
@@ -0,0 +1,92 @@
1
+ # encoding: utf-8
2
+
3
+ require 'uv'
4
+
5
+ module Slideshow
6
+ module Syntax
7
+ module UvHelper
8
+
9
+ # uv option defaults
10
+ UV_LANG = 'ruby'
11
+ UV_LINE_NUMBERS = 'true'
12
+ UV_THEME = 'amy'
13
+
14
+ def uv_worker( code, opts )
15
+
16
+ lang = opts.fetch( :lang, UV_LANG )
17
+ line_numbers_value = opts.fetch( :line_numbers, headers.get( 'code-line-numbers', UV_LINE_NUMBERS ))
18
+ line_numbers = (line_numbers_value =~ /true|yes|on/i) ? true : false
19
+
20
+ # change all-hallows-eve (CSS-style/convention) to all_hallows_eve (uv internal-style)
21
+ theme = opts.fetch( :theme, headers.get( 'code-theme', UV_THEME )).tr( '-', '_' )
22
+
23
+ code_highlighted = Uv.parse( code, "xhtml", lang, line_numbers, theme )
24
+
25
+ # first time? copy all uv built-in themes (css styles) to temporary cache (~/.slideshow/*)
26
+ uv_first_time = session.fetch( :uv_first_time, true )
27
+ if uv_first_time
28
+ session[ :uv_first_time ] = false
29
+ logger.debug "cache_dir=#{config.cache_dir}"
30
+
31
+ FileUtils.mkdir(config.cache_dir) unless File.exists?(config.cache_dir) if config.cache_dir
32
+ Uv.copy_files "xhtml", config.cache_dir
33
+ end
34
+
35
+ # first time this theme gets used add it to content_for hash for templates to include
36
+ uv_themes = session[ :uv_themes ] ||= {}
37
+ if uv_themes[ theme ].nil?
38
+ uv_themes[ theme ] = true
39
+
40
+ theme_content = File.read( "#{config.cache_dir}/css/#{theme}.css" )
41
+
42
+ theme_out = %{/* styles for ultraviolet code syntax highlighting theme '#{theme}' */\n\n}
43
+ theme_out << theme_content
44
+ theme_out << %{\n\n}
45
+
46
+ content_for( :css, theme_out )
47
+ end
48
+
49
+ css_class = 'code'
50
+ css_class_opt = opts.fetch( :class, nil ) # large, small, tiny, etc.
51
+ css_class << " #{css_class_opt}" if css_class_opt # e.g. use/allow multiple classes -> code small, code large, etc.
52
+
53
+ name = opts.fetch( :name, nil )
54
+ txmt_value = opts.fetch( :txmt, headers.code_txmt )
55
+ txmt = (txmt_value =~ /true|yes|on/i) ? true : false
56
+
57
+ out = %{<pre class='#{css_class}'>\n}
58
+ out << code_highlighted
59
+ out << %{</pre>\n}
60
+
61
+ # add optional href link for textmate
62
+ if name
63
+ out << %{<div class="codeurl">}
64
+ out << %{<a href="txmt://open?url=file://#{File.expand_path(name)}">} if txmt
65
+ out << name
66
+ out << %{</a>} if txmt
67
+ out << %{</div>\n}
68
+ end
69
+
70
+ return out
71
+ end
72
+
73
+ def uv( *args, &blk )
74
+ # check for optional hash for options
75
+ opts = args.last.kind_of?(Hash) ? args.pop : {}
76
+
77
+ code = capture_erb(&blk)
78
+ return if code.empty?
79
+
80
+ code_highlighted = uv_worker( code, opts )
81
+
82
+ concat_erb( wrap_markup( code_highlighted ), blk.binding )
83
+ return
84
+ end
85
+
86
+ end # module UvHelper
87
+ end # module Syntax
88
+ end # module Slideshow
89
+
90
+ class Slideshow::Gen
91
+ include Slideshow::Syntax::UvHelper
92
+ end