Class: ViewHandler
- Defined in:
- lib/volt/server/html_parser/view_handler.rb
Instance Attribute Summary collapse
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#templates ⇒ Object
readonly
Returns the value of attribute templates.
Instance Method Summary collapse
- #binding(binding) ⇒ Object
- #comment(comment) ⇒ Object
- #end_tag(tag_name) ⇒ Object
- #html ⇒ Object
-
#initialize(initial_path, allow_sections = true) ⇒ ViewHandler
constructor
A new instance of ViewHandler.
- #last ⇒ Object
- #start_section(tag_name, attributes, unary) ⇒ Object
- #start_tag(tag_name, attributes, unary) ⇒ Object
- #text(text) ⇒ Object
Constructor Details
#initialize(initial_path, allow_sections = true) ⇒ ViewHandler
Returns a new instance of ViewHandler.
12 13 14 15 16 17 18 19 20 |
# File 'lib/volt/server/html_parser/view_handler.rb', line 12 def initialize(initial_path, allow_sections=true) @original_path = initial_path # Default to the body section initial_path += '/body' if allow_sections @scope = [ViewScope.new(self, initial_path)] @templates = {} end |
Instance Attribute Details
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
2 3 4 |
# File 'lib/volt/server/html_parser/view_handler.rb', line 2 def scope @scope end |
#templates ⇒ Object (readonly)
Returns the value of attribute templates.
2 3 4 |
# File 'lib/volt/server/html_parser/view_handler.rb', line 2 def templates @templates end |
Instance Method Details
#binding(binding) ⇒ Object
30 31 32 |
# File 'lib/volt/server/html_parser/view_handler.rb', line 30 def binding(binding) @scope.last.add_binding(binding) end |
#comment(comment) ⇒ Object
22 23 24 |
# File 'lib/volt/server/html_parser/view_handler.rb', line 22 def comment(comment) last << "<!--#{comment}-->" end |
#end_tag(tag_name) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/volt/server/html_parser/view_handler.rb', line 54 def end_tag(tag_name) if @in_textarea && tag_name == 'textarea' last.close_scope @in_textarea = nil else last << "</#{tag_name}>" end end |
#html ⇒ Object
4 5 6 |
# File 'lib/volt/server/html_parser/view_handler.rb', line 4 def html last.html end |
#last ⇒ Object
8 9 10 |
# File 'lib/volt/server/html_parser/view_handler.rb', line 8 def last @scope.last end |
#start_section(tag_name, attributes, unary) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/volt/server/html_parser/view_handler.rb', line 63 def start_section(tag_name, attributes, unary) path = last.path # Start of section if @in_section # Close any previous sections last.close_scope else # This is the first time we've hit a section header, everything # outside of the headers should be removed @templates = {} end @in_section = tag_name[1..-1] # Set the new path to include the section new_path = @original_path + '/' + @in_section @scope = [ViewScope.new(self, new_path)] end |
#start_tag(tag_name, attributes, unary) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/volt/server/html_parser/view_handler.rb', line 34 def start_tag(tag_name, attributes, unary) case tag_name[0] when ':' # Component last.add_component(tag_name, attributes, unary) else if tag_name == 'textarea' @in_textarea = true last.add_textarea(tag_name, attributes, unary) else # Normal tag attributes = last.process_attributes(tag_name, attributes) attr_str = last.attribute_string(attributes) last << "<#{tag_name}#{attr_str}#{unary ? ' /' : ''}>" end end end |
#text(text) ⇒ Object
26 27 28 |
# File 'lib/volt/server/html_parser/view_handler.rb', line 26 def text(text) last << text end |