Class: Metro::View
- Inherits:
-
Object
- Object
- Metro::View
- Defined in:
- lib/metro/views/view.rb
Overview
A view represents the representation of the content found within the view file. A view has the ability to save/load the content as well.
Instance Attribute Summary collapse
-
#format ⇒ Object
Return the format of the view.
-
#name ⇒ Object
The name of the view, which is used to influence the file path.
Instance Method Summary collapse
-
#content ⇒ Object
The content contained within the view.
-
#content=(value) ⇒ Object
Set the content of the view.
- #default_writer ⇒ Object
-
#parse ⇒ Object
Parse the content found at the view path for the view.
-
#parser ⇒ Object
The parser for this view is one of the supported parsers.
-
#save ⇒ Object
Ask the parser to save the current content of the view at the view path.
-
#supported_parsers ⇒ Object
Supported view formats.
- #supported_writers ⇒ Object
-
#view_path ⇒ Object
A Scene view path is based on the view name.
-
#writer ⇒ Object
The writer for this view.
Instance Attribute Details
#format ⇒ Object
Return the format of the view. By default the format of the view is dictated by the format of the content that is parsed.
97 98 99 |
# File 'lib/metro/views/view.rb', line 97 def format @format || parser.format end |
#name ⇒ Object
The name of the view, which is used to influence the file path.
16 17 18 |
# File 'lib/metro/views/view.rb', line 16 def name @name end |
Instance Method Details
#content ⇒ Object
The content contained within the view.
21 22 23 24 25 26 27 |
# File 'lib/metro/views/view.rb', line 21 def content @content ||= begin parsed_content = parse parsed_content.default = {} parsed_content end end |
#content=(value) ⇒ Object
Set the content of the view.
34 35 36 37 |
# File 'lib/metro/views/view.rb', line 34 def content=(value) value.default = {} @content = value end |
#default_writer ⇒ Object
127 128 129 |
# File 'lib/metro/views/view.rb', line 127 def default_writer Views::Writers.default_writer end |
#parse ⇒ Object
Parse the content found at the view path for the view.
66 67 68 |
# File 'lib/metro/views/view.rb', line 66 def parse parser.parse(view_path) end |
#parser ⇒ Object
The parser for this view is one of the supported parsers. A parser is selected if the parser is capable of finding the content to load.
75 76 77 |
# File 'lib/metro/views/view.rb', line 75 def parser @parser ||= supported_parsers.find { |parser| parser.exists? view_path } end |
#save ⇒ Object
Ask the parser to save the current content of the view at the view path
89 90 91 |
# File 'lib/metro/views/view.rb', line 89 def save writer.write(view_path,content) end |
#supported_parsers ⇒ Object
Supported view formats
82 83 84 |
# File 'lib/metro/views/view.rb', line 82 def supported_parsers Views::Parsers.parsers_with_no_view_fallback end |
#supported_writers ⇒ Object
123 124 125 |
# File 'lib/metro/views/view.rb', line 123 def supported_writers Views::Writers.writers end |
#view_path ⇒ Object
A Scene view path is based on the view name.
57 58 59 |
# File 'lib/metro/views/view.rb', line 57 def view_path File.join "views", name end |
#writer ⇒ Object
The writer for this view. If the view has already been parsed then use
116 117 118 119 120 121 |
# File 'lib/metro/views/view.rb', line 116 def writer @writer ||= begin writer_matching_existing_parser = supported_writers.find { |writer| writer.format == format } writer_matching_existing_parser || default_writer end end |