Class: Swift::Playground::Section
- Inherits:
-
Object
- Object
- Swift::Playground::Section
- Includes:
- Util::SourceIO
- Defined in:
- lib/swift/playground/section.rb
Direct Known Subclasses
Defined Under Namespace
Classes: TemplateContext
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
Instance Method Summary collapse
- #filename(number) ⇒ Object
-
#initialize(content) ⇒ Section
constructor
A new instance of Section.
- #path(number) ⇒ Object
- #render(number, playground, custom_content = nil) ⇒ Object
- #xcplayground_node(number) ⇒ Object
Methods included from Util::SourceIO
#derived_filename, #source_as_io
Constructor Details
#initialize(content) ⇒ Section
Returns a new instance of Section.
70 71 72 73 |
# File 'lib/swift/playground/section.rb', line 70 def initialize(content) @content = source_as_io(content).read @content.freeze end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
33 34 35 |
# File 'lib/swift/playground/section.rb', line 33 def content @content end |
Instance Method Details
#filename(number) ⇒ Object
75 76 77 |
# File 'lib/swift/playground/section.rb', line 75 def filename(number) "section-#{number}.#{extension}" end |
#path(number) ⇒ Object
79 80 81 |
# File 'lib/swift/playground/section.rb', line 79 def path(number) directory.join filename(number) end |
#render(number, playground, custom_content = nil) ⇒ Object
91 92 93 94 95 96 |
# File 'lib/swift/playground/section.rb', line 91 def render(number, playground, custom_content = nil) context = TemplateContext.context custom_content || content, number, playground template.result(context) end |
#xcplayground_node(number) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/swift/playground/section.rb', line 83 def xcplayground_node(number) = node = Nokogiri::XML.fragment("<#{options[:node]}>").children.first node[[:path_attribute]] = path(number).relative_path_from(directory) node end |