Class: Slideshow::Gen
- Inherits:
-
Object
- Object
- Slideshow::Gen
- Includes:
- LogUtils::Logging, BackgroundHelper, DebugFilter, DirectiveHelper, HeadersFilter, ManifestHelper, MarkdownEngines, SlideFilter, SourceHelper, StepHelper, Syntax::CodeRayHelper, Syntax::ShHelper, Syntax::UvHelper, TextFilter
- Defined in:
- lib/slideshow/markdown.rb,
lib/slideshow/commands/gen.rb,
lib/slideshow/filters/text_filter.rb,
lib/slideshow/helpers/step_helper.rb,
lib/slideshow/filters/debug_filter.rb,
lib/slideshow/filters/slide_filter.rb,
lib/slideshow/helpers/source_helper.rb,
lib/slideshow/filters/headers_filter.rb,
lib/slideshow/helpers/directive_helper.rb,
lib/slideshow/helpers/syntax/sh_helper.rb,
lib/slideshow/helpers/syntax/uv_helper.rb,
lib/slideshow/helpers/background_helper.rb,
lib/slideshow/helpers/syntax/coderay_helper.rb
Overview
module Slideshow
Constant Summary
Constants included from Syntax::CodeRayHelper
Syntax::CodeRayHelper::CR_LANG, Syntax::CodeRayHelper::CR_LINE_NUMBERS
Constants included from Syntax::UvHelper
Syntax::UvHelper::UV_LANG, Syntax::UvHelper::UV_LINE_NUMBERS, Syntax::UvHelper::UV_THEME
Constants included from Syntax::ShHelper
Syntax::ShHelper::SH_LANG, Syntax::ShHelper::SH_LINE_NUMBERS
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#outdir ⇒ Object
readonly
NB: “initalized” in create_slideshow.
-
#pakdir ⇒ Object
readonly
NB: “initalized” in create_slideshow.
-
#session ⇒ Object
readonly
give helpers/plugins a session-like hash.
-
#srcdir ⇒ Object
readonly
NB: “initalized” in create_slideshow.
-
#usrdir ⇒ Object
readonly
original working dir (user called slideshow from).
Instance Method Summary collapse
- #create_slideshow(fn) ⇒ Object
-
#guard_block(text) ⇒ Object
use/rename to guard_text_block - why? why not?.
-
#guard_inline(text) ⇒ Object
use/rename to guard_text_inline - why? why not?.
- #guard_text(text) ⇒ Object
-
#initialize(config) ⇒ Gen
constructor
A new instance of Gen.
- #wrap_markup(text) ⇒ Object
Methods included from Syntax::CodeRayHelper
Methods included from BackgroundHelper
#background, #color, #gradient, #gradient_from_headers
Methods included from Syntax::UvHelper
Methods included from Syntax::ShHelper
Methods included from DirectiveHelper
Methods included from HeadersFilter
Methods included from SourceHelper
Methods included from SlideFilter
Methods included from DebugFilter
#dump_content_to_file_debug_html, #dump_content_to_file_debug_text, #dump_content_to_file_debug_text_erb
Methods included from StepHelper
Methods included from TextFilter
#directives_bang_style_to_percent_style, #directives_percent_style, #erb_rename_helper_hack
Methods included from ManifestHelper
#installed_plugin_manifest_patterns, #installed_plugin_manifests, #installed_quick_manifest_patterns, #installed_quick_manifests, #installed_template_manifest_patterns, #installed_template_manifests
Methods included from MarkdownEngines
Constructor Details
#initialize(config) ⇒ Gen
Returns a new instance of Gen.
15 16 17 18 19 20 21 |
# File 'lib/slideshow/commands/gen.rb', line 15 def initialize( config ) @config = config @headers = Headers.new( config ) ## todo: check if we need to use expand_path - Dir.pwd always absolute (check ~/user etc.) @usrdir = File.( Dir.pwd ) # save original (current) working directory end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
27 28 29 |
# File 'lib/slideshow/commands/gen.rb', line 27 def config @config end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
27 28 29 |
# File 'lib/slideshow/commands/gen.rb', line 27 def headers @headers end |
#outdir ⇒ Object (readonly)
NB: “initalized” in create_slideshow
24 25 26 |
# File 'lib/slideshow/commands/gen.rb', line 24 def outdir @outdir end |
#pakdir ⇒ Object (readonly)
NB: “initalized” in create_slideshow
24 25 26 |
# File 'lib/slideshow/commands/gen.rb', line 24 def pakdir @pakdir end |
#session ⇒ Object (readonly)
give helpers/plugins a session-like hash
28 29 30 |
# File 'lib/slideshow/commands/gen.rb', line 28 def session @session end |
#srcdir ⇒ Object (readonly)
NB: “initalized” in create_slideshow
24 25 26 |
# File 'lib/slideshow/commands/gen.rb', line 24 def srcdir @srcdir end |
#usrdir ⇒ Object (readonly)
original working dir (user called slideshow from)
23 24 25 |
# File 'lib/slideshow/commands/gen.rb', line 23 def usrdir @usrdir end |
Instance Method Details
#create_slideshow(fn) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/slideshow/commands/gen.rb', line 59 def ( fn ) manifest_path_or_name = config.manifest # add .txt file extension if missing (for convenience) if manifest_path_or_name.downcase.ends_with?( '.txt' ) == false manifest_path_or_name << '.txt' end logger.debug "manifest=#{manifest_path_or_name}" # check if file exists (if yes use custom template package!) - allows you to override builtin package with same name if File.exists?( manifest_path_or_name ) manifestsrc = manifest_path_or_name else # check for builtin manifests manifests = installed_template_manifests matches = manifests.select { |m| m[0] == manifest_path_or_name } if matches.empty? puts "*** error: unknown template manifest '#{manifest_path_or_name}'" # todo: list installed manifests exit 2 end manifestsrc = matches[0][1] end ### todo: use File.expand_path( xx, relative_to ) always with second arg ## do NOT default to cwd (because cwd will change!) # Reference src with absolute path, because this can be used with different pwd manifestsrc = File.( manifestsrc, usrdir ) # expand output path in current dir and make sure output path exists @outdir = File.( config.output_path, usrdir ) logger.debug "setting outdir to >#{outdir}<" FileUtils.makedirs( outdir ) unless File.directory? outdir dirname = File.dirname( fn ) basename = File.basename( fn, '.*' ) extname = File.extname( fn ) logger.debug "dirname=#{dirname}, basename=#{basename}, extname=#{extname}" # change working dir to sourcefile dir # todo: add a -c option to commandline? to let you set cwd? @srcdir = File.( dirname, usrdir ) logger.debug "setting srcdir to >#{srcdir}<" unless usrdir == srcdir logger.debug "changing cwd to src - new >#{srcdir}<, old >#{Dir.pwd}<" Dir.chdir srcdir end puts "Preparing slideshow '#{basename}'..." ### todo/fix: ## reset headers too - why? why not? # shared variables for templates (binding) @content_for = {} # reset content_for hash @name = basename @extname = extname @session = {} # reset session hash for plugins/helpers inname = "#{basename}#{extname}" logger.debug "inname=#{inname}" content = File.read( inname ) # run text filters config.text_filters.each do |filter| mn = filter.tr( '-', '_' ).to_sym # construct method name (mn) puts " run filter #{mn}..." content = send( mn, content ) # call filter e.g. include_helper_hack( content ) end if config.takahashi? content = ( content ) end # convert light-weight markup to hypertext content = markdown_to_html( content ) # post-processing deck = Deck.new( content, header_level: config.header_level, use_slide: config. ) ### todo/fix: move merge to its own ## class e.g. commands/merge.rb or something ## or use Merger - why? why not? #### pak merge # nb: change cwd to template pak root @pakdir = File.dirname( manifestsrc ) # template pak root - make availabe too in erb via binding logger.debug " setting pakdir to >#{pakdir}<" # todo/fix: change current work dir (cwd) in pakman gem itself # for now lets do it here logger.debug "changing cwd to pak - new >#{pakdir}<, old >#{Dir.pwd}<" Dir.chdir( pakdir ) pakpath = outdir logger.debug( "manifestsrc >#{manifestsrc}<, pakpath >#{pakpath}<" ) ########################################### ## fix: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ## todo: setup hash for binding ctx = { 'name' => @name, 'headers' => HeadersDrop.new( @headers ), 'content' => deck.content, 'slides' => deck..map { || SlideDrop.new() }, # strutured content - use LiquidDrop - why? why not? ## todo/fix: add content_for hash ## and some more -- ?? } ## add content_for entries e.g. ## content_for :js => more_content_for_js or content_for_js or extra_js etc. ## for now allow all three aliases puts "content_for:" pp @content_for @content_for.each do |k,v| puts " (auto-)add content_for >#{k.to_s}< to ctx:" puts v ctx[ "more_content_for_#{k}"] = v ctx[ "content_for_#{k}" ] = v ctx[ "extra_#{k}" ] = v end puts "ctx:" pp ctx Pakman::LiquidTemplater.new.merge_pak( manifestsrc, pakpath, ctx, basename ) logger.debug "restoring cwd to src - new >#{srcdir}<, old >#{Dir.pwd}<" Dir.chdir( srcdir ) ## pop/restore org (original) working folder/dir unless usrdir == srcdir logger.debug "restoring cwd to usr - new >#{usrdir}<, old >#{Dir.pwd}<" Dir.chdir( usrdir ) end puts "Done." end |
#guard_block(text) ⇒ Object
use/rename to guard_text_block - why? why not?
44 45 46 47 |
# File 'lib/slideshow/commands/gen.rb', line 44 def guard_block( text ) ## use/rename to guard_text_block - why? why not? # wrap in newlines to avoid runons "\n\n#{text}\n\n" end |
#guard_inline(text) ⇒ Object
use/rename to guard_text_inline - why? why not?
49 50 51 |
# File 'lib/slideshow/commands/gen.rb', line 49 def guard_inline( text ) ## use/rename to guard_text_inline - why? why not? wrap_markup( text ) end |
#guard_text(text) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/slideshow/commands/gen.rb', line 31 def guard_text( text ) # todo/fix 2: note we need to differentiate between blocks and inline # thus, to avoid runs - use guard_block (add a leading newline to avoid getting include in block that goes before) # todo/fix: remove wrap_markup; replace w/ guard_text # why: text might be css, js, not just html ### !!!!!!!!!!!! ## todo: add print depreciation warning wrap_markup( text ) end |
#wrap_markup(text) ⇒ Object
53 54 55 56 |
# File 'lib/slideshow/commands/gen.rb', line 53 def wrap_markup( text ) # saveguard with wrapper etc./no further processing needed - check how to do in markdown text end |