Class: Noticent::View

Inherits:
Object
  • Object
show all
Defined in:
lib/noticent/view.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, template_filename: "", channel:) ⇒ View

Returns a new instance of View.

Raises:



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/noticent/view.rb', line 19

def initialize(filename, template_filename: "", channel:)
  raise ViewNotFound, "view #{filename} not found" unless File.exist?(filename)
  raise ViewNotFound, "template #{template_filename} not found" if template_filename != "" && !File.exist?(template_filename)
  raise ArgumentError, "channel is nil" if channel.nil?

  @filename = filename
  @view_content = File.read(filename)
  @template_content = template_filename != "" ? File.read(template_filename) : "<%= @content %>"
  @template_filename = template_filename != "" ? template_filename : ""
  @channel = channel
end

Instance Attribute Details

#contentObject (readonly)

content rendered



9
10
11
# File 'lib/noticent/view.rb', line 9

def content
  @content
end

#dataObject (readonly)

these are the attributes we should use in most cases



8
9
10
# File 'lib/noticent/view.rb', line 8

def data
  @data
end

#filenameObject (readonly)

view filename



13
14
15
# File 'lib/noticent/view.rb', line 13

def filename
  @filename
end

#raw_contentObject (readonly)

content in their raw (pre render) format



15
16
17
# File 'lib/noticent/view.rb', line 15

def raw_content
  @raw_content
end

#raw_dataObject (readonly)

frontmatter in their raw (pre render) format



16
17
18
# File 'lib/noticent/view.rb', line 16

def raw_data
  @raw_data
end

#rendered_dataObject (readonly)

frontmatter rendered in string format



17
18
19
# File 'lib/noticent/view.rb', line 17

def rendered_data
  @rendered_data
end

#template_contentObject (readonly)

contents of the template



14
15
16
# File 'lib/noticent/view.rb', line 14

def template_content
  @template_content
end

#view_contentObject (readonly)

these are mostly for debug and testing purposes



12
13
14
# File 'lib/noticent/view.rb', line 12

def view_content
  @view_content
end

Instance Method Details

#process(context) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/noticent/view.rb', line 31

def process(context)
  parse
  render_data(context)
  read_data
  # TODO this is nasty. we need to refactor to have an independent render context which somehow merges the binding with the channel.
  @channel.data = @data
  render_content(context)
end