Class: Swift::Playground::Section

Inherits:
Object
  • Object
show all
Includes:
Util::SourceIO
Defined in:
lib/swift/playground/section.rb

Direct Known Subclasses

CodeSection, DocumentationSection

Defined Under Namespace

Classes: TemplateContext

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contentObject (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)
  options = xcplayground_options

  node = Nokogiri::XML.fragment("<#{options[:node]}>").children.first
  node[options[:path_attribute]] = path(number).relative_path_from(directory)
  node
end