Class: Regenerate::RubyCode

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

Overview

A page component consisting of Ruby code which is to be evaluated in the context of the object that defines the page Defined by start line “<!– [ruby” and end line “ruby] –>”.

Instance Attribute Summary collapse

Attributes inherited from PageComponent

#parentPage, #text

Instance Method Summary collapse

Methods inherited from PageComponent

#addLine, #finishText, #finished, #initializeFromStartComment, #processEndComment, #processStartComment

Constructor Details

#initialize(lineNumber) ⇒ RubyCode

Initialise this page component, additionally initialising the line number



89
90
91
92
# File 'lib/regenerate/web-page.rb', line 89

def initialize(lineNumber)
  super()
  @lineNumber = lineNumber
end

Instance Attribute Details

#lineNumberObject (readonly)

The line number, which matters for code evaluation so that Ruby can populate stack traces correctly



86
87
88
# File 'lib/regenerate/web-page.rb', line 86

def lineNumber
  @lineNumber
end

Instance Method Details

#addToParentPageObject

Add to parent page, which requires adding to the page’s list of Ruby page components (which will all get executed at some later stage)



105
106
107
# File 'lib/regenerate/web-page.rb', line 105

def addToParentPage
  @parentPage.addRubyComponent(self)
end

#output(showSource = true) ⇒ Object

Output this page component in a form that would be reparsed back into the same page component



95
96
97
98
99
100
101
# File 'lib/regenerate/web-page.rb', line 95

def output(showSource = true)
  if showSource
    "<!-- [ruby\n#{text}\nruby] -->\n"
  else
    ""
  end
end