Class: Noticent::View
- Inherits:
-
Object
- Object
- Noticent::View
- Defined in:
- lib/noticent/view.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
content rendered.
-
#data ⇒ Object
readonly
these are the attributes we should use in most cases.
-
#filename ⇒ Object
readonly
view filename.
-
#raw_content ⇒ Object
readonly
content in their raw (pre render) format.
-
#raw_data ⇒ Object
readonly
frontmatter in their raw (pre render) format.
-
#rendered_data ⇒ Object
readonly
frontmatter rendered in string format.
-
#template_content ⇒ Object
readonly
contents of the template.
-
#view_content ⇒ Object
readonly
these are mostly for debug and testing purposes.
Instance Method Summary collapse
-
#initialize(filename, template_filename: "", channel:) ⇒ View
constructor
A new instance of View.
- #process(context) ⇒ Object
Constructor Details
#initialize(filename, template_filename: "", channel:) ⇒ View
Returns a new instance of View.
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
#content ⇒ Object (readonly)
content rendered
9 10 11 |
# File 'lib/noticent/view.rb', line 9 def content @content end |
#data ⇒ Object (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 |
#filename ⇒ Object (readonly)
view filename
13 14 15 |
# File 'lib/noticent/view.rb', line 13 def filename @filename end |
#raw_content ⇒ Object (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_data ⇒ Object (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_data ⇒ Object (readonly)
frontmatter rendered in string format
17 18 19 |
# File 'lib/noticent/view.rb', line 17 def rendered_data @rendered_data end |
#template_content ⇒ Object (readonly)
contents of the template
14 15 16 |
# File 'lib/noticent/view.rb', line 14 def template_content @template_content end |
#view_content ⇒ Object (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 |