Class: Regenerate::PageComponent

Inherits:
Object
  • Object
show all
Defined in:
lib/regenerate/web-page.rb

Overview

Base class for page components, defined by a sequence of lines in an HTML file which make up the text of that component

Direct Known Subclasses

RubyCode, SetPageObjectClass, StaticHtml, TextVariable

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePageComponent

Returns a new instance of PageComponent.



17
18
19
20
21
# File 'lib/regenerate/web-page.rb', line 17

def initialize
  @lines = [] # No lines of text yet
  @text = nil # if text is nil, component is not yet finished
  @parentPage = nil # A link to the parent WebPage object, will get set from a method on that object
end

Instance Attribute Details

#parentPageObject

Returns the value of attribute parentPage.



15
16
17
# File 'lib/regenerate/web-page.rb', line 15

def parentPage
  @parentPage
end

#textObject (readonly)

Returns the value of attribute text.



14
15
16
# File 'lib/regenerate/web-page.rb', line 14

def text
  @text
end

Instance Method Details

#addLine(line) ⇒ Object

Add a text line, by adding it to @lines



50
51
52
# File 'lib/regenerate/web-page.rb', line 50

def addLine(line)
  @lines << line
end

#addToParentPageObject

Do whatever needs to be done to the parent WebPage object for this page component



55
56
57
# File 'lib/regenerate/web-page.rb', line 55

def addToParentPage
  # default do nothing - over-ride this in derived classes
end

#finishedObject

Has this component finished



45
46
47
# File 'lib/regenerate/web-page.rb', line 45

def finished
  @text != nil # finishText sets the value of @text, so use that as a test for "is it finished?"
end

#finishTextObject

After all text lines have been added, join them together and put into @text



60
61
62
63
# File 'lib/regenerate/web-page.rb', line 60

def finishText
  @text = @lines.join("\n")
  addToParentPage # do whatever needs to be done to the parent WebPage object for this page component
end

#initializeFromStartComment(parsedCommentLine) ⇒ Object

Do whatever needs to be done to initialise this page component from the start command



40
41
42
# File 'lib/regenerate/web-page.rb', line 40

def initializeFromStartComment(parsedCommentLine)
  # default do nothing - over-ride this method in derived classes
end

#processEndComment(parsedCommentLine) ⇒ Object



32
33
34
35
36
37
# File 'lib/regenerate/web-page.rb', line 32

def processEndComment(parsedCommentLine)
  finishText # there will be no more text lines added to this component
  if parsedCommentLine.name != @startName # check match of name in end comment with name in start comment
    raise ParseException.new("Name #{parsedCommentLine.name.inspect} in end comment doesn't match name #{@startName.inspect} in start comment.")
  end
end

#processStartComment(parsedCommentLine) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/regenerate/web-page.rb', line 23

def processStartComment(parsedCommentLine)
  @startName = parsedCommentLine.name # remember the name in the start command, 
                                      # because it has to match the name in the end command
  initializeFromStartComment(parsedCommentLine) # do whatever has to be done to initialise this page component
  if parsedCommentLine.sectionEnd # section end in start comment line, so already finished
    finishText # i.e. there will be no more text lines added to this component
  end
end