Class: Slideshow::Deck

Inherits:
Object
  • Object
show all
Includes:
LogUtils::Logging, DeckFilter
Defined in:
lib/slideshow/models/deck.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DeckFilter

#add_slide_directive_before_h1, #add_slide_directive_before_h2, #add_slide_directive_for_hr

Constructor Details

#initialize(source, header_level: 2, use_slide: false) ⇒ Deck

Returns a new instance of Deck.



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/slideshow/models/deck.rb', line 88

def initialize( source, header_level: 2, use_slide: false )
  @source = source  ## keep a copy of the original source (input)

  @header_level = header_level   # e.g. 1 or 2   -- todo/fix: allow more options e.g. 1..2 etc.
  @use_slide    = use_slide      # e.g. opts.slide? -- only allow !SLIDE directives fo slide breaks?

  @slides  = []
  @content = ''  # note: gets (re)build from slides in parse 

  parse()
end

Instance Attribute Details

#contentObject

all-in-one content (that is, incl. all slides )



84
85
86
# File 'lib/slideshow/models/deck.rb', line 84

def content
  @content
end

#slidesObject

Returns the value of attribute slides.



85
86
87
# File 'lib/slideshow/models/deck.rb', line 85

def slides
  @slides
end

Instance Method Details

#parseObject



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
# File 'lib/slideshow/models/deck.rb', line 101

def parse
  #############################
  # step 1 - add slide breaks

  @content = @source

  if @use_slide  # only allow !SLIDE directives fo slide breaks?
     # do nothing (no extra automagic slide breaks wanted)
  else  

    ## default rule for horizontal line/rule <hr> - gets replaced by slide directive
    ##  - for now alway on/used  (use !SLIDE only if not wanted for now)
    @content = add_slide_directive_for_hr( @content )

    if @header_level == 1
      @content = add_slide_directive_before_h1( @content )
    else # assume level 2
      ## note: level 2 also turns level 1 into slide breaks
      @content = add_slide_directive_before_h1( @content )
      @content = add_slide_directive_before_h2( @content )
    end
  end


  ### todo/fix: add back dump to file (requires @name and outpath !!!!)
  ### dump_content_to_file_debug_html( content )


  #############################################################
  # step 2 -  use generic slide break processing instruction to
  #   split content into slides

  counter = 0
  chunks = []
  buf = ""

   
  @content.each_line do |line|
     if line.include?( '<!-- _S9SLIDE_' ) || line.include?( '<!-- @SLIDE' )  ## add new format  
        if counter > 0   # found start of new slide (and, thus, end of last slide)
          chunks << buf  # add slide to slide stack
          buf = ""         # reset slide source buffer
        else  # counter == 0
          # check for first slide with missing leading SLIDE directive (possible/allowed in takahashi, for example)
          ##  remove html comments and whitspaces (still any content?)
          ### more than just whitespace? assume its  a slide
          if buf.gsub(/<!--.*?-->/m, '').gsub( /[\n\r\t ]/, '').length > 0
            logger.debug "add slide with missing leading slide directive >#{buf}< with slide_counter == 0"
            chunks << buf
            buf = ""
          else
            logger.debug "** note: skipping slide >#{buf}< with counter == 0"
          end
        end
        counter += 1
     end
     buf << line
  end

  if counter > 0
    chunks << buf     # add slide to slide stack
    buf = ""            # reset slide source buffer 
  end


  @slides = []
  chunks.each do |chunk|
    @slides << Slide.new( chunk, header_level: @header_level )
  end


  puts "#{@slides.size} slides found:"
  
  @slides.each_with_index do |slide,i|
    print "  [#{i+1}] "
    if slide.header.present?
      print slide.header
    else
      # remove html comments
      print "-- no header -- | #{slide.content.gsub(/<!--.*?-->/m, '').gsub(/\n/,'$')[0..40]}"
    end
    puts
  end

  ## rebuild all-in-one content (incl. all slides)       
  @content = ""
  @slides.each do |slide|
    @content << slide.to_classic_html
  end  
end