class Volt::ViewHandler

Attributes

scope[R]
templates[R]

Public Class Methods

new(initial_path, sprockets_context=nil, allow_sections = true) click to toggle source

@param [String] - the path to the template file being processed @param - the sprockets context, used for asset_url bindings @param [Boolean] - if the processing should default to body section

# File lib/volt/server/html_parser/view_handler.rb, line 16
def initialize(initial_path, sprockets_context=nil, allow_sections = true)
  @original_path = initial_path
  @sprockets_context = sprockets_context
  @links = []

  # Default to the body section
  initial_path += '/body' if allow_sections

  @scope     = [ViewScope.new(self, initial_path)]
  @templates = {}
end

Public Instance Methods

binding(binding) click to toggle source
# File lib/volt/server/html_parser/view_handler.rb, line 36
def binding(binding)
  @scope.last.add_binding(binding)
end
comment(comment) click to toggle source
# File lib/volt/server/html_parser/view_handler.rb, line 28
def comment(comment)
  last << "<!--#{comment}-->"
end
end_tag(tag_name) click to toggle source
# File lib/volt/server/html_parser/view_handler.rb, line 60
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() click to toggle source
# File lib/volt/server/html_parser/view_handler.rb, line 5
def html
  last.html
end
last() click to toggle source
# File lib/volt/server/html_parser/view_handler.rb, line 9
def last
  @scope.last
end
start_section(tag_name, attributes, unary) click to toggle source
# File lib/volt/server/html_parser/view_handler.rb, line 72
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) click to toggle source
# File lib/volt/server/html_parser/view_handler.rb, line 40
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) click to toggle source
# File lib/volt/server/html_parser/view_handler.rb, line 32
def text(text)
  last << text
end