Class: Volt::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.
13 14 15 16 17 18 19 20 21 |
# File 'lib/volt/server/html_parser/view_handler.rb', line 13 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.
3 4 5 |
# File 'lib/volt/server/html_parser/view_handler.rb', line 3 def scope @scope end |
#templates ⇒ Object (readonly)
Returns the value of attribute templates.
3 4 5 |
# File 'lib/volt/server/html_parser/view_handler.rb', line 3 def templates @templates end |
Instance Method Details
#binding(binding) ⇒ Object
31 32 33 |
# File 'lib/volt/server/html_parser/view_handler.rb', line 31 def binding(binding) @scope.last.add_binding(binding) end |
#comment(comment) ⇒ Object
23 24 25 |
# File 'lib/volt/server/html_parser/view_handler.rb', line 23 def comment(comment) last << "<!--#{comment}-->" end |
#end_tag(tag_name) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/volt/server/html_parser/view_handler.rb', line 55 def end_tag(tag_name) if @in_textarea && tag_name == 'textarea' last.close_scope @in_textarea = nil elsif tag_name[0] == ':' # Closing a volt tag last.close_scope else last << "</#{tag_name}>" end end |
#html ⇒ Object
5 6 7 |
# File 'lib/volt/server/html_parser/view_handler.rb', line 5 def html last.html end |
#last ⇒ Object
9 10 11 |
# File 'lib/volt/server/html_parser/view_handler.rb', line 9 def last @scope.last end |
#start_section(tag_name, attributes, unary) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/volt/server/html_parser/view_handler.rb', line 67 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
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/volt/server/html_parser/view_handler.rb', line 35 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
27 28 29 |
# File 'lib/volt/server/html_parser/view_handler.rb', line 27 def text(text) last << text end |