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,132 @@
1
+ # encoding: utf-8
2
+
3
+ module Slideshow
4
+ module TextHelper
5
+
6
+ def s9_include( name, opts = {} )
7
+ puts " Including '#{name}'..."
8
+ content = File.read( name )
9
+ end
10
+
11
+
12
+ # Usage example:
13
+ # <%= code 'code/file.rb#section', :lang => 'ruby', :class => 'small' %>
14
+ # or
15
+ # <% code :lang => 'ruby' do %>
16
+ # code goes here
17
+ # <% end %>
18
+ #
19
+
20
+ def code( *args, &blk )
21
+ # check for optional hash for options
22
+ opts = args.last.kind_of?(Hash) ? args.pop : {}
23
+
24
+ name_plus_part = args.first # check for optional filename
25
+
26
+ if name_plus_part
27
+ name, part = name_plus_part.split( '#' ) # split off optional part/anchor
28
+
29
+ content = find_content_from( name, part )
30
+
31
+ # add name and part to opts so engine can use paras too
32
+ opts[ :name ] = name
33
+ opts[ :part ] = part if part
34
+
35
+ return format_code( content, opts )
36
+ elsif blk # inline code via block?
37
+ content = capture_erb(&blk)
38
+ return if content.empty?
39
+
40
+ concat_erb( format_code( content, opts ), blk.binding )
41
+ return
42
+ else
43
+ msg = '*** warning: empty code directive; inline code or file para expected'
44
+ puts msg
45
+ return wrap_markup( "<!-- #{msg} -->" )
46
+ end
47
+ end
48
+
49
+
50
+ def find_content_from( name, part )
51
+ begin
52
+ content = File.read( name )
53
+
54
+ # note: for now content with no parts selected gets filtered too and (part) marker lines get removed from source
55
+ lines = find_part_lines_in( content, part )
56
+
57
+ if part
58
+ puts " Including code part '#{part}' in '#{name}' [#{lines.size} lines]..."
59
+ ## todo: issue warning if no lines found?
60
+ else
61
+ puts " Including code in '#{name}' [#{lines.size} lines]..."
62
+ end
63
+
64
+ return lines.join
65
+ rescue Exception => e
66
+ puts "*** error: reading '#{name}': #{e}"
67
+ exit 2
68
+ end
69
+ end
70
+
71
+ def find_part_lines_in( content, part )
72
+ result = []
73
+ state = part.nil? ? :normal : :skipping
74
+ content.each_line do |line|
75
+ if line =~ /(START|END):(\w+)/
76
+ if $2 == part
77
+ if $1 == "START"
78
+ state = :normal
79
+ else
80
+ state = :skipping
81
+ end
82
+ end
83
+ next
84
+ end
85
+ result << line unless state == :skipping
86
+ end
87
+ result
88
+ end
89
+
90
+
91
+ def format_code( code, opts )
92
+
93
+ engine = opts.fetch( :engine, headers.code_engine ).to_s.downcase
94
+
95
+ if engine == 'uv' || engine == 'ultraviolet'
96
+ if respond_to?( :uv_worker )
97
+ code_highlighted = uv_worker( code, opts )
98
+ else
99
+ puts "** error: ultraviolet gem required for syntax highlighting; install with gem install ultraviolet (or use a different engine)"
100
+ exit 2
101
+ end
102
+ elsif engine == 'cr' || engine == 'coderay'
103
+ if respond_to?( :coderay_worker )
104
+ code_highlighted = coderay_worker( code, opts )
105
+ else
106
+ puts "*** error: coderay gem required for syntax highlighting; install with gem install coderay (or use a different engine)"
107
+ exit 2
108
+ end
109
+ else
110
+ method_name = "#{engine}_worker".to_sym
111
+ if respond_to?( method_name )
112
+ # try to call custom syntax highlighting engine
113
+ code_highlighted = send( method_name, code, opts )
114
+ else
115
+ msg = "*** error: unkown syntax highlighting engine '#{engine}'; available built-in options include: uv, ultraviolet, cr, coderay"
116
+ puts msg
117
+ code_highlighted = "<!-- #{msg} -->"
118
+ end
119
+ end
120
+
121
+ out = %{<!-- begin code#{opts.inspect} -->\n}
122
+ out << code_highlighted
123
+ out << %{<!-- end code -->\n}
124
+
125
+ guard_block( out ) # saveguard with notextile wrapper etc./no further processing needed
126
+ end
127
+
128
+
129
+ end # module TextHelper
130
+ end # module Slideshow
131
+
132
+ Slideshow::Gen.__send__( :include, Slideshow::TextHelper )
@@ -0,0 +1,99 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ module Slideshow
5
+
6
+ module ManifestHelper
7
+
8
+ ## shared methods for handling manifest lookups
9
+
10
+ def installed_plugin_manifest_patterns
11
+ # 1) search ./plugins
12
+ # 2) search config_dir/plugins
13
+
14
+ config_patterns = [
15
+ "#{config.config_dir}/plugins/*.{txt.plugin,plugin.txt}",
16
+ "#{config.config_dir}/plugins/*/*.{txt.plugin,plugin.txt}"
17
+ ]
18
+ current_patterns = [
19
+ "plugins/*.{txt.plugin,plugin.txt}",
20
+ "plugins/*/*.{txt.plugin,plugin.txt}"
21
+ ]
22
+
23
+ patterns = []
24
+ patterns += current_patterns
25
+ patterns += config_patterns
26
+ end
27
+
28
+ def installed_plugin_manifests # quickstarter templates
29
+ Pakman::Finder.new.find_manifests( installed_plugin_manifest_patterns )
30
+ end
31
+
32
+
33
+ def installed_template_manifest_patterns
34
+ # 1) search ./templates
35
+ # 2) search config_dir/templates
36
+ # 3) search gem/templates
37
+
38
+ # Note: only include builtin patterns if slideshow-templates gem included/required (it's optional)
39
+ builtin_patterns = []
40
+ builtin_patterns << "#{SlideshowTemplates.root}/templates/*.txt" if defined?( SlideshowTemplates )
41
+
42
+ config_patterns = [
43
+ "#{config.config_dir}/templates/*.txt",
44
+ "#{config.config_dir}/templates/*/*.txt"
45
+ ]
46
+ current_patterns = [
47
+ "templates/*.txt",
48
+ "templates/*/*.txt" # todo: use all in one line? {*.txt,*/*.txt} does it work?
49
+ ]
50
+
51
+ patterns = []
52
+ patterns += current_patterns
53
+ patterns += config_patterns
54
+ patterns += builtin_patterns
55
+ end
56
+
57
+ def installed_template_manifests
58
+ ## note: code moved to its own gem, that is, pakman
59
+ ## see https://github.com/geraldb/pakman
60
+
61
+ ## exclude manifest.txt/i (avoid confusion w/ ruby gem manifest; not a specific name anyway)
62
+ ## also exclude patterns for quickstarter templates
63
+
64
+ excludes = [
65
+ 'manifest.txt',
66
+ '*/manifest.txt',
67
+ '*.{txt.quick,quick.txt}',
68
+ '*/*.{txt.quick,quick.txt}'
69
+ ]
70
+
71
+ Pakman::Finder.new.find_manifests( installed_template_manifest_patterns, excludes )
72
+ end
73
+
74
+
75
+ def installed_quick_manifest_patterns
76
+ # 1) search config_dir/templates
77
+ # 2) search gem/templates
78
+
79
+ # Note: only include builtin patterns if slideshow-templates gem included/required (it's optional)
80
+ builtin_patterns = []
81
+ builtin_patterns << "#{SlideshowTemplates.root}/templates/*.{txt.quick,quick.txt}" if defined?( SlideshowTemplates )
82
+
83
+ config_patterns = [
84
+ "#{config.config_dir}/templates/*.{txt.quick,quick.txt}",
85
+ "#{config.config_dir}/templates/*/*.{txt.quick,quick.txt}"
86
+ ]
87
+
88
+ patterns = []
89
+ patterns += config_patterns
90
+ patterns += builtin_patterns
91
+ end
92
+
93
+ def installed_quick_manifests # quickstarter templates
94
+ Pakman::Finder.new.find_manifests( installed_quick_manifest_patterns )
95
+ end
96
+
97
+
98
+ end # module Manifest
99
+ end # module Slideshow
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ module Slideshow
4
+ module MarkdownEngines
5
+
6
+ ## note: code moved to its own gem, that is, markdown
7
+ ## see https://github.com/geraldb/markdown
8
+
9
+ def markdown_to_html( content )
10
+ ## puts " Converting Markdown-text (#{content.length} bytes) to HTML using library '#{@markdown_libs.first}' calling '#{mn}'..."
11
+
12
+ Markdown.new( content ).to_html
13
+ end
14
+
15
+ end # module MarkdownEngines
16
+ end # module Slideshow
17
+
18
+ class Slideshow::Gen
19
+ include Slideshow::MarkdownEngines
20
+ end
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ module Slideshow
4
+ module MediawikiEngines
5
+
6
+
7
+ def setup_mediawiki_engine
8
+ return if @mediawiki_engine_setup
9
+ logger.debug 'require wikicloth -- load mediawiki library'
10
+ require 'wikicloth' # default mediawiki library
11
+ @mediawiki_engine_setup = true
12
+ rescue LoadError
13
+ puts "You're missing a library required for Mediawiki to Hypertext conversion. Please run:"
14
+ puts " $ gem install wikicloth"
15
+ # check: raise exception instead of exit e.g
16
+ # raise FatalException.new( 'Missing library dependency: wikicloth' )
17
+ exit 1
18
+ end
19
+
20
+
21
+ def mediawiki_to_html( content )
22
+
23
+ setup_mediawiki_engine()
24
+
25
+ puts " Converting Mediawiki-text (#{content.length} bytes) to HTML..."
26
+
27
+ # NB: turn off table_of_contents (TOC) auto-generation with __NOTOC__
28
+ # NB: turn off adding of edit section/markers for headings (noedit:true)
29
+
30
+ wiki = WikiCloth::Parser.new( data: "__NOTOC__\n"+content, params: {} )
31
+
32
+ content = wiki.to_html( noedit: true )
33
+ end
34
+
35
+ end # module MediawikiEngines
36
+ end # module Slideshow
37
+
38
+ class Slideshow::Gen
39
+ include Slideshow::MediawikiEngines
40
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ require 'pandoc-ruby'
4
+
5
+ module Slideshow
6
+ module RestEngines # reStructuredText
7
+
8
+ def rest_to_html( content )
9
+ puts " Converting reStructuredText (#{content.length} bytes) to HTML..."
10
+
11
+ content = PandocRuby.new( content, :from => :rst, :to => :html ).convert
12
+ end
13
+
14
+ end # module RestEngines
15
+ end # module Slideshow
16
+
17
+ class Slideshow::Gen
18
+ include Slideshow::RestEngines
19
+ end
@@ -0,0 +1,70 @@
1
+ # encoding: utf-8
2
+
3
+ module Slideshow
4
+ module TextileEngines
5
+
6
+ def redcloth_java_fix_escape_nonascii( txt )
7
+ txt.chars.map{ |x| x.size > 1 ? "&##{x.unpack("U*")};" : x }.join
8
+ end
9
+
10
+ def redcloth_java_fix_escape_nonascii_exclude_pre( txt )
11
+
12
+ buf = ""
13
+ from = 0
14
+
15
+ while (pos = txt.index( /<pre.*?>.*?<\/pre>/m, from ))
16
+ # add text before pre block escaped
17
+ buf << redcloth_java_fix_escape_nonascii( txt[ from, pos-from] )
18
+
19
+ # add pre block unescaped (otherwise html entities get escaped twice)
20
+ from = Regexp.last_match.end(0)
21
+ buf << txt[pos, from-pos]
22
+ end
23
+ buf << redcloth_java_fix_escape_nonascii( txt[from, txt.length-from] )
24
+
25
+ buf
26
+ end
27
+
28
+
29
+ def setup_textile_engine
30
+ return if @textile_engine_setup
31
+ logger.debug 'require redcloth -- load textile library'
32
+ require 'redcloth' # default textile library
33
+ @textile_engine_setup = true
34
+ rescue LoadError
35
+ puts "You're missing a library required for Textile to Hypertext conversion. Please run:"
36
+ puts " $ gem install RedCloth"
37
+ # check: raise exception instead of exit e.g
38
+ # raise FatalException.new( 'Missing library dependency: RedCloth' )
39
+ exit 1
40
+ end
41
+
42
+
43
+ def textile_to_html( content )
44
+
45
+ setup_textile_engine() # optinal lib; extra; load only textile lib if used (soft dependency)
46
+
47
+ puts " Converting Textile-text (#{content.length} bytes) to HTML..."
48
+
49
+ # JRuby workaround for RedCloth 4 multi-byte character bug
50
+ # see http://jgarber.lighthouseapp.com/projects/13054/tickets/149-redcloth-4-doesnt-support-multi-bytes-content
51
+ # basically convert non-ascii chars (>127) to html entities
52
+
53
+ if RedCloth::EXTENSION_LANGUAGE == "Java"
54
+ puts " Patching RedCloth for Java; converting non-Ascii/multi-byte chars to HTML-entities..."
55
+ content = redcloth_java_fix_escape_nonascii_exclude_pre( content )
56
+ end
57
+
58
+ # turn off hard line breaks
59
+ # turn off span caps (see http://rubybook.ca/2008/08/16/redcloth)
60
+ red = RedCloth.new( content, [:no_span_caps] )
61
+ red.hard_breaks = false
62
+ content = red.to_html
63
+ end
64
+
65
+ end # module TextileEngines
66
+ end # module Slideshow
67
+
68
+ class Slideshow::Gen
69
+ include Slideshow::TextileEngines
70
+ end
@@ -0,0 +1,98 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ # core and stlibs
5
+ require 'erb'
6
+ require 'pp'
7
+ require 'date'
8
+ require 'ostruct'
9
+ require 'yaml'
10
+ require 'json'
11
+ require 'uri'
12
+ require 'net/http'
13
+ require 'net/https'
14
+ require 'cgi'
15
+ require 'fileutils'
16
+
17
+
18
+ # required gems
19
+ require 'active_support/all'
20
+
21
+ require 'props' # manage settings/env
22
+ require 'logutils' # logger utils library
23
+
24
+ require 'markdown' # default markdown library
25
+ require 'fetcher' # fetch docs and blogs via http, https, etc.
26
+
27
+
28
+ class Env
29
+ def self.slideshowopt
30
+ ENV[ 'SLIDESHOWOPT' ]
31
+ end
32
+ end # class Env
33
+
34
+ require 'textutils' # text filters and helpers
35
+ require 'pakman' # template pack manager
36
+
37
+
38
+ # our own code
39
+ require 'slideshow/version' # note: let version always go first
40
+ require 'slideshow/headers'
41
+ require 'slideshow/config'
42
+ require 'slideshow/manifest_helpers'
43
+ require 'slideshow/plugin_helpers'
44
+ require 'slideshow/slide'
45
+
46
+ require 'slideshow/commands/fetch'
47
+ require 'slideshow/commands/gen'
48
+ require 'slideshow/commands/list'
49
+ require 'slideshow/commands/plugins'
50
+ require 'slideshow/commands/quick'
51
+
52
+
53
+ require 'slideshow/markup/markdown'
54
+ require 'slideshow/markup/mediawiki'
55
+ require 'slideshow/markup/textile'
56
+
57
+
58
+ # load built-in (required) helpers/plugins
59
+ require 'slideshow/helpers/text_helper'
60
+ require 'slideshow/helpers/capture_helper'
61
+ require 'slideshow/helpers/step_helper'
62
+ require 'slideshow/helpers/background_helper'
63
+ require 'slideshow/helpers/source_helper'
64
+ require 'slideshow/helpers/directive_helper'
65
+ require 'slideshow/helpers/markdown_helper'
66
+
67
+ require 'slideshow/helpers/syntax/sh_helper'
68
+
69
+ # load built-in filters
70
+ require 'slideshow/filters/headers_filter'
71
+ require 'slideshow/filters/text_filter'
72
+ require 'slideshow/filters/debug_filter'
73
+ require 'slideshow/filters/slide_filter'
74
+
75
+
76
+
77
+ # load built-in (optional) helpers/plugins/engines
78
+ # If a helper fails to load, simply ingnore it
79
+ # If you want to use it install missing required gems e.g.:
80
+ # gem install coderay
81
+ # gem install ultraviolet etc.
82
+ BUILTIN_OPT_HELPERS = [
83
+ 'slideshow/helpers/syntax/uv_helper.rb',
84
+ 'slideshow/helpers/syntax/coderay_helper.rb',
85
+ 'slideshow/markup/rest.rb',
86
+ ]
87
+
88
+ BUILTIN_OPT_HELPERS.each do |helper|
89
+ begin
90
+ require(helper)
91
+ rescue Exception => e
92
+ ;
93
+ end
94
+ end
95
+
96
+
97
+ # say hello
98
+ puts Slideshow.banner if $DEBUG || (defined?($RUBYLIBS_DEBUG) && $RUBYLIBS_DEBUG)