Class: WLang::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/wlang/source.rb,
lib/wlang/source/front_matter.rb

Direct Known Subclasses

FrontMatter

Defined Under Namespace

Classes: FrontMatter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subject, template = nil) ⇒ Source

Returns a new instance of Source.



7
8
9
10
11
# File 'lib/wlang/source.rb', line 7

def initialize(subject, template = nil)
  @subject  = subject
  @template = template
  @locals   = {}
end

Instance Attribute Details

#subjectObject (readonly)

Returns the value of attribute subject.



4
5
6
# File 'lib/wlang/source.rb', line 4

def subject
  @subject
end

#templateObject (readonly)

Returns the value of attribute template.



5
6
7
# File 'lib/wlang/source.rb', line 5

def template
  @template
end

Instance Method Details

#localsObject



18
19
20
# File 'lib/wlang/source.rb', line 18

def locals
  @locals
end

#pathObject Also known as: to_path



13
14
15
# File 'lib/wlang/source.rb', line 13

def path
  find_on_subject(:path, :to_path)
end

#raw_contentObject



22
23
24
25
26
# File 'lib/wlang/source.rb', line 22

def raw_content
  find_on_subject(:read, :to_str){
    raise ArgumentError, "Invalid template source `#{subject}`"
  }
end

#template_contentObject



28
29
30
# File 'lib/wlang/source.rb', line 28

def template_content
  raw_content
end

#to_strObject Also known as: to_s



32
33
34
# File 'lib/wlang/source.rb', line 32

def to_str
  template_content
end

#with_front_matter(enabled = true) ⇒ Object



37
38
39
# File 'lib/wlang/source.rb', line 37

def with_front_matter(enabled = true)
  enabled ? FrontMatter.new(self, template) : self
end