Class: StaticMatic::TemplateError

### Home Classes Methods

### In Files

- lib/staticmatic/template_error.rb

### Parent

StandardError

### Methods

- ::new
- #filename
- #line_number
- #source_extract

### Files

- LICENSE

### Class/Module Index

Quicksearch

- StaticMatic
- StaticMatic::Base
- StaticMatic::BuildMixin
- StaticMatic::Configuration
- StaticMatic::Error
- StaticMatic::Helpers
- StaticMatic::Helpers::AssetsHelper
- StaticMatic::Helpers::CurrentPathHelper
- StaticMatic::Helpers::FormHelper
- StaticMatic::Helpers::RenderHelper
- StaticMatic::Helpers::TagHelper
- StaticMatic::Helpers::UrlHelper
- StaticMatic::HelpersMixin
- StaticMatic::RenderMixin
- StaticMatic::RescueMixin
- StaticMatic::Server
- StaticMatic::ServerMixin
- StaticMatic::SetupMixin
- StaticMatic::TemplateError
- Compass
- Compass::AppIntegration
- Compass::AppIntegration::Staticmatic
- Compass::AppIntegration::Staticmatic::ConfigurationDefaults
- Compass::AppIntegration::Staticmatic::Installer

No matching classes.

# StaticMatic::TemplateError

### Constants

SOURCE_CODE_RADIUS

### Attributes

backtrace[R]
original_exception[R]

### Public Class Methods

new(template, original_exception) click to toggle source

    # File lib/staticmatic/template_error.rb, line 6
    def initialize(template, original_exception)
      @template, @original_exception = template, original_exception
      @backtrace = original_exception.backtrace

      if template
        @source = File.read(template)
      else
        @source = ""
      end
    end

### Public Instance Methods

filename() click to toggle source

    # File lib/staticmatic/template_error.rb, line 22
    def filename
      @template
    end

line_number() click to toggle source

TODO: Replace 'haml|sass' with any registered engines

    # File lib/staticmatic/template_error.rb, line 18
    def line_number
      @line_number ||= $2 if backtrace.find { |line| line =~ /\((haml|sass|scss)\)\:(\d+)/ }
    end

source_extract(indentation = 0) click to toggle source

    # File lib/staticmatic/template_error.rb, line 26
    def source_extract(indentation = 0)
      return "" unless num = line_number
      num = num.to_i

      source_code = @source.split("\n")

      start_on_line = [ num - SOURCE_CODE_RADIUS - 1, 0 ].max
      end_on_line   = [ num + SOURCE_CODE_RADIUS - 1, source_code.length].min

      indent = ' ' * indentation
      line_counter = start_on_line
      return unless source_code = source_code[start_on_line..end_on_line]

      source_code.collect do |line|
        line_counter += 1
        "#{indent}#{line_counter}: #{line}\n"
      end.to_s
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.